Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
72166a68
Unverified
Commit
72166a68
authored
Oct 12, 2023
by
protolambda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
go: Address.Hash() util replacement
parent
ac2df11b
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
43 additions
and
24 deletions
+43
-24
config.go
op-chain-ops/genesis/config.go
+1
-1
layer_one_test.go
op-chain-ops/genesis/layer_one_test.go
+2
-1
layer_two.go
op-chain-ops/genesis/layer_two.go
+2
-1
layer_two_test.go
op-chain-ops/genesis/layer_two_test.go
+2
-1
setters.go
op-chain-ops/genesis/setters.go
+6
-5
encoding.go
op-chain-ops/state/encoding.go
+6
-5
system_config_test.go
op-e2e/actions/system_config_test.go
+1
-1
deposit_log.go
op-node/rollup/derive/deposit_log.go
+4
-2
fuzz_parsers_test.go
op-node/rollup/derive/fuzz_parsers_test.go
+1
-1
address.go
op-service/eth/address.go
+12
-0
cheat.go
op-wheel/cheat/cheat.go
+6
-6
No files found.
op-chain-ops/genesis/config.go
View file @
72166a68
...
...
@@ -724,7 +724,7 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
"basefee"
:
block
.
BaseFee
(),
"hash"
:
block
.
Hash
(),
"sequenceNumber"
:
0
,
"batcherHash"
:
config
.
BatchSenderAddress
.
Hash
(
),
"batcherHash"
:
eth
.
AddressAsLeftPaddedHash
(
config
.
BatchSenderAddress
),
"l1FeeOverhead"
:
config
.
GasPriceOracleOverhead
,
"l1FeeScalar"
:
config
.
GasPriceOracleScalar
,
}
...
...
op-chain-ops/genesis/layer_one_test.go
View file @
72166a68
...
...
@@ -14,6 +14,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"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/backends"
"github.com/ethereum/go-ethereum/core/state"
...
...
@@ -118,7 +119,7 @@ func TestBuildL1DeveloperGenesis(t *testing.T) {
require
.
Equal
(
t
,
scalar
.
Uint64
(),
config
.
GasPriceOracleScalar
)
batcherHash
,
err
:=
sysCfg
.
BatcherHash
(
&
bind
.
CallOpts
{})
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
{})
require
.
NoError
(
t
,
err
)
require
.
Equal
(
t
,
gasLimit
,
uint64
(
config
.
L2GenesisBlockGasLimit
))
...
...
op-chain-ops/genesis/layer_two.go
View file @
72166a68
...
...
@@ -10,6 +10,7 @@ import (
"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/state"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
// BuildL2DeveloperGenesis will build the L2 genesis block.
...
...
@@ -62,7 +63,7 @@ func BuildL2Genesis(config *DeployConfig, l1StartBlock *types.Block) (*core.Gene
return
nil
,
fmt
.
Errorf
(
"error converting to code namespace: %w"
,
err
)
}
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
)
}
else
{
db
.
DeleteState
(
addr
,
AdminSlot
)
...
...
op-chain-ops/genesis/layer_two_test.go
View file @
72166a68
...
...
@@ -18,6 +18,7 @@ import (
"github.com/ethereum-optimism/optimism/op-bindings/bindings"
"github.com/ethereum-optimism/optimism/op-bindings/predeploys"
"github.com/ethereum-optimism/optimism/op-chain-ops/genesis"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
var
writeFile
bool
...
...
@@ -58,7 +59,7 @@ func testBuildL2Genesis(t *testing.T, config *genesis.DeployConfig) *core.Genesi
(
!
config
.
EnableGovernance
&&
addr
==
predeploys
.
GovernanceTokenAddr
)
if
isProxy
{
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
)
}
else
{
require
.
Equal
(
t
,
false
,
ok
,
name
)
...
...
op-chain-ops/genesis/setters.go
View file @
72166a68
...
...
@@ -4,13 +4,14 @@ import (
"errors"
"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/core/vm"
"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
...
...
@@ -46,7 +47,7 @@ func setProxies(db vm.StateDB, proxyAdminAddr common.Address, namespace *big.Int
}
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
)
}
...
...
op-chain-ops/state/encoding.go
View file @
72166a68
...
...
@@ -8,11 +8,12 @@ import (
"regexp"
"strings"
"github.com/ethereum-optimism/optimism/op-bindings/solc"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/common/hexutil"
"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
...
...
@@ -330,20 +331,20 @@ func encodeAddressValue(value any) (common.Hash, error) {
if
!
ok
{
return
common
.
Hash
{},
errInvalidType
}
return
address
.
Hash
(
),
nil
return
eth
.
AddressAsLeftPaddedHash
(
*
address
),
nil
}
else
{
address
,
ok
:=
value
.
(
common
.
Address
)
if
!
ok
{
return
common
.
Hash
{},
errInvalidType
}
return
address
.
Hash
(
),
nil
return
eth
.
AddressAsLeftPaddedHash
(
address
),
nil
}
case
"string"
:
address
,
ok
:=
value
.
(
string
)
if
!
ok
{
return
common
.
Hash
{},
errInvalidType
}
return
common
.
HexToAddress
(
address
)
.
Hash
(
),
nil
return
eth
.
AddressAsLeftPaddedHash
(
common
.
HexToAddress
(
address
)
),
nil
default
:
return
common
.
Hash
{},
errInvalidType
}
...
...
op-e2e/actions/system_config_test.go
View file @
72166a68
...
...
@@ -80,7 +80,7 @@ func TestBatcherKeyRotation(gt *testing.T) {
require
.
Equal
(
t
,
dp
.
Addresses
.
SysCfgOwner
,
owner
,
"system config owner mismatch"
)
// 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
)
t
.
Logf
(
"batcher changes in L1 tx %s"
,
tx
.
Hash
())
miner
.
ActL1StartBlock
(
12
)(
t
)
...
...
op-node/rollup/derive/deposit_log.go
View file @
72166a68
...
...
@@ -10,6 +10,8 @@ import (
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/crypto"
"github.com/ethereum-optimism/optimism/op-service/eth"
)
var
(
...
...
@@ -143,11 +145,11 @@ func unmarshalDepositVersion0(dep *types.DepositTx, to common.Address, opaqueDat
func
MarshalDepositLogEvent
(
depositContractAddr
common
.
Address
,
deposit
*
types
.
DepositTx
)
(
*
types
.
Log
,
error
)
{
toBytes
:=
common
.
Hash
{}
if
deposit
.
To
!=
nil
{
toBytes
=
deposit
.
To
.
Hash
(
)
toBytes
=
eth
.
AddressAsLeftPaddedHash
(
*
deposit
.
To
)
}
topics
:=
[]
common
.
Hash
{
DepositEventABIHash
,
deposit
.
From
.
Hash
(
),
eth
.
AddressAsLeftPaddedHash
(
deposit
.
From
),
toBytes
,
DepositEventVersion0
,
}
...
...
op-node/rollup/derive/fuzz_parsers_test.go
View file @
72166a68
...
...
@@ -97,7 +97,7 @@ func FuzzL1InfoAgainstContract(f *testing.F) {
BytesToBigInt
(
baseFee
),
common
.
BytesToHash
(
hash
),
seqNumber
,
common
.
BytesToAddress
(
batcherHash
)
.
Hash
(
),
eth
.
AddressAsLeftPaddedHash
(
common
.
BytesToAddress
(
batcherHash
)
),
common
.
BytesToHash
(
l1FeeOverhead
)
.
Big
(),
common
.
BytesToHash
(
l1FeeScalar
)
.
Big
(),
)
...
...
op-service/eth/address.go
0 → 100644
View file @
72166a68
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
}
op-wheel/cheat/cheat.go
View file @
72166a68
...
...
@@ -371,19 +371,19 @@ func OvmOwners(conf *OvmOwnersConfig) HeadFn {
// Address manager owner
// Ownable, first storage slot
headState
.
SetState
(
addressManager
,
common
.
Hash
{},
conf
.
Owner
.
Hash
(
))
headState
.
SetState
(
addressManager
,
common
.
Hash
{},
eth
.
AddressAsLeftPaddedHash
(
conf
.
Owner
))
// L1SB proxy owner
headState
.
SetState
(
l1SBProxy
,
ownerSlot
,
conf
.
Owner
.
Hash
(
))
headState
.
SetState
(
l1SBProxy
,
ownerSlot
,
eth
.
AddressAsLeftPaddedHash
(
conf
.
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
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
headState
.
SetState
(
l1ERC721BridgeProxy
,
ownerSlot
,
conf
.
Owner
.
Hash
(
))
headState
.
SetState
(
l1ERC721BridgeProxy
,
ownerSlot
,
eth
.
AddressAsLeftPaddedHash
(
conf
.
Owner
))
// Legacy sequencer/proposer addresses
// See AddressManager.sol "addresses" mapping(bytes32 => address), at slot position 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_Proposer"
)),
addressesSlot
.
Bytes
()),
conf
.
Proposer
.
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
()),
eth
.
AddressAsLeftPaddedHash
(
conf
.
Proposer
))
// Fund sequencer and proposer with 100 ETH
headState
.
SetBalance
(
conf
.
Sequencer
,
HundredETH
)
headState
.
SetBalance
(
conf
.
Proposer
,
HundredETH
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment