core: update according to latest specs

This commit is contained in:
zsfelfoldi 2026-01-21 03:52:58 +01:00 committed by Jared Wasinger
parent 5ebefb21bf
commit 6e3c6162b4
3 changed files with 32 additions and 15 deletions

View file

@ -120,7 +120,7 @@ func testEthTransferLogs(t *testing.T, value uint64) {
var expLogs = []*types.Log{ var expLogs = []*types.Log{
{ {
Address: types.EthTransferLogAddress, Address: types.EthSystemLogAddress,
Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr1), addr2hash(addr2)}, Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr1), addr2hash(addr2)},
Data: u256(value), Data: u256(value),
}, },
@ -130,7 +130,7 @@ func testEthTransferLogs(t *testing.T, value uint64) {
Data: nil, Data: nil,
}, },
{ {
Address: types.EthTransferLogAddress, Address: types.EthSystemLogAddress,
Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr2), addr2hash(addr3)}, Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr2), addr2hash(addr3)},
Data: u256(value / 2), Data: u256(value / 2),
}, },
@ -140,7 +140,7 @@ func testEthTransferLogs(t *testing.T, value uint64) {
Data: nil, Data: nil,
}, },
{ {
Address: types.EthTransferLogAddress, Address: types.EthSystemLogAddress,
Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr3), addr2hash(addr4)}, Topics: []common.Hash{types.EthTransferLogTopic0, addr2hash(addr3), addr2hash(addr4)},
Data: u256(value / 2), Data: u256(value / 2),
}, },

View file

@ -68,25 +68,42 @@ type logMarshaling struct {
var ( var (
// system contract address // system contract address
EthTransferLogAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe") EthSystemLogAddress = common.HexToAddress("0xfffffffffffffffffffffffffffffffffffffffe")
// keccak256('Transfer(address,address,uint256)') // keccak256('Transfer(address,address,uint256)')
EthTransferLogTopic0 = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef") EthTransferLogTopic0 = common.HexToHash("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
// keccak256('Selfdestruct(address,uint256)')
EthBurnLogTopic0 = common.HexToHash("0x4bfaba3443c1a1836cd362418edc679fc96cae8449cbefccb6457cdf2c943083")
) )
// EthTransferLog creates and ETH transfer log according to EIP-7708. // EthTransferLog creates and ETH transfer log according to EIP-7708.
// Specification: https://eips.ethereum.org/EIPS/eip-7708 // Specification: https://eips.ethereum.org/EIPS/eip-7708
func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log { func EthTransferLog(blockNumber *big.Int, from, to common.Address, amount *uint256.Int) *Log {
topics := make([]common.Hash, 3)
topics[0] = EthTransferLogTopic0
copy(topics[1][common.HashLength-common.AddressLength:], from[:])
copy(topics[2][common.HashLength-common.AddressLength:], to[:])
amount32 := amount.Bytes32() amount32 := amount.Bytes32()
data := make([]byte, 32)
copy(data, amount32[:])
return &Log{ return &Log{
Address: EthTransferLogAddress, Address: EthSystemLogAddress,
Topics: topics, Topics: []common.Hash{
Data: data, EthTransferLogTopic0,
common.BytesToHash(from.Bytes()),
common.BytesToHash(to.Bytes()),
},
Data: amount32[:],
// This is a non-consensus field, but assigned here because
// core/state doesn't know the current block number.
BlockNumber: blockNumber.Uint64(),
}
}
// EthBurnLog creates and ETH self-destruct burn log according to EIP-7708.
// Specification: https://eips.ethereum.org/EIPS/eip-7708
func EthBurnLog(blockNumber *big.Int, from common.Address, amount *uint256.Int) *Log {
amount32 := amount.Bytes32()
return &Log{
Address: EthSystemLogAddress,
Topics: []common.Hash{
EthBurnLogTopic0,
common.BytesToHash(from.Bytes()),
},
Data: amount32[:],
// This is a non-consensus field, but assigned here because // This is a non-consensus field, but assigned here because
// core/state doesn't know the current block number. // core/state doesn't know the current block number.
BlockNumber: blockNumber.Uint64(), BlockNumber: blockNumber.Uint64(),

View file

@ -899,7 +899,7 @@ func opSelfdestruct(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, error) {
if this != beneficiary { if this != beneficiary {
evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance))
} else { } else {
evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, common.Address{}, balance)) evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance))
} }
} }
evm.StateDB.SelfDestruct(this) evm.StateDB.SelfDestruct(this)
@ -944,7 +944,7 @@ func opSelfdestruct6780(pc *uint64, evm *EVM, scope *ScopeContext) ([]byte, erro
if this != beneficiary { if this != beneficiary {
evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance)) evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, beneficiary, balance))
} else if newContract { } else if newContract {
evm.StateDB.AddLog(types.EthTransferLog(evm.Context.BlockNumber, this, common.Address{}, balance)) evm.StateDB.AddLog(types.EthBurnLog(evm.Context.BlockNumber, this, balance))
} }
} }