mirror of
https://github.com/ethereum/go-ethereum.git
synced 2026-08-19 02:12:23 +00:00
core/vm: fix opExtCode{Size,Hash,Copy}
This commit is contained in:
parent
b2ae97892d
commit
6c97819d94
3 changed files with 18 additions and 12 deletions
|
|
@ -473,13 +473,6 @@ func (s *StateDB) SetCode(addr common.Address, code []byte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func (s *StateDB) SetCodeEOF(addr common.Address, code []byte) {
|
|
||||||
stateObject := s.getOrNewStateObject(addr)
|
|
||||||
if stateObject != nil {
|
|
||||||
stateObject.SetCode(types.EmptyEOFCodeHash, code)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
|
func (s *StateDB) SetState(addr common.Address, key, value common.Hash) {
|
||||||
stateObject := s.getOrNewStateObject(addr)
|
stateObject := s.getOrNewStateObject(addr)
|
||||||
if stateObject != nil {
|
if stateObject != nil {
|
||||||
|
|
|
||||||
|
|
@ -357,7 +357,12 @@ func opExtCodeSize(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
||||||
witness.AddCode(interpreter.evm.StateDB.GetCode(address))
|
witness.AddCode(interpreter.evm.StateDB.GetCode(address))
|
||||||
witness.AddCode(interpreter.evm.StateDB.ResolveCode(address))
|
witness.AddCode(interpreter.evm.StateDB.ResolveCode(address))
|
||||||
}
|
}
|
||||||
|
code := interpreter.evm.StateDB.GetCode(slot.Bytes20())
|
||||||
|
if isEOFVersion1(code) {
|
||||||
|
slot.SetUint64(2)
|
||||||
|
} else {
|
||||||
slot.SetUint64(uint64(len(interpreter.evm.StateDB.ResolveCode(slot.Bytes20()))))
|
slot.SetUint64(uint64(len(interpreter.evm.StateDB.ResolveCode(slot.Bytes20()))))
|
||||||
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -389,6 +394,7 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
||||||
memOffset = stack.pop()
|
memOffset = stack.pop()
|
||||||
codeOffset = stack.pop()
|
codeOffset = stack.pop()
|
||||||
length = stack.pop()
|
length = stack.pop()
|
||||||
|
lengthU64 = length.Uint64()
|
||||||
)
|
)
|
||||||
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
uint64CodeOffset, overflow := codeOffset.Uint64WithOverflow()
|
||||||
if overflow {
|
if overflow {
|
||||||
|
|
@ -400,8 +406,11 @@ func opExtCodeCopy(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
||||||
witness.AddCode(interpreter.evm.StateDB.GetCode(addr))
|
witness.AddCode(interpreter.evm.StateDB.GetCode(addr))
|
||||||
witness.AddCode(code)
|
witness.AddCode(code)
|
||||||
}
|
}
|
||||||
codeCopy := getData(code, uint64CodeOffset, length.Uint64())
|
if isEOFVersion1(code) {
|
||||||
scope.Memory.Set(memOffset.Uint64(), length.Uint64(), codeCopy)
|
lengthU64 = 2
|
||||||
|
}
|
||||||
|
codeCopy := getData(code, uint64CodeOffset, lengthU64)
|
||||||
|
scope.Memory.Set(memOffset.Uint64(), lengthU64, codeCopy)
|
||||||
|
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
@ -440,9 +449,14 @@ func opExtCodeHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext)
|
||||||
address := common.Address(slot.Bytes20())
|
address := common.Address(slot.Bytes20())
|
||||||
if interpreter.evm.StateDB.Empty(address) {
|
if interpreter.evm.StateDB.Empty(address) {
|
||||||
slot.Clear()
|
slot.Clear()
|
||||||
|
} else {
|
||||||
|
code := interpreter.evm.StateDB.GetCode(address)
|
||||||
|
if HasEOFByte(code) {
|
||||||
|
slot.SetFromHex("0x9dbf3648db8210552e9c4f75c6a1c3057c0ca432043bd648be15fe7be05646f5")
|
||||||
} else {
|
} else {
|
||||||
slot.SetBytes(interpreter.evm.StateDB.ResolveCodeHash(address).Bytes())
|
slot.SetBytes(interpreter.evm.StateDB.ResolveCodeHash(address).Bytes())
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return nil, nil
|
return nil, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -43,7 +43,6 @@ type StateDB interface {
|
||||||
GetCodeHash(common.Address) common.Hash
|
GetCodeHash(common.Address) common.Hash
|
||||||
GetCode(common.Address) []byte
|
GetCode(common.Address) []byte
|
||||||
SetCode(common.Address, []byte)
|
SetCode(common.Address, []byte)
|
||||||
SetCodeEOF(common.Address, []byte)
|
|
||||||
GetCodeSize(common.Address) int
|
GetCodeSize(common.Address) int
|
||||||
|
|
||||||
ResolveCodeHash(common.Address) common.Hash
|
ResolveCodeHash(common.Address) common.Hash
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue