fix(trace): record account proof for ErrContractAddressCollision (#488)

* fix(trace): record account proof for ErrContractAddressCollision

* bump version

* fix memory reading

* bump version

---------

Co-authored-by: Péter Garamvölgyi <peter@scroll.io>
Co-authored-by: HAOYUatHZ <37070449+HAOYUatHZ@users.noreply.github.com>
Co-authored-by: HAOYUatHZ <haoyu@protonmail.com>
This commit is contained in:
Zhang Zhuo 2023-09-04 12:05:42 +08:00 committed by GitHub
parent c60fa3a643
commit 2d9d48d463
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 25 additions and 1 deletions

View file

@ -31,6 +31,7 @@ import (
"github.com/scroll-tech/go-ethereum/common/hexutil" "github.com/scroll-tech/go-ethereum/common/hexutil"
"github.com/scroll-tech/go-ethereum/common/math" "github.com/scroll-tech/go-ethereum/common/math"
"github.com/scroll-tech/go-ethereum/core/types" "github.com/scroll-tech/go-ethereum/core/types"
"github.com/scroll-tech/go-ethereum/crypto"
"github.com/scroll-tech/go-ethereum/log" "github.com/scroll-tech/go-ethereum/log"
"github.com/scroll-tech/go-ethereum/params" "github.com/scroll-tech/go-ethereum/params"
) )
@ -275,6 +276,29 @@ func (l *StructLogger) CaptureState(pc uint64, op OpCode, gas, cost uint64, scop
extraData.Caller = append(extraData.Caller, getWrappedAccountForAddr(l, scope.Contract.Address())) extraData.Caller = append(extraData.Caller, getWrappedAccountForAddr(l, scope.Contract.Address()))
} }
// in reality it is impossible for CREATE to trigger ErrContractAddressCollision
if op == CREATE2 && opErr == nil {
_ = stack.data[stack.len()-1] // value
offset := stack.data[stack.len()-2]
size := stack.data[stack.len()-3]
salt := stack.data[stack.len()-4]
// `CaptureState` is called **before** memory resizing
// So sometimes we need to auto pad 0.
code := getData(scope.Memory.Data(), offset.Uint64(), size.Uint64())
codeAndHash := &codeAndHash{code: code}
address := crypto.CreateAddress2(contract.Address(), salt.Bytes32(), codeAndHash.Hash().Bytes())
contractHash := l.env.StateDB.GetKeccakCodeHash(address)
if l.env.StateDB.GetNonce(address) != 0 || (contractHash != (common.Hash{}) && contractHash != emptyKeccakCodeHash) {
extraData := structLog.getOrInitExtraData()
wrappedStatus := getWrappedAccountForAddr(l, address)
extraData.StateList = append(extraData.StateList, wrappedStatus)
l.statesAffected[address] = struct{}{}
}
}
structLog.RefundCounter = l.env.StateDB.GetRefund() structLog.RefundCounter = l.env.StateDB.GetRefund()
l.logs = append(l.logs, structLog) l.logs = append(l.logs, structLog)
} }

View file

@ -24,7 +24,7 @@ import (
const ( const (
VersionMajor = 4 // Major version component of the current release VersionMajor = 4 // Major version component of the current release
VersionMinor = 3 // Minor version component of the current release VersionMinor = 3 // Minor version component of the current release
VersionPatch = 61 // Patch version component of the current release VersionPatch = 62 // Patch version component of the current release
VersionMeta = "sepolia" // Version metadata to append to the version string VersionMeta = "sepolia" // Version metadata to append to the version string
) )