For the implementation of the zk-EVM, a consensus mechanism for a decentralized L2 protocol is necessary.
This consensus mechanism defines a two-step model where:
This protocol separates batch creation into two steps. Therefore, we find two parts:
The sequencer needs to register to get a chainID (Users needs to chose a chainID to sign. That chainID could be sequencer specific or global. Meaning global that any sequencer could send that transactions and it will be valid)
Then, the two steps are done one for each part:
sendBatch
: the sequencer sends a group of L2 transactionsvalidateBatch
: the aggregator validates de batchThere are two state types:
mapping[address => Sequencer]
–> Sequencer = {sequencerURL,chainID}
registerSequencer(sequencerURL) {
mappingSeq[address] = { sequencerURL, chainID }
}
bytes
uint256
mapping[numBatch] => struct = { H(txs, currentGlobalExitRoot), chainId/ethAddr}
sequencerCollateral
in MATIC
sendBatch(bytes l2TxsData, uint256 maticAmount){
maticCollateral = calculateMaticCollateral
transfer(maticCollateral)
lastBatchSent++
currentGlobalExitRoot = bridge.currentGlobalExitRoot();
mappingSentBatches[lastBatchSent] = {H(abi.encodePacked(l2TxsData, currentGlobalExitRoot)), msg.sender, maticCollateral}
emit event SendBatch
}
invalid L2 tx are selected as NOP
In mappingSentBatches themsg.sender
is saved only if thechainID != DEFAULT_CHAINID
newLocalExitRoot
newStateRoot
batchNum
(sanity check)proofA
, proofB
, proofC
currentStateRoot
: current state rootcurrentLocalExitRoot
: current local (rollup) exit rootnewStateRoot
: new state rootnewLocalExitRoot
: new local (rollup) exit rootsequencerAddress
hash(l2TxsData # lastGlobalExitRoot)
**Buffer bytes notation**
[ calldata bits ] l2TxsData
[ 256 bits ] lastGlobalExitRoot
chainID
: CHAIN_ID_DEFAULT + sequencerID**Buffer bytes notation**
[ 256 bits ] currentStateRoot
[ 256 bits ] currentLocalExitRoot
[ 256 bits ] newStateRoot
[ 256 bits ] newLocalExitRoot
[ 160 bits ] sequencerAddress
[ 256 bits ] keccak256(l2TxsData # lastGlobalExitRoot)
[ 32 bits ] chainID (sequencerID)
[ 32 bits ] batchNum
validateBatch(newLocalExitRoot, newStateRoot, batchNum, proofA, proofB, proofC) {
require(batchNum == lastConfirmedBatch + 1)
input = calculateInput()
require(verifyProof)
lastVerifiedBatch++
currentStateRoot = newStateRoot;
currentLocalExitRoot = newLocalExitRoot;
bridge.updateRollupExitRoot(currentLocalExitRoot);
lastGlobalExitRoot = bridge.currentGlobalExitRoot();
matic.transfer()
emit event VerifyBatch
}
lastGlobalExitRoot
currentLocalExitRoot
currentStateRoot
lastVerifiedBatch
lastBatchSent
numSequencers
mapping(uint256 => BatchData) sentBatches
==> BatchData = {sequencerAddress, batchL2HashData, maticCollateral}
mapping(address => Sequencer) sequencers
==> Sequencer = {sequencerURL, chainID}
or
or
By clicking below, you agree to our terms of service.
New to HackMD? Sign up
Syntax | Example | Reference | |
---|---|---|---|
# Header | Header | 基本排版 | |
- Unordered List |
|
||
1. Ordered List |
|
||
- [ ] Todo List |
|
||
> Blockquote | Blockquote |
||
**Bold font** | Bold font | ||
*Italics font* | Italics font | ||
~~Strikethrough~~ | |||
19^th^ | 19th | ||
H~2~O | H2O | ||
++Inserted text++ | Inserted text | ||
==Marked text== | Marked text | ||
[link text](https:// "title") | Link | ||
 | Image | ||
`Code` | Code |
在筆記中貼入程式碼 | |
```javascript var i = 0; ``` |
|
||
:smile: | ![]() |
Emoji list | |
{%youtube youtube_id %} | Externals | ||
$L^aT_eX$ | LaTeX | ||
:::info This is a alert area. ::: |
This is a alert area. |
On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?
Please give us some advice and help us improve HackMD.
Do you want to remove this version name and description?
Syncing