-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
package etherman | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
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 = []byte{0xdb, 0x5b, 0x0e, 0xd7} // 165e8a8d sequenceBatches((bytes,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address) | ||
methodIDSequenceBatchesBananaName = "sequenceBatchesBanana" | ||
) | ||
|
||
type DecodeSequenceBatchesDecodeBanana struct { | ||
SequenceBatchesBase | ||
} | ||
|
||
func NewDecodeSequenceBatchesDecodeBanana() (*DecodeSequenceBatchesDecodeBanana, error) { | ||
base, err := NewSequenceBatchesBase(methodIDSequenceBatchesBanana, methodIDSequenceBatchesBananaName, polygonvalidiumetrog.PolygonvalidiumetrogABI) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &DecodeSequenceBatchesDecodeBanana{*base}, nil | ||
} | ||
|
||
func (s *DecodeSequenceBatchesDecodeBanana) DecodeSequenceBatches(txData []byte, lastBatchNumber uint64, sequencer common.Address, txHash common.Hash, nonce uint64, l1InfoRoot common.Hash) ([]SequencedBatch, error) { | ||
//decoded, err := decodeSequenceCallData(s.SmcABI(), txData) | ||
_, err := decodeSequenceCallData(s.SmcABI(), txData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return nil, fmt.Errorf("not implemented") | ||
/* | ||
data := decoded.Data | ||
bytedata := decoded.InputByteData | ||
var sequences []polygonvalidiumetrog.PolygonRollupBaseEtrogBatchData | ||
err = json.Unmarshal(bytedata, &sequences) | ||
if err != nil { | ||
return nil, err | ||
} | ||
maxSequenceTimestamp := data[1].(uint64) | ||
initSequencedBatchNumber := data[2].(uint64) | ||
coinbase := (data[3]).(common.Address) | ||
sequencedBatches := make([]SequencedBatch, len(sequences)) | ||
SequencedBatchMetadata := &SequencedBatchMetadata{ | ||
CallFunctionName: s.NameMethodID(txData[:4]), | ||
RollupFlavor: RollupFlavorZkEVM, | ||
ForkName: "elderberry", | ||
} | ||
for i, seq := range sequences { | ||
elderberry := SequencedBatchElderberryData{ | ||
MaxSequenceTimestamp: maxSequenceTimestamp, | ||
InitSequencedBatchNumber: initSequencedBatchNumber, | ||
} | ||
bn := lastBatchNumber - uint64(len(sequences)-(i+1)) | ||
s := seq | ||
sequencedBatches[i] = SequencedBatch{ | ||
BatchNumber: bn, | ||
L1InfoRoot: &l1InfoRoot, | ||
SequencerAddr: sequencer, | ||
TxHash: txHash, | ||
Nonce: nonce, | ||
Coinbase: coinbase, | ||
PolygonRollupBaseEtrogBatchData: &s, | ||
SequencedBatchElderberryData: &elderberry, | ||
Metadata: SequencedBatchMetadata, | ||
} | ||
} | ||
return sequencedBatches, nil | ||
*/ | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,164 @@ | ||
package etherman | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/0xPolygon/cdk-contracts-tooling/contracts/banana/polygonvalidiumetrog" | ||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/dataavailability" | ||
elderberrypolygonzkevm "github.com/0xPolygonHermez/zkevm-synchronizer-l1/etherman/smartcontracts/polygonzkevm" | ||
"github.com/0xPolygonHermez/zkevm-synchronizer-l1/log" | ||
"github.com/ethereum/go-ethereum/common" | ||
) | ||
|
||
var ( | ||
/* | ||
// contract: v8.0.0-rc.1-fork.12 | ||
https://github.com/0xPolygonHermez/zkevm-contracts/blob/a5eacc6e51d7456c12efcabdfc1c37457f2219b2/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol#L29 | ||
struct ValidiumBatchData { | ||
bytes32 transactionsHash; | ||
bytes32 forcedGlobalExitRoot; | ||
uint64 forcedTimestamp; | ||
bytes32 forcedBlockHashL1; | ||
} | ||
//https://github.com/0xPolygonHermez/zkevm-contracts/blob/a9b4f742f66bd4f3bcd98a3a188422480ffe0d4e/contracts/v2/consensus/validium/PolygonValidiumEtrog.sol#L91 | ||
function sequenceBatchesValidium( | ||
ValidiumBatchData[] calldata batches, | ||
uint32 indexL1InfoRoot, | ||
uint64 maxSequenceTimestamp, | ||
bytes32 expectedFinalAccInputHash, | ||
address l2Coinbase, | ||
bytes calldata dataAvailabilityMessage | ||
) | ||
165e8a8d50cd47dabdf9bde8bf707c673d2379d465bd458693e23b75ab3a4424 | ||
sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address,bytes) | ||
*/ | ||
methodIDSequenceBatchesBananaValidium = []byte{0x16, 0x5e, 0x8a, 0x8d} // 165e8a8d sequenceBatchesValidium((bytes32,bytes32,uint64,bytes32)[],uint32,uint64,bytes32,address,bytes) | ||
methodIDSequenceBatchesBananaValidiumName = "sequenceBatchesBananaValidium" | ||
) | ||
|
||
type SequenceBatchesDecoderBananaValidium struct { | ||
SequenceBatchesBase | ||
da dataavailability.BatchDataProvider | ||
} | ||
|
||
func NewSequenceBatchesDecoderBananaValidium(da dataavailability.BatchDataProvider) (*SequenceBatchesDecoderBananaValidium, error) { | ||
base, err := NewSequenceBatchesBase(methodIDSequenceBatchesBananaValidium, | ||
methodIDSequenceBatchesBananaValidiumName, polygonvalidiumetrog.PolygonvalidiumetrogABI) | ||
if err != nil { | ||
return nil, err | ||
} | ||
return &SequenceBatchesDecoderBananaValidium{*base, da}, nil | ||
} | ||
|
||
func (s *SequenceBatchesDecoderBananaValidium) DecodeSequenceBatches(txData []byte, lastBatchNumber uint64, sequencer common.Address, txHash common.Hash, nonce uint64, l1InfoRoot common.Hash) ([]SequencedBatch, error) { | ||
log.Debugf("%s batchNum: %d Data:%s", methodIDSequenceBatchesBananaValidiumName, lastBatchNumber+1, common.Bytes2Hex(txData)) | ||
if s.da == nil { | ||
return nil, fmt.Errorf("data availability backend not set") | ||
} | ||
decoded, err := decodeSequenceCallData(s.SmcABI(), txData) | ||
if err != nil { | ||
return nil, err | ||
} | ||
data := decoded.Data | ||
bytedata := decoded.InputByteData | ||
var sequencesValidium []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData | ||
err = json.Unmarshal(bytedata, &sequencesValidium) | ||
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) | ||
dataAvailabilityMsg := data[5].([]byte) | ||
bananaData := BananaSequenceData{ | ||
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / unittest
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / check_version
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / test_db
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / test_db
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / unittest
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / lint
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / lint
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / lint
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / lint
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / lint
Check failure on line 79 in etherman/sequence_batches_decode_banana_validium.go GitHub Actions / lint
|
||
CounterL1InfoRoot: counterL1InfoRoot, | ||
MaxSequenceTimestamp: maxSequenceTimestamp, | ||
ExpectedFinalAccInputHash: expectedFinalAccInputHash, | ||
DataAvailabilityMsg: dataAvailabilityMsg, | ||
} | ||
batchInfos := createBatchInfoBanana(sequencesValidium, lastBatchNumber) | ||
|
||
batchData, err := retrieveBatchData(s.da, batchInfos, dataAvailabilityMsg) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
log.Debugf("Decoded Banana sequenceBatchesValidium: counterL1InfoRoot:%d maxSequenceTimestamp:%d expectedFinalAccInputHash:%s coinbase:%s dataAvailabilityMsg:%s", | ||
counterL1InfoRoot, maxSequenceTimestamp, expectedFinalAccInputHash, coinbase.Hex(), dataAvailabilityMsg) | ||
|
||
SequencedBatchMetadata := &SequencedBatchMetadata{ | ||
CallFunctionName: s.NameMethodID(txData[:4]), | ||
ForkName: "banana", | ||
RollupFlavor: RollupFlavorValidium, | ||
} | ||
sequencedBatches := createSequencedBatchListBanana(sequencesValidium, batchInfos, batchData, l1InfoRoot, sequencer, txHash, nonce, coinbase, maxSequenceTimestamp, SequencedBatchMetadata) | ||
|
||
return sequencedBatches, nil | ||
|
||
} | ||
|
||
func createBatchInfoBanana(sequencesValidium []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, lastBatchNumber uint64) []batchInfo { | ||
// Pair the batch number, hash, and if it is forced. This will allow | ||
// retrieval from different sources, and keep them in original order. | ||
|
||
var batchInfos []batchInfo | ||
for i, d := range sequencesValidium { | ||
bn := lastBatchNumber - uint64(len(sequencesValidium)-(i+1)) | ||
forced := d.ForcedTimestamp > 0 | ||
h := d.TransactionsHash | ||
batchInfos = append(batchInfos, batchInfo{num: bn, hash: h, isForced: forced}) | ||
} | ||
return batchInfos | ||
} | ||
|
||
func createSequencedBatchListBanana(sequencesValidium []polygonvalidiumetrog.PolygonValidiumEtrogValidiumBatchData, batchInfos []batchInfo, batchData []dataavailability.BatchL2Data, | ||
l1InfoRoot common.Hash, sequencer common.Address, txHash common.Hash, nonce uint64, coinbase common.Address, | ||
maxSequenceTimestamp uint64, | ||
metaData *SequencedBatchMetadata) []SequencedBatch { | ||
sequencedBatches := make([]SequencedBatch, len(sequencesValidium)) | ||
for i, info := range batchInfos { | ||
bn := info.num | ||
s := elderberrypolygonzkevm.PolygonRollupBaseEtrogBatchData{ | ||
Transactions: batchData[i].Data, | ||
ForcedGlobalExitRoot: sequencesValidium[i].ForcedGlobalExitRoot, | ||
ForcedTimestamp: sequencesValidium[i].ForcedTimestamp, | ||
ForcedBlockHashL1: sequencesValidium[i].ForcedBlockHashL1, | ||
} | ||
if metaData != nil { | ||
switch batchData[i].Source { | ||
case dataavailability.External: | ||
metaData.SourceBatchData = SourceBatchDataValidiumDAExternal | ||
case dataavailability.Trusted: | ||
metaData.SourceBatchData = SourceBatchDataValidiumDATrusted | ||
|
||
metaData.SourceBatchData = string(batchData[i].Source) | ||
} | ||
} | ||
batch := SequencedBatch{ | ||
BatchNumber: bn, | ||
L1InfoRoot: &l1InfoRoot, | ||
SequencerAddr: sequencer, | ||
TxHash: txHash, | ||
Nonce: nonce, | ||
Coinbase: coinbase, | ||
PolygonRollupBaseEtrogBatchData: &s, | ||
Metadata: metaData, | ||
} | ||
|
||
/* | ||
elderberry := &SequencedBatchElderberryData{ | ||
MaxSequenceTimestamp: maxSequenceTimestamp, | ||
InitSequencedBatchNumber: initSequencedBatchNumber, | ||
} | ||
batch.SequencedBatchElderberryData = elderberry | ||
*/ | ||
sequencedBatches[i] = batch | ||
} | ||
return sequencedBatches | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package etherman | ||
|
||
const ( | ||
txDataBananaValidiumHex = "165e8a8d00000000000000000000000000000000000000000000000000000000000000c000000000000000000000000000000000000000000000000000000000000000010000000000000000000000000000000000000000000000000000000066c43b8e443448cabd1b7808f64eb3f2737180b7ef27a0a28e19afebb2981714a6492c9b0000000000000000000000005b06837a43bdc3dd9f114558daf4b26ed49842ed00000000000000000000000000000000000000000000000000000000000002600000000000000000000000000000000000000000000000000000000000000003d09d1238668f9e4dd74d503f15a90c8fc230069b5ace4a3327896b50bf809db5000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000df729b193d68d2b455c59f7040687d4dc2d147557442aeef4c10cc5769d47ade00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000014df0077a11ccf22bd14d1ec3e209ba5d8e065ce73556fdc8fb9c19b83af4ec30000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000055f10249e353edebbaa84755e6216d6bf44a1be5e5b140ed6cd94f56dcd7611ad2202708675673a014fcea40c1519ae920ed7652e23e43bf837e11fc5c403539fd1b5951f5b2604c9b42e478d5e2b2437f44073ef9a60000000000000000000000" | ||
) |