Skip to content

Commit

Permalink
More spec fixes (#511)
Browse files Browse the repository at this point in the history
* fix EXTCODESIZE rule for system contract

Signed-off-by: Ignacio Hagopian <[email protected]>

* 21000 witness target write touch CODEHASH

Signed-off-by: Ignacio Hagopian <[email protected]>

* fix EXTCODECOPY witness for system contract

Signed-off-by: Ignacio Hagopian <[email protected]>

* rename and comment

Signed-off-by: Ignacio Hagopian <[email protected]>

---------

Signed-off-by: Ignacio Hagopian <[email protected]>
  • Loading branch information
jsign authored Oct 16, 2024
1 parent 9635cc1 commit 1ec805c
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
11 changes: 8 additions & 3 deletions core/state/access_witness.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,14 @@ func (aw *AccessWitness) TouchTxOriginAndComputeGas(originAddr []byte) {
}
}

func (aw *AccessWitness) TouchTxExistingAndComputeGas(targetAddr []byte, sendsValue bool) {
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, sendsValue, nil)
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.CodeHashLeafKey, false, nil)
func (aw *AccessWitness) TouchTxTarget(targetAddr []byte) {
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.BasicDataLeafKey, true, nil)
// Note that we do a write-event in CodeHash without distinguishing if the tx target account
// exists or not. Pre-7702, there's no situation in which an existing codeHash can be mutated, thus
// doing a write-event shouldn't cause an observable difference in gas usage.
// TODO(7702): re-check this in the spec and implementation to be sure is a correct solution after
// EIP-7702 is implemented.
aw.touchAddressAndChargeGas(targetAddr, zeroTreeIndex, utils.CodeHashLeafKey, true, nil)
}

func (aw *AccessWitness) TouchSlotAndChargeGas(addr []byte, slot common.Hash, isWrite bool, useGasFn UseGasFn, warmCostCharging bool) bool {
Expand Down
2 changes: 1 addition & 1 deletion core/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -396,7 +396,7 @@ func (st *StateTransition) TransitionDb() (*ExecutionResult, error) {
st.evm.Accesses.TouchTxOriginAndComputeGas(originAddr.Bytes())

if msg.To != nil {
st.evm.Accesses.TouchTxExistingAndComputeGas(targetAddr.Bytes(), msg.Value.Sign() != 0)
st.evm.Accesses.TouchTxTarget(targetAddr.Bytes())

// ensure the code size ends up in the access witness
st.evm.StateDB.GetCodeSize(*targetAddr)
Expand Down
6 changes: 4 additions & 2 deletions core/vm/instructions.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,7 +352,8 @@ func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
address := slot.Bytes20()
cs := uint64(interpreter.evm.StateDB.GetCodeSize(address))
if interpreter.evm.chainRules.IsVerkle {
if _, isPrecompile := interpreter.evm.precompile(address); isPrecompile {
isSystemContract := interpreter.evm.isSystemContract(address)
if _, isPrecompile := interpreter.evm.precompile(address); isPrecompile || isSystemContract {
if !scope.Contract.UseGas(params.WarmStorageReadCostEIP2929) {
return nil, ErrOutOfGas
}
Expand Down Expand Up @@ -407,7 +408,8 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)

if interpreter.evm.chainRules.IsVerkle {
addr := common.Address(a.Bytes20())
if _, isPrecompile := interpreter.evm.precompile(addr); isPrecompile {
isSystemContract := interpreter.evm.isSystemContract(addr)
if _, isPrecompile := interpreter.evm.precompile(addr); isPrecompile || isSystemContract {
if !scope.Contract.UseGas(params.WarmStorageReadCostEIP2929) {
return nil, ErrOutOfGas
}
Expand Down

0 comments on commit 1ec805c

Please sign in to comment.