Skip to content

Commit

Permalink
feat: add validation for blocks interval in GetLastGlobalExitRoot, re…
Browse files Browse the repository at this point in the history
…names and comments
  • Loading branch information
Stefan-Ethernal committed Dec 9, 2024
1 parent dcca9ae commit b1cb788
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 13 deletions.
12 changes: 6 additions & 6 deletions cmd/importcombinedjson.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ type CombinedJSON struct {
RollupGasTokenAddress common.Address `json:"gasTokenAddress"`
DACAddress common.Address `json:"polygonDataCommitteeAddress"`
BatchL2Data string `json:"batchL2Data,omitempty"`
LastGlobalExitRoot common.Hash `json:"globalExitRoot,omitempty"`
RollupGlobalExitRoot common.Hash `json:"globalExitRoot,omitempty"`
}

func importCombinedJson(cliCtx *cli.Context) error {
Expand Down Expand Up @@ -77,9 +77,9 @@ func importCombinedJson(cliCtx *cli.Context) error {
}

var (
dacAddr common.Address
batchL2Data string
lastGlobalExitRoot common.Hash
dacAddr common.Address
batchL2Data string
rollupGlobalExitRoot common.Hash
)

switch rollupMetadata.VerifierType {
Expand All @@ -94,7 +94,7 @@ func importCombinedJson(cliCtx *cli.Context) error {
return fmt.Errorf("failed to retrieve batch l2 data %w", err)
}

lastGlobalExitRoot, err = r.GetLastGlobalExitRoot(rollupManager, client)
rollupGlobalExitRoot, err = r.GetRollupGlobalExitRoot(rollupManager, client)
if err != nil {
return fmt.Errorf("failed to retrieve batch l2 data %w", err)
}
Expand Down Expand Up @@ -128,7 +128,7 @@ func importCombinedJson(cliCtx *cli.Context) error {
RollupGasTokenAddress: rollupMetadata.GasToken,
DACAddress: dacAddr,
BatchL2Data: batchL2Data,
LastGlobalExitRoot: lastGlobalExitRoot,
RollupGlobalExitRoot: rollupGlobalExitRoot,
}

raw, err := json.MarshalIndent(combinedJson, "", " ")
Expand Down
19 changes: 12 additions & 7 deletions rollup/rollup_pessimistic_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ func (r *RollupPessimisticProofs) GetBatchL2Data(client bind.ContractBackend) (s
return hexutil.Encode(rawTxWithSignature), nil
}

// GetLastGlobalExitRoot retrieves the last global exit root from global exit root manager
func (r *RollupPessimisticProofs) GetLastGlobalExitRoot(rm *rollupmanager.RollupManager, client bind.ContractBackend) (common.Hash, error) {
// GetRollupGlobalExitRoot retrieves the actual global exit root at the rollup creation time
func (r *RollupPessimisticProofs) GetRollupGlobalExitRoot(rm *rollupmanager.RollupManager, client bind.ContractBackend) (common.Hash, error) {
gerContract, err := polygonzkevmglobalexitrootv2.NewPolygonzkevmglobalexitrootv2(rm.GERAddr, client)
if err != nil {
return common.Hash{}, err
Expand All @@ -128,12 +128,17 @@ func (r *RollupPessimisticProofs) GetLastGlobalExitRoot(rm *rollupmanager.Rollup
}

endBlock := r.CreationBlock - 1
iter, err := gerContract.FilterUpdateL1InfoTree(
&bind.FilterOpts{
Start: rm.UpdateToULxLyBlock,
End: &endBlock,
}, nil, nil)

if endBlock < rm.UpdateToULxLyBlock {
return common.Hash{}, fmt.Errorf("end block (%d) is less than starting block (%d) in UpdateL1InfoTree filter",
rm.UpdateToULxLyBlock, endBlock)
}

filter := &bind.FilterOpts{
Start: rm.UpdateToULxLyBlock,
End: &endBlock,
}
iter, err := gerContract.FilterUpdateL1InfoTree(filter, nil, nil)
if err != nil {
return common.Hash{}, err
}
Expand Down

0 comments on commit b1cb788

Please sign in to comment.