From b7fe238091a796e025cd980163c3913da7776fac Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Stefan=20Negovanovi=C4=87?= <93934272+Stefan-Ethernal@users.noreply.github.com> Date: Tue, 17 Dec 2024 10:44:50 +0100 Subject: [PATCH] fix: pessimistic proofs - handle zero gas token batchl2data (#27) * fix: handle 0x0 gas token encoding * feat: add new rollup definitions for Bali --- cmd/importrollupmanager.go | 2 +- config/config.go | 5 +++-- networks/sepolia/bali/rollups/20-cdk20.json | 13 +++++++++++++ networks/sepolia/bali/rollups/21-cdk21.json | 13 +++++++++++++ rollup/rollup_pessimistic_proofs.go | 20 ++++++++++++-------- 5 files changed, 42 insertions(+), 11 deletions(-) create mode 100644 networks/sepolia/bali/rollups/20-cdk20.json create mode 100644 networks/sepolia/bali/rollups/21-cdk21.json diff --git a/cmd/importrollupmanager.go b/cmd/importrollupmanager.go index fb16844..bb38af4 100644 --- a/cmd/importrollupmanager.go +++ b/cmd/importrollupmanager.go @@ -97,7 +97,7 @@ func importRollupManager(cliCtx *cli.Context) error { return err } for chainID, name := range rollups { - fmt.Println("importing rollup ", name, " with chainID ", chainID) + fmt.Println("importing rollup", name, "with chainID", chainID) r, err := rollup.LoadMetadataFromL1ByChainID(client, rm, chainID) if err != nil { return err diff --git a/config/config.go b/config/config.go index e1c1388..bfd2063 100644 --- a/config/config.go +++ b/config/config.go @@ -25,9 +25,10 @@ func Load(l1Network, rmAlias, rAlias, baseDir string) (*RPCs, *rollupmanager.Rol return nil, nil, nil, err } - fmt.Println("loading the rollup info from file") rollupPath := path.Join(rollupManagerPath, "rollups") - r, err := rollup.LoadMetadataFromFile(path.Join(rollupPath, rAlias+".json")) + rollupFile := path.Join(rollupPath, rAlias+".json") + fmt.Println("loading the rollup info from file", rollupFile) + r, err := rollup.LoadMetadataFromFile(rollupFile) if err != nil { return nil, nil, nil, err } diff --git a/networks/sepolia/bali/rollups/20-cdk20.json b/networks/sepolia/bali/rollups/20-cdk20.json new file mode 100644 index 0000000..5da7d1c --- /dev/null +++ b/networks/sepolia/bali/rollups/20-cdk20.json @@ -0,0 +1,13 @@ +{ + "Address": "0x25d24e2fc03407cee7a653af22bd5ed65b2a2222", + "GenesisRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "CreationBlock": 7265676, + "CreationBlockHash": "0x1c46f3eecd09aba4c2383611082430dd759fcfe1cfdc812820c776b0d051f985", + "CreationParentBlockHash": "0xb1c01b0031139ed5e31ccb07a91af6d3c84de237709cfdbf02376b231c67bd0b", + "CreationTimestamp": 1734030720, + "ChainID": 465, + "Name": "cdk20", + "RollupID": 20, + "GasToken": "0x0000000000000000000000000000000000000000", + "VerifierType": 1 +} \ No newline at end of file diff --git a/networks/sepolia/bali/rollups/21-cdk21.json b/networks/sepolia/bali/rollups/21-cdk21.json new file mode 100644 index 0000000..2694fe7 --- /dev/null +++ b/networks/sepolia/bali/rollups/21-cdk21.json @@ -0,0 +1,13 @@ +{ + "Address": "0x661e666e33d669eaf73fd287bdfa783652677d45", + "GenesisRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", + "CreationBlock": 7265676, + "CreationBlockHash": "0x1c46f3eecd09aba4c2383611082430dd759fcfe1cfdc812820c776b0d051f985", + "CreationParentBlockHash": "0xb1c01b0031139ed5e31ccb07a91af6d3c84de237709cfdbf02376b231c67bd0b", + "CreationTimestamp": 1734030720, + "ChainID": 466, + "Name": "cdk21", + "RollupID": 21, + "GasToken": "0x72293b2e981d4d0642531357f0792ae1b70bf1ab", + "VerifierType": 1 +} \ No newline at end of file diff --git a/rollup/rollup_pessimistic_proofs.go b/rollup/rollup_pessimistic_proofs.go index 71ea0d3..87cccdd 100644 --- a/rollup/rollup_pessimistic_proofs.go +++ b/rollup/rollup_pessimistic_proofs.go @@ -46,7 +46,10 @@ func (r *RollupPessimisticProofs) InitContract(ctx context.Context, client bind. // The logic is implemented according to the following snippet: // https://github.com/0xPolygonHermez/zkevm-contracts/blob/v9.0.0-rc.3-pp/deployment/v2/4_createRollup.ts#L404-L456 func (r *RollupPessimisticProofs) GetBatchL2Data(client bind.ContractBackend) (string, error) { - const maxDataLength = 65535 + const ( + maxTxDataLength = 65535 + gasLimit = uint64(30000000) + ) bridgeAddr, err := r.Contract.BridgeAddress(nil) if err != nil { @@ -63,9 +66,12 @@ func (r *RollupPessimisticProofs) GetBatchL2Data(client bind.ContractBackend) (s return "", err } - gasTokenMetadata, err := bridge.GetTokenMetadata(nil, r.GasToken) - if err != nil { - return "", err + gasTokenMetadata := []byte{} + if r.GasToken != common.HexToAddress("0x0") { + gasTokenMetadata, err = bridge.GetTokenMetadata(nil, r.GasToken) + if err != nil { + return "", err + } } bridgeABI, err := polygonzkevmbridgev2.Polygonzkevmbridgev2MetaData.GetAbi() @@ -84,16 +90,14 @@ func (r *RollupPessimisticProofs) GetBatchL2Data(client bind.ContractBackend) (s return "", err } - if len(bridgeInitTxData) > maxDataLength { - return "", fmt.Errorf("bridge init tx data length exceeds maximum allowed size (%d bytes)", maxDataLength) + if len(bridgeInitTxData) > maxTxDataLength { + return "", fmt.Errorf("bridge init tx data length exceeds maximum allowed size (%d bytes)", maxTxDataLength) } V := big.NewInt(27) R := common.BigToHash(big.NewInt(0x5ca1ab1e0)) S := common.BigToHash(big.NewInt(0x5ca1ab1e)) - const gasLimit = uint64(30000000) - bridgeInitTx := &preEIP155Transaction{ To: &bridgeAddr, Nonce: 0,