Skip to content

Commit 88edd3a

Browse files
Merge pull request #4087 from OffchainLabs/backport-validate-non-empty-genesis
Modify validateGenesisAssertion to handle non-empty genesis (#4031)
2 parents f9ac116 + 82c3b83 commit 88edd3a

File tree

1 file changed

+26
-4
lines changed

1 file changed

+26
-4
lines changed

cmd/nitro/init.go

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
909909
return chainDb, nil, err
910910
}
911911
if config.Init.ValidateGenesisAssertion {
912-
if err := validateGenesisAssertion(ctx, rollupAddrs.Rollup, l1Client, l2BlockChain.Genesis().Hash(), initDataReaderHasAccounts); err != nil {
912+
if err := validateGenesisAssertion(ctx, rollupAddrs.Rollup, l1Client, l2BlockChain.Genesis(), initDataReaderHasAccounts); err != nil {
913913
if !config.Init.Force {
914914
return chainDb, nil, fmt.Errorf("error testing genesis assertion: %w", err)
915915
}
@@ -937,7 +937,7 @@ func openInitializeChainDb(ctx context.Context, stack *node.Node, config *NodeCo
937937
return rebuildLocalWasm(ctx, &config.Execution, l2BlockChain, chainDb, wasmDb, config.Init.RebuildLocalWasm)
938938
}
939939

940-
func validateGenesisAssertion(ctx context.Context, rollupAddress common.Address, l1Client *ethclient.Client, genesisBlockHash common.Hash, initDataReaderHasAccounts bool) error {
940+
func validateGenesisAssertion(ctx context.Context, rollupAddress common.Address, l1Client *ethclient.Client, genesis *types.Block, initDataReaderHasAccounts bool) error {
941941
if l1Client == nil {
942942
return fmt.Errorf("no l1 client")
943943
}
@@ -959,15 +959,37 @@ func validateGenesisAssertion(ctx context.Context, rollupAddress common.Address,
959959
}
960960
genesisAssertionCreationInfo, err := bold.ReadBoldAssertionCreationInfo(ctx, userLogic, l1Client, rollupAddress, genesisAssertionHash)
961961
if err != nil {
962-
return err
962+
// If we can't find the empty genesis assertion, try to compute the assertion for non-empty genesis
963+
genesisGlobalState := protocol.GoGlobalState{
964+
BlockHash: genesis.Hash(),
965+
SendRoot: types.DeserializeHeaderExtraInformation(genesis.Header()).SendRoot,
966+
Batch: 1,
967+
PosInBatch: 0,
968+
}
969+
genesisAssertionState := rollupgen.AssertionState{
970+
GlobalState: rollupgen.GlobalState{
971+
Bytes32Vals: genesisGlobalState.AsSolidityStruct().Bytes32Vals,
972+
U64Vals: genesisGlobalState.AsSolidityStruct().U64Vals,
973+
},
974+
MachineStatus: 1,
975+
EndHistoryRoot: [32]byte{},
976+
}
977+
genesisAssertionHash, err = userLogic.ComputeAssertionHash(&bind.CallOpts{Context: ctx}, common.Hash{}, genesisAssertionState, common.Hash{})
978+
if err != nil {
979+
return err
980+
}
981+
genesisAssertionCreationInfo, err = bold.ReadBoldAssertionCreationInfo(ctx, userLogic, l1Client, rollupAddress, genesisAssertionHash)
982+
if err != nil {
983+
return err
984+
}
963985
}
964986
beforeGlobalState := protocol.GoGlobalStateFromSolidity(genesisAssertionCreationInfo.BeforeState.GlobalState)
965987
afterGlobalState := protocol.GoGlobalStateFromSolidity(genesisAssertionCreationInfo.AfterState.GlobalState)
966988
isNullAssertion := beforeGlobalState.Batch == afterGlobalState.Batch && beforeGlobalState.PosInBatch == afterGlobalState.PosInBatch
967989
if isNullAssertion && initDataReaderHasAccounts {
968990
return errors.New("genesis assertion is null but there are accounts in the init data")
969991
}
970-
if !isNullAssertion && afterGlobalState.BlockHash != genesisBlockHash {
992+
if !isNullAssertion && afterGlobalState.BlockHash != genesis.Hash() {
971993
return errors.New("genesis assertion is non null and its afterGlobalState.BlockHash doesn't match the genesis blockHash")
972994
}
973995
return nil

0 commit comments

Comments
 (0)