Last active
May 2, 2022 16:18
-
-
Save ilamanov/b6c7954ce5e4198aefcbe0ac69586da8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
/** | |
* @title CanonicalTransactionChain | |
* @dev The Canonical Transaction Chain (CTC) contract is an append-only log of transactions | |
* which must be applied to the rollup state. It defines the ordering of rollup transactions by | |
* writing them to the 'CTC:batches' instance of the Chain Storage Container. | |
* The CTC also allows any account to 'enqueue' an L2 transaction, which will require that the | |
* Sequencer will eventually append it to the rollup state. | |
* | |
*/ | |
contract CanonicalTransactionChain is ICanonicalTransactionChain, Lib_AddressResolver { | |
/** | |
* Inserts a batch into the chain of batches. | |
* @param _transactionRoot Root of the transaction tree for this batch. | |
* @param _batchSize Number of elements in the batch. | |
* @param _numQueuedTransactions Number of queue transactions in the batch. | |
* @param _timestamp The latest batch timestamp. | |
* @param _blockNumber The latest batch blockNumber. | |
*/ | |
function _appendBatch( | |
bytes32 _transactionRoot, | |
uint256 _batchSize, | |
uint256 _numQueuedTransactions, | |
uint40 _timestamp, | |
uint40 _blockNumber | |
) internal { | |
IChainStorageContainer batchesRef = batches(); | |
(uint40 totalElements, uint40 nextQueueIndex, , ) = _getBatchExtraData(); | |
Lib_OVMCodec.ChainBatchHeader memory header = Lib_OVMCodec.ChainBatchHeader({ | |
batchIndex: batchesRef.length(), | |
batchRoot: _transactionRoot, | |
batchSize: _batchSize, | |
prevTotalElements: totalElements, | |
extraData: hex"" | |
}); | |
emit TransactionBatchAppended( | |
header.batchIndex, | |
header.batchRoot, | |
header.batchSize, | |
header.prevTotalElements, | |
header.extraData | |
); | |
bytes32 batchHeaderHash = Lib_OVMCodec.hashBatchHeader(header); | |
bytes27 latestBatchContext = _makeBatchExtraData( | |
totalElements + uint40(header.batchSize), | |
nextQueueIndex + uint40(_numQueuedTransactions), | |
_timestamp, | |
_blockNumber | |
); | |
// slither-disable-next-line reentrancy-no-eth, reentrancy-events | |
batchesRef.push(batchHeaderHash, latestBatchContext); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment