mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-20 02:42:27 +00:00
all: comment eip-2929 implementations
This commit is contained in:
parent
0f6d38b50f
commit
fff6498ed6
5 changed files with 32 additions and 6 deletions
|
|
@ -25,12 +25,15 @@ type accessList struct {
|
|||
slots []map[common.Hash]struct{}
|
||||
}
|
||||
|
||||
// ContainsAddress는 address가 access list에 있는지 여부를 리턴한다.
|
||||
// ContainsAddress returns true if the address is in the access list.
|
||||
func (al *accessList) ContainsAddress(address common.Address) bool {
|
||||
_, ok := al.addresses[address]
|
||||
return ok
|
||||
}
|
||||
|
||||
// Contains는 slot이 access list에 있는 account에 속해 있는지 확인하고,
|
||||
// account와 slot각각에 대해 분리된 flag를 리턴한다.
|
||||
// Contains checks if a slot within an account is present in the access list, returning
|
||||
// separate flags for the presence of the account and the slot respectively.
|
||||
func (al *accessList) Contains(address common.Address, slot common.Hash) (addressPresent bool, slotPresent bool) {
|
||||
|
|
@ -47,6 +50,7 @@ func (al *accessList) Contains(address common.Address, slot common.Hash) (addres
|
|||
return true, slotPresent
|
||||
}
|
||||
|
||||
// newAccessList는 새로운 accessList를 생성
|
||||
// newAccessList creates a new accessList.
|
||||
func newAccessList() *accessList {
|
||||
return &accessList{
|
||||
|
|
@ -54,6 +58,7 @@ func newAccessList() *accessList {
|
|||
}
|
||||
}
|
||||
|
||||
// Copy는 accessList의 독립된 copy를 생성한다.
|
||||
// Copy creates an independent copy of an accessList.
|
||||
func (a *accessList) Copy() *accessList {
|
||||
cp := newAccessList()
|
||||
|
|
@ -71,6 +76,7 @@ func (a *accessList) Copy() *accessList {
|
|||
return cp
|
||||
}
|
||||
|
||||
// AddAddress는 access list에 address를 추가하고, 이 연산이 변화를 만들었다면 true를 리턴한다.
|
||||
// AddAddress adds an address to the access list, and returns 'true' if the operation
|
||||
// caused a change (addr was not previously in the list).
|
||||
func (al *accessList) AddAddress(address common.Address) bool {
|
||||
|
|
@ -81,6 +87,7 @@ func (al *accessList) AddAddress(address common.Address) bool {
|
|||
return true
|
||||
}
|
||||
|
||||
// AddSlot은 (addr, slot)을 access list에 추가한다.
|
||||
// AddSlot adds the specified (addr, slot) combo to the access list.
|
||||
// Return values are:
|
||||
// - address added
|
||||
|
|
@ -106,6 +113,7 @@ func (al *accessList) AddSlot(address common.Address, slot common.Hash) (addrCha
|
|||
return false, false
|
||||
}
|
||||
|
||||
// DeleteSlot은 (address, slot) tuple을 access list에서 제거한다.
|
||||
// DeleteSlot removes an (address, slot)-tuple from the access list.
|
||||
// This operation needs to be performed in the same order as the addition happened.
|
||||
// This method is meant to be used by the journal, which maintains ordering of
|
||||
|
|
@ -127,6 +135,7 @@ func (al *accessList) DeleteSlot(address common.Address, slot common.Hash) {
|
|||
}
|
||||
}
|
||||
|
||||
// DeleteAddress는 address를 access list에서 삭제한다.
|
||||
// DeleteAddress removes an address from the access list. This operation
|
||||
// needs to be performed in the same order as the addition happened.
|
||||
// This method is meant to be used by the journal, which maintains ordering of
|
||||
|
|
|
|||
|
|
@ -148,6 +148,7 @@ func init() {
|
|||
}
|
||||
}
|
||||
|
||||
// ActivePrecompiles은 config에 따라 precompiles할 주소 목록을 반환한다.
|
||||
// ActivePrecompiles returns the precompiles enabled with the current configuration.
|
||||
func ActivePrecompiles(rules params.Rules) []common.Address {
|
||||
switch {
|
||||
|
|
|
|||
|
|
@ -102,6 +102,7 @@ type EVM struct {
|
|||
// Context provides auxiliary blockchain related information
|
||||
Context BlockContext
|
||||
TxContext
|
||||
// StateDB는 state에 대한 access 제공
|
||||
// StateDB gives access to the underlying state
|
||||
StateDB StateDB
|
||||
// Depth is the current call stack
|
||||
|
|
|
|||
|
|
@ -96,6 +96,10 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
|
|||
}
|
||||
}
|
||||
|
||||
// gasLoadEIP2929는 SLOAD의 dynamic gas를 계산한다.
|
||||
// (address,storage_key) pair가 accessed list에
|
||||
// 없으면 2100gas(ColdSLoadCostEIP2929)을 청구하고 해당 데이터 해시값을 해당 address의 slot에 저장하고
|
||||
// 있으면 100gas(WarmStorageReadCostEIP2929)를 청구한다.
|
||||
// gasSLoadEIP2929 calculates dynamic gas for SLOAD according to EIP-2929
|
||||
// For SLOAD, if the (address, storage_key) pair (where address is the address of the contract
|
||||
// whose storage is being read) is not yet in accessed_storage_keys,
|
||||
|
|
@ -103,6 +107,7 @@ func makeGasSStoreFunc(clearingRefund uint64) gasFunc {
|
|||
// If the pair is already in accessed_storage_keys, charge 100 gas.
|
||||
func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||
loc := stack.peek()
|
||||
// slot에 접근 데이터 hash를 저장
|
||||
slot := common.Hash(loc.Bytes32())
|
||||
// Check slot presence in the access list
|
||||
if _, slotPresent := evm.StateDB.SlotInAccessList(contract.Address(), slot); !slotPresent {
|
||||
|
|
@ -114,6 +119,7 @@ func gasSLoadEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memory, me
|
|||
return params.WarmStorageReadCostEIP2929, nil
|
||||
}
|
||||
|
||||
// getExtCodeCopyEIP2929는 extcodecopy를 구현한다.
|
||||
// gasExtCodeCopyEIP2929 implements extcodecopy according to EIP-2929
|
||||
// EIP spec:
|
||||
// > If the target is not in accessed_addresses,
|
||||
|
|
@ -139,6 +145,9 @@ func gasExtCodeCopyEIP2929(evm *EVM, contract *Contract, stack *Stack, mem *Memo
|
|||
return gas, nil
|
||||
}
|
||||
|
||||
// gasEip2929AccountCheck은 address가 access list에 있는지 확인한다.
|
||||
// 있으면 0을 리턴하고, 없으면 cold-warm gas(추가비용)를 리턴한다.
|
||||
// 이더리움 네트워크에서 계정 액세스에 대한 가스 비용을 동적으로 조절
|
||||
// gasEip2929AccountCheck checks whether the first stack item (as address) is present in the access list.
|
||||
// If it is, this method returns '0', otherwise 'cold-warm' gas, presuming that the opcode using it
|
||||
// is also using 'warm' as constant factor.
|
||||
|
|
@ -158,6 +167,7 @@ func gasEip2929AccountCheck(evm *EVM, contract *Contract, stack *Stack, mem *Mem
|
|||
return 0, nil
|
||||
}
|
||||
|
||||
// EIP2929에 따라 계산되는 gas 비용
|
||||
func makeCallVariantGasCallEIP2929(oldCalculator gasFunc) gasFunc {
|
||||
return func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||
addr := common.Address(stack.Back(1).Bytes20())
|
||||
|
|
@ -225,6 +235,7 @@ var (
|
|||
gasSStoreEIP3529 = makeGasSStoreFunc(params.SstoreClearsScheduleRefundEIP3529)
|
||||
)
|
||||
|
||||
// makeSelfdestructGasFn은 selfdestruct의 dynamic gas func를 생성한다.
|
||||
// makeSelfdestructGasFn can create the selfdestruct dynamic gas function for EIP-2929 and EIP-3529
|
||||
func makeSelfdestructGasFn(refundsEnabled bool) gasFunc {
|
||||
gasFunc := func(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (uint64, error) {
|
||||
|
|
|
|||
|
|
@ -28,12 +28,12 @@ const (
|
|||
MaxGasLimit uint64 = 0x7fffffffffffffff // Maximum the gas limit (2^63-1).
|
||||
GenesisGasLimit uint64 = 4712388 // Gas limit of the Genesis block.
|
||||
|
||||
MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
|
||||
ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction.
|
||||
SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added.
|
||||
CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero.
|
||||
CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior.
|
||||
TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.
|
||||
MaximumExtraDataSize uint64 = 32 // Maximum size extra data may be after Genesis.
|
||||
ExpByteGas uint64 = 10 // Times ceil(log256(exponent)) for the EXP instruction.
|
||||
SloadGas uint64 = 50 // Multiplied by the number of 32-byte words that are copied (round up) for any *COPY operation and added.
|
||||
CallValueTransferGas uint64 = 9000 // Paid for CALL when the value transfer is non-zero.
|
||||
CallNewAccountGas uint64 = 25000 // Paid for CALL when the destination address didn't exist prior.
|
||||
TxGas uint64 = 21000 // Per transaction not creating a contract. NOTE: Not payable on data of calls between transactions.
|
||||
//eip2: 추가된 가스비 코드
|
||||
TxGasContractCreation uint64 = 53000 // Per transaction that creates a contract. NOTE: Not payable on data of calls between transactions.
|
||||
TxDataZeroGas uint64 = 4 // Per byte of data attached to a transaction that equals zero. NOTE: Not payable on data of calls between transactions.
|
||||
|
|
@ -120,6 +120,10 @@ const (
|
|||
ExtcodeCopyBaseFrontier uint64 = 20
|
||||
ExtcodeCopyBaseEIP150 uint64 = 700
|
||||
|
||||
// CreateBySelfdestructGas는 selfdestruct 연산에서 환불 계정이 존재하지 않을 때 사용되는 가스 비용을 나타낸다.
|
||||
// selfdestruct는 컨트랙트를 소멸시키고, 해당 컨트랙트의 잔액을 지정된 계정으로 전송한다.
|
||||
// 이때, 환불계정이 존재하지 않는 경우에는 계정 생성에 따른 추가적인 가스 비용이 발생함
|
||||
// DoS공격 방지, 일관성유지
|
||||
// CreateBySelfdestructGas is used when the refunded account is one that does
|
||||
// not exist. This logic is similar to call.
|
||||
// Introduced in Tangerine Whistle (Eip 150)
|
||||
|
|
|
|||
Loading…
Reference in a new issue