Skip to content

Commit

Permalink
fix: pessimistic proofs - handle zero gas token batchl2data (#27)
Browse files Browse the repository at this point in the history
* fix: handle 0x0 gas token encoding

* feat: add new rollup definitions for Bali
  • Loading branch information
Stefan-Ethernal authored Dec 17, 2024
1 parent faeedea commit b7fe238
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 11 deletions.
2 changes: 1 addition & 1 deletion cmd/importrollupmanager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
13 changes: 13 additions & 0 deletions networks/sepolia/bali/rollups/20-cdk20.json
Original file line number Diff line number Diff line change
@@ -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
}
13 changes: 13 additions & 0 deletions networks/sepolia/bali/rollups/21-cdk21.json
Original file line number Diff line number Diff line change
@@ -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
}
20 changes: 12 additions & 8 deletions rollup/rollup_pessimistic_proofs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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()
Expand All @@ -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,
Expand Down

0 comments on commit b7fe238

Please sign in to comment.