From dd756eb47dfc16559dabbb38609aa37d3d0dbe3b Mon Sep 17 00:00:00 2001 From: Hadrien Croubois Date: Sun, 18 Feb 2024 22:08:02 +0100 Subject: [PATCH] restrict CREATE2 and SELFDESTRUCT --- core/vm/instructions.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/core/vm/instructions.go b/core/vm/instructions.go index 2a55f64e42..27c9e0fb38 100644 --- a/core/vm/instructions.go +++ b/core/vm/instructions.go @@ -624,6 +624,11 @@ func opCreate(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]b } func opCreate2(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + if interpreter.evm.TxContext.Is5806 { + if scope.Contract.CodeHash == types.EmptyCodeHash || scope.Contract.CodeHash == (common.Hash{}) { + return nil, ErrEip5806Write + } + } if interpreter.readOnly { return nil, ErrWriteProtection } @@ -805,6 +810,11 @@ func opStop(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byt } func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + if interpreter.evm.TxContext.Is5806 { + if scope.Contract.CodeHash == types.EmptyCodeHash || scope.Contract.CodeHash == (common.Hash{}) { + return nil, ErrEip5806Write + } + } if interpreter.readOnly { return nil, ErrWriteProtection } @@ -820,6 +830,11 @@ func opSelfdestruct(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext } func opSelfdestruct6780(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) { + if interpreter.evm.TxContext.Is5806 { + if scope.Contract.CodeHash == types.EmptyCodeHash || scope.Contract.CodeHash == (common.Hash{}) { + return nil, ErrEip5806Write + } + } if interpreter.readOnly { return nil, ErrWriteProtection }