Commit 72166a68 authored by protolambda's avatar protolambda

go: Address.Hash() util replacement

parent ac2df11b
...@@ -724,7 +724,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage ...@@ -724,7 +724,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
"basefee": block.BaseFee(), "basefee": block.BaseFee(),
"hash": block.Hash(), "hash": block.Hash(),
"sequenceNumber": 0, "sequenceNumber": 0,
"batcherHash": config.BatchSenderAddress.Hash(), "batcherHash": eth.AddressAsLeftPaddedHash(config.BatchSenderAddress),
"l1FeeOverhead": config.GasPriceOracleOverhead, "l1FeeOverhead": config.GasPriceOracleOverhead,
"l1FeeScalar": config.GasPriceOracleScalar, "l1FeeScalar": config.GasPriceOracleScalar,
} }
......
...@@ -14,6 +14,7 @@ import ( ...@@ -14,6 +14,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys" "github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/deployer" "github.com/ethereum-optimism/optimism/op-chain-ops/deployer"
"github.com/ethereum-optimism/optimism/op-service/eth"
"github.com/ethereum/go-ethereum/accounts/abi/bind" "github.com/ethereum/go-ethereum/accounts/abi/bind"
"github.com/ethereum/go-ethereum/accounts/abi/bind/backends" "github.com/ethereum/go-ethereum/accounts/abi/bind/backends"
"github.com/ethereum/go-ethereum/core/state" "github.com/ethereum/go-ethereum/core/state"
...@@ -118,7 +119,7 @@ func TestBuildL1DeveloperGenesis(t *testing.T) { ...@@ -118,7 +119,7 @@ func TestBuildL1DeveloperGenesis(t *testing.T) {
require.Equal(t, scalar.Uint64(), config.GasPriceOracleScalar) require.Equal(t, scalar.Uint64(), config.GasPriceOracleScalar)
batcherHash, err := sysCfg.BatcherHash(&bind.CallOpts{}) batcherHash, err := sysCfg.BatcherHash(&bind.CallOpts{})
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, common.Hash(batcherHash), config.BatchSenderAddress.Hash()) require.Equal(t, common.Hash(batcherHash), eth.AddressAsLeftPaddedHash(config.BatchSenderAddress))
gasLimit, err := sysCfg.GasLimit(&bind.CallOpts{}) gasLimit, err := sysCfg.GasLimit(&bind.CallOpts{})
require.NoError(t, err) require.NoError(t, err)
require.Equal(t, gasLimit, uint64(config.L2GenesisBlockGasLimit)) require.Equal(t, gasLimit, uint64(config.L2GenesisBlockGasLimit))
......
...@@ -10,6 +10,7 @@ import ( ...@@ -10,6 +10,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/predeploys" "github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/immutables" "github.com/ethereum-optimism/optimism/op-chain-ops/immutables"
"github.com/ethereum-optimism/optimism/op-chain-ops/state" "github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum-optimism/optimism/op-service/eth"
) )
// BuildL2DeveloperGenesis will build the L2 genesis block. // BuildL2DeveloperGenesis will build the L2 genesis block.
...@@ -62,7 +63,7 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene ...@@ -62,7 +63,7 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
return nil, fmt.Errorf("error converting to code namespace: %w", err) return nil, fmt.Errorf("error converting to code namespace: %w", err)
} }
db.CreateAccount(codeAddr) db.CreateAccount(codeAddr)
db.SetState(addr, ImplementationSlot, codeAddr.Hash()) db.SetState(addr, ImplementationSlot, eth.AddressAsLeftPaddedHash(codeAddr))
log.Info("Set proxy", "name", name, "address", addr, "implementation", codeAddr) log.Info("Set proxy", "name", name, "address", addr, "implementation", codeAddr)
} else { } else {
db.DeleteState(addr, AdminSlot) db.DeleteState(addr, AdminSlot)
......
...@@ -18,6 +18,7 @@ import ( ...@@ -18,6 +18,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings" "github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys" "github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis" "github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-service/eth"
) )
var writeFile bool var writeFile bool
...@@ -58,7 +59,7 @@ func testBuildL2Genesis(t *testing.T, config *genesis.DeployConfig) *core.Genesi ...@@ -58,7 +59,7 @@ func testBuildL2Genesis(t *testing.T, config *genesis.DeployConfig) *core.Genesi
(!config.EnableGovernance && addr == predeploys.GovernanceTokenAddr) (!config.EnableGovernance && addr == predeploys.GovernanceTokenAddr)
if isProxy { if isProxy {
require.Equal(t, true, ok, name) require.Equal(t, true, ok, name)
require.Equal(t, predeploys.ProxyAdminAddr.Hash(), adminSlot) require.Equal(t, eth.AddressAsLeftPaddedHash(predeploys.ProxyAdminAddr), adminSlot)
require.Equal(t, proxyBytecode, account.Code) require.Equal(t, proxyBytecode, account.Code)
} else { } else {
require.Equal(t, false, ok, name) require.Equal(t, false, ok, name)
......
...@@ -4,13 +4,14 @@ import ( ...@@ -4,13 +4,14 @@ import (
"errors" "errors"
"math/big" "math/big"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-chain-ops/immutables"
"github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/vm" "github.com/ethereum/go-ethereum/core/vm"
"github.com/ethereum/go-ethereum/log" "github.com/ethereum/go-ethereum/log"
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-chain-ops/immutables"
"github.com/ethereum-optimism/optimism/op-chain-ops/state"
"github.com/ethereum-optimism/optimism/op-service/eth"
) )
// PrecompileCount represents the number of precompile addresses // PrecompileCount represents the number of precompile addresses
...@@ -46,7 +47,7 @@ func setProxies(db vm.StateDB, proxyAdminAddr common.Address, namespace *big.Int ...@@ -46,7 +47,7 @@ func setProxies(db vm.StateDB, proxyAdminAddr common.Address, namespace *big.Int
} }
db.SetCode(addr, depBytecode) db.SetCode(addr, depBytecode)
db.SetState(addr, AdminSlot, proxyAdminAddr.Hash()) db.SetState(addr, AdminSlot, eth.AddressAsLeftPaddedHash(proxyAdminAddr))
log.Trace("Set proxy", "address", addr, "admin", proxyAdminAddr) log.Trace("Set proxy", "address", addr, "admin", proxyAdminAddr)
} }
......
...@@ -8,11 +8,12 @@ import ( ...@@ -8,11 +8,12 @@ import (
"regexp" "regexp"
"strings" "strings"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil" "github.com/ethereum/go-ethereum/common/hexutil"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum-optimism/optimism/op-service/eth"
) )
// EncodeStorageKeyValue encodes the key value pair that is stored in state // EncodeStorageKeyValue encodes the key value pair that is stored in state
...@@ -330,20 +331,20 @@ func encodeAddressValue(value any) (common.Hash, error) { ...@@ -330,20 +331,20 @@ func encodeAddressValue(value any) (common.Hash, error) {
if !ok { if !ok {
return common.Hash{}, errInvalidType return common.Hash{}, errInvalidType
} }
return address.Hash(), nil return eth.AddressAsLeftPaddedHash(*address), nil
} else { } else {
address, ok := value.(common.Address) address, ok := value.(common.Address)
if !ok { if !ok {
return common.Hash{}, errInvalidType return common.Hash{}, errInvalidType
} }
return address.Hash(), nil return eth.AddressAsLeftPaddedHash(address), nil
} }
case "string": case "string":
address, ok := value.(string) address, ok := value.(string)
if !ok { if !ok {
return common.Hash{}, errInvalidType return common.Hash{}, errInvalidType
} }
return common.HexToAddress(address).Hash(), nil return eth.AddressAsLeftPaddedHash(common.HexToAddress(address)), nil
default: default:
return common.Hash{}, errInvalidType return common.Hash{}, errInvalidType
} }
......
...@@ -80,7 +80,7 @@ func TestBatcherKeyRotation(gt *testing.T) { ...@@ -80,7 +80,7 @@ func TestBatcherKeyRotation(gt *testing.T) {
require.Equal(t, dp.Addresses.SysCfgOwner, owner, "system config owner mismatch") require.Equal(t, dp.Addresses.SysCfgOwner, owner, "system config owner mismatch")
// Change the batch sender key to Bob! // Change the batch sender key to Bob!
tx, err := sysCfgContract.SetBatcherHash(sysCfgOwner, dp.Addresses.Bob.Hash()) tx, err := sysCfgContract.SetBatcherHash(sysCfgOwner, eth.AddressAsLeftPaddedHash(dp.Addresses.Bob))
require.NoError(t, err) require.NoError(t, err)
t.Logf("batcher changes in L1 tx %s", tx.Hash()) t.Logf("batcher changes in L1 tx %s", tx.Hash())
miner.ActL1StartBlock(12)(t) miner.ActL1StartBlock(12)(t)
......
...@@ -10,6 +10,8 @@ import ( ...@@ -10,6 +10,8 @@ import (
"github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types" "github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto" "github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/optimism/op-service/eth"
) )
var ( var (
...@@ -143,11 +145,11 @@ func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueDat ...@@ -143,11 +145,11 @@ func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueDat
func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.DepositTx) (*types.Log, error) { func MarshalDepositLogEvent(depositContractAddr common.Address, deposit *types.DepositTx) (*types.Log, error) {
toBytes := common.Hash{} toBytes := common.Hash{}
if deposit.To != nil { if deposit.To != nil {
toBytes = deposit.To.Hash() toBytes = eth.AddressAsLeftPaddedHash(*deposit.To)
} }
topics := []common.Hash{ topics := []common.Hash{
DepositEventABIHash, DepositEventABIHash,
deposit.From.Hash(), eth.AddressAsLeftPaddedHash(deposit.From),
toBytes, toBytes,
DepositEventVersion0, DepositEventVersion0,
} }
......
...@@ -97,7 +97,7 @@ func FuzzL1InfoAgainstContract(f *testing.F) { ...@@ -97,7 +97,7 @@ func FuzzL1InfoAgainstContract(f *testing.F) {
BytesToBigInt(baseFee), BytesToBigInt(baseFee),
common.BytesToHash(hash), common.BytesToHash(hash),
seqNumber, seqNumber,
common.BytesToAddress(batcherHash).Hash(), eth.AddressAsLeftPaddedHash(common.BytesToAddress(batcherHash)),
common.BytesToHash(l1FeeOverhead).Big(), common.BytesToHash(l1FeeOverhead).Big(),
common.BytesToHash(l1FeeScalar).Big(), common.BytesToHash(l1FeeScalar).Big(),
) )
......
package eth
import "github.com/ethereum/go-ethereum/common"
// AddressAsLeftPaddedHash converts an address to a hash by left-padding it with zeros.
// No hashing is performed.
// This was previously known as Address.Hash(),
// but removed from go-ethereum in PR 28228, because the naming was not clear.
func AddressAsLeftPaddedHash(addr common.Address) (out common.Hash) {
copy(out[32-20:], addr[:])
return
}
...@@ -371,19 +371,19 @@ func OvmOwners(conf *OvmOwnersConfig) HeadFn { ...@@ -371,19 +371,19 @@ func OvmOwners(conf *OvmOwnersConfig) HeadFn {
// Address manager owner // Address manager owner
// Ownable, first storage slot // Ownable, first storage slot
headState.SetState(addressManager, common.Hash{}, conf.Owner.Hash()) headState.SetState(addressManager, common.Hash{}, eth.AddressAsLeftPaddedHash(conf.Owner))
// L1SB proxy owner // L1SB proxy owner
headState.SetState(l1SBProxy, ownerSlot, conf.Owner.Hash()) headState.SetState(l1SBProxy, ownerSlot, eth.AddressAsLeftPaddedHash(conf.Owner))
// L1XDM owner // L1XDM owner
// 0x33 = 51. L1CrossDomainMessenger is L1CrossDomainMessenger (0) Lib_AddressResolver (1) OwnableUpgradeable (1, but covered by gap) + ContextUpgradeable (special gap of 50) and then _owner // 0x33 = 51. L1CrossDomainMessenger is L1CrossDomainMessenger (0) Lib_AddressResolver (1) OwnableUpgradeable (1, but covered by gap) + ContextUpgradeable (special gap of 50) and then _owner
headState.SetState(l1XDMProxy, common.Hash{31: 0x33}, conf.Owner.Hash()) headState.SetState(l1XDMProxy, common.Hash{31: 0x33}, eth.AddressAsLeftPaddedHash(conf.Owner))
// L1 ERC721 bridge owner // L1 ERC721 bridge owner
headState.SetState(l1ERC721BridgeProxy, ownerSlot, conf.Owner.Hash()) headState.SetState(l1ERC721BridgeProxy, ownerSlot, eth.AddressAsLeftPaddedHash(conf.Owner))
// Legacy sequencer/proposer addresses // Legacy sequencer/proposer addresses
// See AddressManager.sol "addresses" mapping(bytes32 => address), at slot position 1 // See AddressManager.sol "addresses" mapping(bytes32 => address), at slot position 1
addressesSlot := common.BigToHash(big.NewInt(1)) addressesSlot := common.BigToHash(big.NewInt(1))
headState.SetState(addressManager, crypto.Keccak256Hash(crypto.Keccak256([]byte("OVM_Sequencer")), addressesSlot.Bytes()), conf.Sequencer.Hash()) headState.SetState(addressManager, crypto.Keccak256Hash(crypto.Keccak256([]byte("OVM_Sequencer")), addressesSlot.Bytes()), eth.AddressAsLeftPaddedHash(conf.Sequencer))
headState.SetState(addressManager, crypto.Keccak256Hash(crypto.Keccak256([]byte("OVM_Proposer")), addressesSlot.Bytes()), conf.Proposer.Hash()) headState.SetState(addressManager, crypto.Keccak256Hash(crypto.Keccak256([]byte("OVM_Proposer")), addressesSlot.Bytes()), eth.AddressAsLeftPaddedHash(conf.Proposer))
// Fund sequencer and proposer with 100 ETH // Fund sequencer and proposer with 100 ETH
headState.SetBalance(conf.Sequencer, HundredETH) headState.SetBalance(conf.Sequencer, HundredETH)
headState.SetBalance(conf.Proposer, HundredETH) headState.SetBalance(conf.Proposer, HundredETH)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment