Commit 2e3534ff authored by Mark Tyneway's avatar Mark Tyneway

op-bindings: handle L2 state

parent 8e605053
...@@ -64,6 +64,17 @@ func (s *StorageLayout) GetStorageLayoutEntry(name string) (StorageLayoutEntry, ...@@ -64,6 +64,17 @@ func (s *StorageLayout) GetStorageLayoutEntry(name string) (StorageLayoutEntry,
return StorageLayoutEntry{}, fmt.Errorf("%s not found", name) return StorageLayoutEntry{}, fmt.Errorf("%s not found", name)
} }
// GetStorageLayoutType returns the StorageLayoutType where the label matches
// the provided name.
func (s *StorageLayout) GetStorageLayoutType(name string) (StorageLayoutType, error) {
for typeName, typ := range s.Types {
if typeName == name {
return typ, nil
}
}
return StorageLayoutType{}, fmt.Errorf("%s not found", name)
}
type StorageLayoutEntry struct { type StorageLayoutEntry struct {
AstId uint `json:"astId"` AstId uint `json:"astId"`
Contract string `json:"contract"` Contract string `json:"contract"`
......
...@@ -603,11 +603,15 @@ func checkL2StandardBridge(addr common.Address, client *ethclient.Client) error ...@@ -603,11 +603,15 @@ func checkL2StandardBridge(addr common.Address, client *ethclient.Client) error
if messenger != predeploys.L2CrossDomainMessengerAddr { if messenger != predeploys.L2CrossDomainMessengerAddr {
return fmt.Errorf("L2StandardBridge MESSENGER should be %s, got %s", predeploys.L2CrossDomainMessengerAddr, messenger) return fmt.Errorf("L2StandardBridge MESSENGER should be %s, got %s", predeploys.L2CrossDomainMessengerAddr, messenger)
} }
version, err := contract.Version(&bind.CallOpts{}) version, err := contract.Version(&bind.CallOpts{})
if err != nil { if err != nil {
return err return err
} }
initialized, err := getInitialized("L2StandardBridge", addr, client)
if err != nil {
return err
}
log.Info("L2StandardBridge", "_initialized", initialized)
log.Info("L2StandardBridge version", "version", version) log.Info("L2StandardBridge version", "version", version)
return nil return nil
} }
...@@ -805,3 +809,48 @@ func getEIP1967ImplementationAddress(client *ethclient.Client, addr common.Addre ...@@ -805,3 +809,48 @@ func getEIP1967ImplementationAddress(client *ethclient.Client, addr common.Addre
impl := common.BytesToAddress(slot) impl := common.BytesToAddress(slot)
return impl, nil return impl, nil
} }
// checkPredeploy ensures that the predeploy at index i has the correct proxy admin set
func checkPredeploy(client *ethclient.Client, i uint64) error {
bigAddr := new(big.Int).Or(genesis.BigL2PredeployNamespace, new(big.Int).SetUint64(i))
addr := common.BigToAddress(bigAddr)
if !predeploys.IsProxied(addr) {
return nil
}
admin, err := getEIP1967AdminAddress(client, addr)
if err != nil {
return err
}
if admin != predeploys.ProxyAdminAddr {
return fmt.Errorf("%s does not have correct proxy admin set", addr)
}
return nil
}
// getInitialized will get the initialized value in storage of a contract.
// This is an incrementing number that starts at 1 and increments each time that
// the contract is upgraded.
func getInitialized(name string, addr common.Address, client *ethclient.Client) (*big.Int, error) {
layout, err := bindings.GetStorageLayout(name)
if err != nil {
return nil, err
}
entry, err := layout.GetStorageLayoutEntry("_initialized")
if err != nil {
return nil, err
}
typ, err := layout.GetStorageLayoutType(entry.Type)
if err != nil {
return nil, err
}
slot := common.BigToHash(big.NewInt(int64(entry.Slot)))
value, err := client.StorageAt(context.Background(), addr, slot, nil)
if err != nil {
return nil, err
}
if entry.Offset+typ.NumberOfBytes > uint(len(value)) {
return nil, fmt.Errorf("value length is too short")
}
initialized := new(big.Int).SetBytes(value[entry.Offset : entry.Offset+typ.NumberOfBytes])
return initialized, nil
}
...@@ -656,6 +656,11 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage ...@@ -656,6 +656,11 @@ func NewL2StorageConfig(config *DeployConfig, block *types.Block) (state.Storage
"xDomainMsgSender": "0x000000000000000000000000000000000000dEaD", "xDomainMsgSender": "0x000000000000000000000000000000000000dEaD",
"msgNonce": 0, "msgNonce": 0,
} }
storage["L2StandardBridge"] = state.StorageValues{
"_initialized": 2,
"_initializing": false,
"_MESSENGER": predeploys.L2CrossDomainMessengerAddr,
}
storage["L1Block"] = state.StorageValues{ storage["L1Block"] = state.StorageValues{
"number": block.Number(), "number": block.Number(),
"timestamp": block.Time(), "timestamp": block.Time(),
......
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