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 sent and validated. Therefore, we find two parts:
The sequencer needs to register to get a chainID (Users needs to chose a chainID to sign. There's a default chainID valid for all sequencers. A sequencer can only send transactions with his chainID the default one
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
–> The transactions should be encoded in the following format:[\(tx_0\) # \(tx_1\) # \(tx_2\) # … # \(tx_n\) ] where a tx should be encoded as following:tx = rlp(nonce, gasprice, gasLimit, to, value, data, chainid, 0, 0,) || v || r || s
uint256
function calculateSequencerCollateral() public view returns (uint256) {
return 1 ether * (1 + lastBatchSent - lastVerifiedBatch);
}
bytes32 lastGlobalExitRoot = bridge.getLastGlobalExitRoot();
Set chainID: default if the sequencer is not registered.
State updates –> mapping[numBatch]
{ H(txs, lastGlobalExitRoot, block.timestamp, msg.sender (sequencer address), batchChainID, numBatch)}
Emit sendBatch
event:
emit SendBatch(lastBatchSent, msg.sender, batchChainID, lastGlobalExitRoot);
sendBatch(bytes l2TxsData, uint256 maticAmount){
maticCollateral = calculateMaticCollateral
transfer(maticCollateral)
lastBatchSent++
currentGlobalExitRoot = bridge.currentGlobalExitRoot();
mappingSentBatches[lastBatchSent] = batchHashData, maticCollateral})
emit event SendBatch
}
invalid L2 tx are selected as NOP
newLocalExitRoot
newStateRoot
numBatch
(sanity check)proofA
, proofB
, proofC
currentStateRoot
: current state rootcurrentLocalExitRoot
: current local (rollup) exit rootnewStateRoot
: new state rootnewLocalExitRoot
: new local (rollup) exit rootbatchHashData
**Buffer bytes notation**
[ 256 bits ] currentStateRoot
[ 256 bits ] currentLocalExitRoot
[ 256 bits ] newStateRoot
[ 256 bits ] newLocalExitRoot
[ 256 bits ] batchHashData
emit VerifyBatch(numBatch, msg.sender);
verifyBatch(newLocalExitRoot, newStateRoot, batchNum, proofA, proofB, proofC) {
require(batchNum == lastConfirmedBatch + 1)
input = calculateInput()
require(verifyProof)
lastVerifiedBatch++
currentStateRoot = newStateRoot;
currentLocalExitRoot = newLocalExitRoot;
bridge.updateRollupExitRoot(currentLocalExitRoot);
matic.transfer()
emit event VerifyBatch
}
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