Skip to content

Commit

Permalink
Remove dynamic gas for EXTCODE*
Browse files Browse the repository at this point in the history
  • Loading branch information
somnathb1 committed Jan 8, 2025
1 parent dc9f28b commit 58f6b70
Show file tree
Hide file tree
Showing 5 changed files with 3 additions and 66 deletions.
2 changes: 1 addition & 1 deletion core/types/transaction_marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ type txJSON struct {
}

type JsonAuthorization struct {
ChainID hexutil.Big `json:"chainId"`
ChainID hexutil.Big `json:"chainId"`
Address libcommon.Address `json:"address"`
Nonce hexutil.Uint64 `json:"nonce"`
V hexutil.Uint64 `json:"v"`
Expand Down
3 changes: 0 additions & 3 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,9 +326,6 @@ func enable7516(jt *JumpTable) {
}

func enable7702(jt *JumpTable) {
jt[EXTCODECOPY].dynamicGas = gasExtCodeCopyEIP7702
jt[EXTCODESIZE].dynamicGas = gasEip7702CodeCheck
jt[EXTCODEHASH].dynamicGas = gasEip7702CodeCheck
jt[CALL].dynamicGas = gasCallEIP7702
jt[CALLCODE].dynamicGas = gasCallCodeEIP7702
jt[STATICCALL].dynamicGas = gasStaticCallEIP7702
Expand Down
2 changes: 1 addition & 1 deletion core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -380,7 +380,7 @@ func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
}
if codeSize == types.DelegateDesignationCodeSize {
if codeSize == types.DelegateDesignationCodeSize {
_, ok, err := interpreter.evm.IntraBlockState().GetDelegatedDesignation(addr)
if err != nil {
return nil, fmt.Errorf("%w: %w", ErrIntraBlockStateFailed, err)
Expand Down
60 changes: 0 additions & 60 deletions core/vm/operations_acl.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,63 +317,3 @@ func makeCallVariantGasCallEIP7702(oldCalculator gasFunc) gasFunc {
return gas, nil
}
}

func gasEip7702CodeCheck(evm *EVM, contract *Contract, stack *stack.Stack, mem *Memory, memorySize uint64) (uint64, error) {
addr := libcommon.Address(stack.Peek().Bytes20())
// The warm storage read cost is already charged as constantGas
// Check slot presence in the access list
var cost uint64
if evm.intraBlockState.AddAddressToAccessList(addr) {
// Check if code is a delegation and if so, charge for resolution
cost = params.ColdAccountAccessCostEIP2929 - params.WarmStorageReadCostEIP2929
}
dd, ok, err := evm.intraBlockState.GetDelegatedDesignation(addr)
if err != nil {
return 0, err
}
if ok {
if evm.intraBlockState.AddAddressToAccessList(dd) {
cost += params.ColdAccountAccessCostEIP2929
} else {
cost += params.WarmStorageReadCostEIP2929
}
}

return cost, nil
}

func gasExtCodeCopyEIP7702(evm *EVM, contract *Contract, stack *stack.Stack, mem *Memory, memorySize uint64) (uint64, error) {
// memory expansion first (dynamic part of pre-2929 implementation)
gas, err := gasExtCodeCopy(evm, contract, stack, mem, memorySize)
if err != nil {
return 0, err
}
addr := libcommon.Address(stack.Peek().Bytes20())
// Check slot presence in the access list
if evm.intraBlockState.AddAddressToAccessList(addr) {
var overflow bool
// We charge (cold-warm), since 'warm' is already charged as constantGas
if gas, overflow = math.SafeAdd(gas, params.ColdAccountAccessCostEIP2929-params.WarmStorageReadCostEIP2929); overflow {
return 0, ErrGasUintOverflow
}
}

// Check if addr has a delegation and if so, charge for resolution
dd, ok, err := evm.intraBlockState.GetDelegatedDesignation(addr)
if err != nil {
return 0, err
}
if ok {
var overflow bool
if evm.intraBlockState.AddAddressToAccessList(dd) {
if gas, overflow = math.SafeAdd(gas, params.ColdAccountAccessCostEIP2929); overflow {
return 0, ErrGasUintOverflow
}
} else {
if gas, overflow = math.SafeAdd(gas, params.WarmStorageReadCostEIP2929); overflow {
return 0, ErrGasUintOverflow
}
}
}
return gas, nil
}
2 changes: 1 addition & 1 deletion tests/exec_spec_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func TestExecutionSpec(t *testing.T) {

bt := new(testMatcher)

dir := filepath.Join(".", "execution-spec-tests",)
dir := filepath.Join(".", "execution-spec-tests")
bt.skipLoad(`^prague/eip2935_historical_block_hashes_from_state/block_hashes/block_hashes_history.json`)
// bt.skipLoad(`^cancun`)
checkStateRoot := true
Expand Down

0 comments on commit 58f6b70

Please sign in to comment.