From eac992aff352a9a3df9b2f8654ac1d68dd73dfbe Mon Sep 17 00:00:00 2001 From: kaiden Date: Wed, 8 Jan 2025 19:16:34 +1100 Subject: [PATCH] rfct/l1coordtxs --- sequencer/common/l1tx.go | 56 +-------------- sequencer/coordinator/batch.go | 2 - sequencer/coordinator/pipeline.go | 17 ++--- sequencer/database/historydb/historydb.go | 17 ----- sequencer/eth/rollup.go | 78 ++++++--------------- sequencer/synchronizer/synchronizer_test.go | 2 - sequencer/test/ethClient.go | 7 -- 7 files changed, 29 insertions(+), 150 deletions(-) diff --git a/sequencer/common/l1tx.go b/sequencer/common/l1tx.go index a7cbc19..e6442c9 100644 --- a/sequencer/common/l1tx.go +++ b/sequencer/common/l1tx.go @@ -265,64 +265,10 @@ func L1TxFromDataAvailability(b []byte, nLevels uint32) (*L1Tx, error) { return &l1tx, Wrap(err) } -// TODO: Remove this, In the PR to initialize the coordinator setup, pipeline creation and helper function addition -// L1CoordinatorTxFromBytes decodes a L1Tx from []byte -func L1CoordinatorTxFromBytes(b []byte, chainID *big.Int, tokamakAddress ethCommon.Address) (*L1Tx, - error) { - if len(b) != RollupConstL1CoordinatorTotalBytes { - return nil, Wrap( - fmt.Errorf("cannot parse L1CoordinatorTx bytes, expected length %d, current: %d", - 101, len(b))) - } - - tx := &L1Tx{ - UserOrigin: false, - } - v := b[0] - s := b[1:33] - r := b[33:65] - pkCompB := b[65:97] - pkCompL := SwapEndianness(pkCompB) - copy(tx.FromBJJ[:], pkCompL) - tx.Amount = big.NewInt(0) - tx.DepositAmount = big.NewInt(0) - if int(v) > 0 { - // L1CoordinatorTX ETH - // Ethereum adds 27 to v - v = b[0] - byte(27) //nolint:gomnd - var signature []byte - signature = append(signature, r[:]...) - signature = append(signature, s[:]...) - signature = append(signature, v) - - accCreationAuth := AccountCreationAuth{ - BJJ: tx.FromBJJ, - } - h, err := accCreationAuth.HashToSign(uint16(chainID.Uint64()), tokamakAddress) - if err != nil { - return nil, Wrap(err) - } - - pubKeyBytes, err := ethCrypto.Ecrecover(h, signature) - if err != nil { - return nil, Wrap(err) - } - pubKey, err := ethCrypto.UnmarshalPubkey(pubKeyBytes) - if err != nil { - return nil, Wrap(err) - } - tx.FromEthAddr = ethCrypto.PubkeyToAddress(*pubKey) - } else { - // L1Coordinator Babyjub - tx.FromEthAddr = RollupConstEthAddressInternalOnly - } - return tx, nil -} - // BytesGeneric returns the generic representation of a L1Tx. This method is // used to compute the []byte representation of a L1UserTx, and also to compute // the L1TxData for the ZKInputs (at the HashGlobalInputs), using this method -// for L1CoordinatorTxs & L1UserTxs (for the ZKInputs case). +// for L1UserTxs (for the ZKInputs case). func (tx *L1Tx) BytesGeneric() ([]byte, error) { var b [RollupConstL1UserTotalBytes]byte copy(b[0:20], tx.FromEthAddr.Bytes()) diff --git a/sequencer/coordinator/batch.go b/sequencer/coordinator/batch.go index ab0fd6b..d038c1a 100644 --- a/sequencer/coordinator/batch.go +++ b/sequencer/coordinator/batch.go @@ -86,8 +86,6 @@ type BatchInfo struct { // L1Batch bool VerifierIdx uint8 L1UserTxs []common.L1Tx - // L1CoordTxs []common.L1Tx - L1CoordinatorTxsAuths [][]byte ForgeBatchArgs *eth.RollupForgeBatchArgs Auth *bind.TransactOpts `json:"-"` diff --git a/sequencer/coordinator/pipeline.go b/sequencer/coordinator/pipeline.go index adc4913..92475e6 100644 --- a/sequencer/coordinator/pipeline.go +++ b/sequencer/coordinator/pipeline.go @@ -209,7 +209,6 @@ func (p *Pipeline) forgeBatch(batchNum common.BatchNum) ( batchInfo.Debug.StartBlockNum = p.stats.Eth.LastBlock.Num + 1 var l1UserTxs []common.L1Tx - var auths [][]byte _l1UserTxs, err := p.historyDB.GetUnforgedL1UserTxs(p.state.lastForgeL1TxsNum + 1) if err != nil { @@ -224,7 +223,7 @@ func (p *Pipeline) forgeBatch(batchNum common.BatchNum) ( } // TODO: figure out what happens here and potentially remove txSelector - auths, l1UserTxs, err = + _, l1UserTxs, err = p.txSelector.GetL1TxSelection(p.cfg.TxProcessorConfig, _l1UserTxs, l1UserFutureTxs) if err != nil { return nil, nil, common.Wrap(err) @@ -245,7 +244,6 @@ func (p *Pipeline) forgeBatch(batchNum common.BatchNum) ( // Save metadata from TxSelector output for BatchNum batchInfo.L1UserTxs = l1UserTxs - batchInfo.L1CoordinatorTxsAuths = auths // Call BatchBuilder with TxSelector output configBatch := &batchbuilder.ConfigBatch{ @@ -446,13 +444,12 @@ func prepareForgeBatchArgs(batchInfo *BatchInfo) *eth.RollupForgeBatchArgs { proof := batchInfo.Proof zki := batchInfo.ZKInputs return ð.RollupForgeBatchArgs{ - NewLastIdx: int64(zki.NewLastIdxRaw), - NewAccountRoot: zki.NewAccountRootRaw.BigInt(), - NewVouchRoot: zki.NewVouchRootRaw.BigInt(), - NewScoreRoot: zki.NewScoreRootRaw.BigInt(), - NewExitRoot: zki.NewExitRootRaw.BigInt(), - L1UserTxs: batchInfo.L1UserTxs, - L1CoordinatorTxsAuths: batchInfo.L1CoordinatorTxsAuths, + NewLastIdx: int64(zki.NewLastIdxRaw), + NewAccountRoot: zki.NewAccountRootRaw.BigInt(), + NewVouchRoot: zki.NewVouchRootRaw.BigInt(), + NewScoreRoot: zki.NewScoreRootRaw.BigInt(), + NewExitRoot: zki.NewExitRootRaw.BigInt(), + L1UserTxs: batchInfo.L1UserTxs, // Circuit selector VerifierIdx: batchInfo.VerifierIdx, ProofA: [2]*big.Int{proof.PiA[0], proof.PiA[1]}, diff --git a/sequencer/database/historydb/historydb.go b/sequencer/database/historydb/historydb.go index 10f8fff..bce7a96 100644 --- a/sequencer/database/historydb/historydb.go +++ b/sequencer/database/historydb/historydb.go @@ -554,23 +554,6 @@ func (hdb *HistoryDB) GetAllL1UserTxs() ([]common.L1Tx, error) { return database.SlicePtrsToSlice(txs).([]common.L1Tx), common.Wrap(err) } -// GetAllL1CoordinatorTxs returns all L1CoordinatorTxs from the DB -func (hdb *HistoryDB) GetAllL1CoordinatorTxs() ([]common.L1Tx, error) { - var txs []*common.L1Tx - // Since the query specifies that only coordinator txs are returned, it's safe to assume - // that returned txs will always have effective amounts - err := meddler.QueryAll( - hdb.dbRead, &txs, - `SELECT tx.id, tx.to_forge_l1_txs_num, tx.position, tx.user_origin, - tx.from_idx, tx.effective_from_idx, tx.from_eth_addr, tx.from_bjj, tx.to_idx, - tx.amount, tx.amount AS effective_amount, - tx.deposit_amount, tx.deposit_amount AS effective_deposit_amount, - tx.eth_block_num, tx.type, tx.batch_num - FROM tx WHERE is_l1 = TRUE AND user_origin = FALSE ORDER BY item_id;`, - ) - return database.SlicePtrsToSlice(txs).([]common.L1Tx), common.Wrap(err) -} - // GetUnforgedL1UserTxs gets L1 User Txs to be forged in the L1Batch with toForgeL1TxsNum. func (hdb *HistoryDB) GetUnforgedL1UserTxs(toForgeL1TxsNum int64) ([]common.L1Tx, error) { var txs []*common.L1Tx diff --git a/sequencer/eth/rollup.go b/sequencer/eth/rollup.go index c71245a..b65be77 100644 --- a/sequencer/eth/rollup.go +++ b/sequencer/eth/rollup.go @@ -171,20 +171,17 @@ func NewRollupEvents() RollupEvents { // RollupForgeBatchArgs are the arguments to the ForgeBatch function in the Rollup Smart Contract type RollupForgeBatchArgs struct { - NewLastIdx int64 - NewAccountRoot *big.Int - NewScoreRoot *big.Int - NewVouchRoot *big.Int - NewExitRoot *big.Int - L1UserTxs []common.L1Tx - L1CoordinatorTxs []common.L1Tx - L1CoordinatorTxsAuths [][]byte // Authorization for accountCreations for each L1CoordinatorTx - // Circuit selector - VerifierIdx uint8 - L1Batch bool - ProofA [2]*big.Int - ProofB [2][2]*big.Int - ProofC [2]*big.Int + NewLastIdx int64 + NewAccountRoot *big.Int + NewScoreRoot *big.Int + NewVouchRoot *big.Int + NewExitRoot *big.Int + L1UserTxs []common.L1Tx + VerifierIdx uint8 + L1Batch bool + ProofA [2]*big.Int + ProofB [2][2]*big.Int + ProofC [2]*big.Int } // RollupForgeBatchArgsAux are the arguments to the ForgeBatch function in the Rollup Smart Contract @@ -569,23 +566,20 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, return nil, nil, common.Wrap(err) } rollupForgeBatchArgs := RollupForgeBatchArgs{ - L1Batch: aux.L1Batch, - NewExitRoot: aux.NewExitRoot, - NewLastIdx: aux.NewLastIdx.Int64(), - NewAccountRoot: aux.NewAccountRoot, - NewVouchRoot: aux.NewVouchRoot, - NewScoreRoot: aux.NewScoreRoot, - ProofA: aux.ProofA, - ProofB: aux.ProofB, - ProofC: aux.ProofC, - VerifierIdx: aux.VerifierIdx, - L1CoordinatorTxs: []common.L1Tx{}, - L1CoordinatorTxsAuths: [][]byte{}, + L1Batch: aux.L1Batch, + NewExitRoot: aux.NewExitRoot, + NewLastIdx: aux.NewLastIdx.Int64(), + NewAccountRoot: aux.NewAccountRoot, + NewVouchRoot: aux.NewVouchRoot, + NewScoreRoot: aux.NewScoreRoot, + ProofA: aux.ProofA, + ProofB: aux.ProofB, + ProofC: aux.ProofC, + VerifierIdx: aux.VerifierIdx, } nLevels := c.consts.Verifiers[rollupForgeBatchArgs.VerifierIdx].NLevels lenL1TxsBytes := int((nLevels/8)*2 + common.Float40BytesLength + 1) //nolint:gomnd numBytesL1TxUser := int(l1UserTxsLen) * lenL1TxsBytes - numTxsL1Coord := len(aux.EncodedL1CoordinatorTx) / common.RollupConstL1CoordinatorTotalBytes l1UserTxsData := []byte{} if l1UserTxsLen > 0 { l1UserTxsData = aux.L1L2TxsData[:numBytesL1TxUser] @@ -599,35 +593,5 @@ func (c *RollupClient) RollupForgeBatchArgs(ethTxHash ethCommon.Hash, } rollupForgeBatchArgs.L1UserTxs = append(rollupForgeBatchArgs.L1UserTxs, *l1Tx) } - for i := 0; i < numTxsL1Coord; i++ { - bytesL1Coordinator := - aux.EncodedL1CoordinatorTx[i*common.RollupConstL1CoordinatorTotalBytes : (i+1)*common.RollupConstL1CoordinatorTotalBytes] //nolint:lll - var signature []byte - v := bytesL1Coordinator[0] - s := bytesL1Coordinator[1:33] - r := bytesL1Coordinator[33:65] - signature = append(signature, r[:]...) - signature = append(signature, s[:]...) - signature = append(signature, v) - l1Tx, err := common.L1CoordinatorTxFromBytes(bytesL1Coordinator, c.chainID, c.address) - if err != nil { - return nil, nil, common.Wrap(err) - } - rollupForgeBatchArgs.L1CoordinatorTxs = append(rollupForgeBatchArgs.L1CoordinatorTxs, *l1Tx) - rollupForgeBatchArgs.L1CoordinatorTxsAuths = - append(rollupForgeBatchArgs.L1CoordinatorTxsAuths, signature) - } - lenFeeIdxCoordinatorBytes := int(nLevels / 8) //nolint:gomnd - numFeeIdxCoordinator := len(aux.FeeIdxCoordinator) / lenFeeIdxCoordinatorBytes - for i := 0; i < numFeeIdxCoordinator; i++ { - var paddedFeeIdx [6]byte - if lenFeeIdxCoordinatorBytes < common.AccountIdxBytesLen { - copy(paddedFeeIdx[6-lenFeeIdxCoordinatorBytes:], - aux.FeeIdxCoordinator[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes]) - } else { - copy(paddedFeeIdx[:], - aux.FeeIdxCoordinator[i*lenFeeIdxCoordinatorBytes:(i+1)*lenFeeIdxCoordinatorBytes]) - } - } return &rollupForgeBatchArgs, &sender, nil } diff --git a/sequencer/synchronizer/synchronizer_test.go b/sequencer/synchronizer/synchronizer_test.go index accb037..4408237 100644 --- a/sequencer/synchronizer/synchronizer_test.go +++ b/sequencer/synchronizer/synchronizer_test.go @@ -96,7 +96,6 @@ func checkSyncBlock(t *testing.T, s *Synchronizer, blockNum int, block, require.NoError(t, err) dbExits, err := s.historyDB.GetAllExits() require.NoError(t, err) - // dbL1CoordinatorTxs := []common.L1Tx{} for i, batch := range block.Rollup.Batches { var dbBatch *common.Batch // Find batch in DB output @@ -352,7 +351,6 @@ func TestSyncGeneral(t *testing.T) { require.Equal(t, 2, int(blocks[i].Block.Num)) require.Equal(t, 4, len(blocks[i].Rollup.L1UserTxs)) require.Equal(t, 2, len(blocks[i].Rollup.Batches)) - // require.Equal(t, 2, len(blocks[i].Rollup.Batches[0].L1CoordinatorTxs)) // Set StateRoots for batches manually (til doesn't set it) blocks[i].Rollup.Batches[0].Batch.AccountRoot = diff --git a/sequencer/test/ethClient.go b/sequencer/test/ethClient.go index 45c7517..a0b806a 100644 --- a/sequencer/test/ethClient.go +++ b/sequencer/test/ethClient.go @@ -848,10 +848,6 @@ func (c *Client) CtlAddBlocks(blocks []common.BlockData) (err error) { } c.CtlSetAddr(ethCommon.HexToAddress("0xE39fEc6224708f0772D2A74fd3f9055A90E0A9f2")) for _, batch := range block.Rollup.Batches { - // auths := make([][]byte, len(batch.L1CoordinatorTxs)) - // for i := range auths { - // auths[i] = make([]byte, 65) - // } if _, err := c.RollupForgeBatch(ð.RollupForgeBatchArgs{ NewLastIdx: batch.Batch.LastIdx, @@ -859,9 +855,6 @@ func (c *Client) CtlAddBlocks(blocks []common.BlockData) (err error) { NewVouchRoot: batch.Batch.VouchRoot, NewScoreRoot: batch.Batch.ScoreRoot, NewExitRoot: batch.Batch.ExitRoot, - // L1CoordinatorTxs: batch.L1CoordinatorTxs, - // L1CoordinatorTxsAuths: auths, - // L2TxsData: batch.L2Txs, // Circuit selector VerifierIdx: 0, // Intentionally empty L1Batch: batch.L1Batch,