-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #99 from 0xPolygonHermez/feature/98-banana_fork-part1
feat: add banana (forkid12) batches
- Loading branch information
Showing
25 changed files
with
650 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
package etherman | ||
|
||
import ( | ||
"encoding/json" | ||
|
||
"github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" | ||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/log" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/ethereum/go-ethereum/crypto" | ||
) | ||
|
||
var ( | ||
/* | ||
struct BatchData { | ||
bytes transactions; | ||
bytes32 forcedGlobalExitRoot; | ||
uint64 forcedTimestamp; | ||
bytes32 forcedBlockHashL1; | ||
} | ||
function sequenceBatches( | ||
BatchData[] calldata batches, | ||
uint32 indexL1InfoRoot, | ||
uint64 maxSequenceTimestamp, | ||
bytes32 expectedFinalAccInputHash, | ||
address l2Coinbase | ||
) | ||
b910e0f97e3128707f02262ec5c90481c982744e80bd892a4449261f745e95d0 | ||
sequenceBatches((bytes,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address) | ||
*/ | ||
methodIDSequenceBatchesBanana = crypto.Keccak256Hash([]byte("sequenceBatches((bytes,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address)")).Bytes()[:4] // b910e0f9 | ||
methodIDSequenceBatchesBananaName = "sequenceBatchesBanana" | ||
) | ||
|
||
type DecodeSequenceBatchesBanana struct { | ||
SequenceBatchesBase | ||
} | ||
|
||
func NewDecodeSequenceBatchesBanana() (*DecodeSequenceBatchesBanana, error) { | ||
base, err := NewSequenceBatchesBase(methodIDSequenceBatchesBanana, methodIDSequenceBatchesBananaName, polygonvalidiumetrog.PolygonvalidiumetrogABI) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DecodeSequenceBatchesBanana{*base}, nil | ||
} | ||
|
||
func (s *DecodeSequenceBatchesBanana) DecodeSequenceBatches(txData []byte, lastBatchNumber uint64, sequencer common.Address, txHash common.Hash, nonce uint64, l1InfoRoot common.Hash) ([]SequencedBatch, error) { | ||
decoded, err := decodeSequenceCallData(s.SmcABI(), txData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data := decoded.Data | ||
bytedata := decoded.InputByteData | ||
var sequences []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData | ||
err = json.Unmarshal(bytedata, &sequences) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
counterL1InfoRoot := data[1].(uint32) | ||
maxSequenceTimestamp := data[2].(uint64) | ||
//expectedFinalAccInputHash := data[3].(common.Hash) | ||
expectedFinalAccInputHashraw := data[3].([common.HashLength]byte) | ||
expectedFinalAccInputHash := common.Hash(expectedFinalAccInputHashraw) | ||
coinbase := data[4].(common.Address) | ||
|
||
bananaData := BananaSequenceData{ | ||
CounterL1InfoRoot: counterL1InfoRoot, | ||
MaxSequenceTimestamp: maxSequenceTimestamp, | ||
ExpectedFinalAccInputHash: expectedFinalAccInputHash, | ||
DataAvailabilityMsg: []byte{}, | ||
} | ||
SequencedBatchMetadata := &SequencedBatchMetadata{ | ||
CallFunctionName: s.NameMethodID(txData[:4]), | ||
ForkName: "banana", | ||
RollupFlavor: RollupFlavorZkEVM, | ||
} | ||
|
||
log.Debugf("Decoded %s: event(lastBatchNumber:%d, sequencer:%s, txHash:%s, nonce:%d, l1InfoRoot:%s) bananaData:%s", | ||
methodIDSequenceBatchesBananaName, | ||
lastBatchNumber, sequencer.String(), txHash.String(), nonce, l1InfoRoot.String(), | ||
bananaData.String()) | ||
log.Debugf("%s batchNum: %d Data:%s", methodIDSequenceBatchesBananaName, lastBatchNumber+1, common.Bytes2Hex(txData)) | ||
for i, d := range sequences { | ||
log.Debugf("%s BatchData[%d]: %s", methodIDSequenceBatchesBananaName, i, common.Bytes2Hex(d.Transactions)) | ||
} | ||
sequencedBatches := make([]SequencedBatch, len(sequences)) | ||
|
||
for i, seq := range sequences { | ||
|
||
bn := lastBatchNumber - uint64(len(sequences)-(i+1)) | ||
s := EtrogSequenceData{ | ||
Transactions: seq.Transactions, | ||
ForcedGlobalExitRoot: seq.ForcedGlobalExitRoot, | ||
ForcedTimestamp: seq.ForcedTimestamp, | ||
ForcedBlockHashL1: seq.ForcedBlockHashL1, | ||
} | ||
sequencedBatches[i] = SequencedBatch{ | ||
BatchNumber: bn, | ||
L1InfoRoot: &l1InfoRoot, | ||
SequencerAddr: sequencer, | ||
TxHash: txHash, | ||
Nonce: nonce, | ||
Coinbase: coinbase, | ||
EtrogSequenceData: &s, | ||
BananaData: &bananaData, | ||
Metadata: SequencedBatchMetadata, | ||
} | ||
} | ||
return sequencedBatches, nil | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package etherman | ||
|
||
import ( | ||
"encoding/hex" | ||
"testing" | ||
|
||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/log" | ||
"github.com/ethereum/go-ethereum/common" | ||
"github.com/stretchr/testify/require" | ||
) | ||
|
||
const ( | ||
txDataBananaHex = "b910e0f900000000000000000000000000000000000000000000000000000000000000a000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000066c4b6531317f62f023ccd827099d9070ac5eb453040af849485827b42eb6ac92fe112530000000000000000000000005b06837a43bdc3dd9f114558daf4b26ed49842ed00000000000000000000000000000000000000000000000000000000000000030000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000012000000000000000000000000000000000000000000000000000000000000001e0000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120b0000007a000000000b00000006000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000120b00000006000000000b000000060000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001b0b00000006000000000b00000006000000000b00000006000000000000000000" | ||
expedtedSeqBanana = `BatchNumber: 2 | ||
L1InfoRoot: 0xa958fee09bf3c4d782ab6839f81c8f40316521e19ba088b9c1a580c9a1438506 | ||
SequencerAddr: 0x5b06837A43bdC3dD9F114558DAf4B26ed49842Ed | ||
TxHash: 0x2b3fa84d57739604e5fbbc921fca588842923c64e28e0636609ee7ba1bea8c64 | ||
Nonce: 1 | ||
Coinbase: 0x5b06837A43bdC3dD9F114558DAf4B26ed49842Ed | ||
PolygonZkEVMBatchData: nil | ||
___EtrogSequenceData:ForcedTimestamp: 0 | ||
___EtrogSequenceData:ForcedGlobalExitRoot: 0000000000000000000000000000000000000000000000000000000000000000 | ||
___EtrogSequenceData:ForcedBlockHashL1: 0000000000000000000000000000000000000000000000000000000000000000 | ||
___EtrogSequenceData:Transactions: 0b0000007a000000000b0000000600000000 | ||
SequencedBatchElderberryData: nil | ||
BananaData: CounterL1InfoRoot: 1 MaxSequenceTimestamp: 1724167763 ExpectedFinalAccInputHash: 0x1317f62f023ccd827099d9070ac5eb453040af849485827b42eb6ac92fe11253 DataAvailabilityMsg(0): | ||
Metadata: SourceBatchData: RollupFlavor: kEVM CallFunctionName: sequenceBatchesBanana ForkName: banana | ||
` | ||
) | ||
|
||
func TestSequencedBatchBananaDecode(t *testing.T) { | ||
sut, err := NewDecodeSequenceBatchesBanana() | ||
require.NoError(t, err) | ||
require.NotNil(t, sut) | ||
txData, err := hex.DecodeString(txDataBananaHex) | ||
require.NoError(t, err) | ||
lastBatchNumber := uint64(4) | ||
sequencer := common.HexToAddress("0x5b06837A43bdC3dD9F114558DAf4B26ed49842Ed") | ||
txHash := common.HexToHash("0x2b3fa84d57739604e5fbbc921fca588842923c64e28e0636609ee7ba1bea8c64") | ||
nonce := uint64(1) | ||
l1InfoRoot := common.HexToHash("0xa958fee09bf3c4d782ab6839f81c8f40316521e19ba088b9c1a580c9a1438506") | ||
|
||
res, err := sut.DecodeSequenceBatches(txData, lastBatchNumber, sequencer, txHash, nonce, l1InfoRoot) | ||
require.NoError(t, err) | ||
require.NotNil(t, res) | ||
res0 := res[0].String() | ||
log.Debug(res0) | ||
require.Equal(t, expedtedSeqBanana, res0) | ||
|
||
} |
Oops, something went wrong.