Skip to content

Commit

Permalink
Merge pull request #120 from 0xPolygonHermez/feature/skip-first-chang…
Browse files Browse the repository at this point in the history
…e-l2-block

add flags to skipChangeL2Block & skipWriteBlockInfoRoot
  • Loading branch information
ignasirv authored Nov 29, 2023
2 parents 13a353c + 5c19cd8 commit 3c5dee6
Show file tree
Hide file tree
Showing 2 changed files with 140 additions and 6 deletions.
34 changes: 28 additions & 6 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ module.exports = class Processor {
* @param {Bool} options.skipUpdateSystemStorage Skips updates on system smrt contract at the end of processable transactions
* @param {Bool} options.skipVerifyL1InfoRoot Skips verification smt proof against the L1InfoRoot
* @param {Number} options.newBlockGasLimit New batch gas limit
* @param {Bool} options.skipFirstChangeL2Block Skips verification that first transaction must be a ChangeL2BlockTx
* @param {Bool} options.skipWriteBlockInfoRoot Skips writing blockL2Info root on L2
* @param {Object} extraData - additional data embedded in the batch
* @param {Array[Object]} extraData.l1Info - L1Info - object with the following [key - value] ==> [indexL1InfoTree - L1InfoLeaf]
* @param {String} extraData.l1Info[x].globalExitRoot - global exit root
Expand Down Expand Up @@ -350,12 +352,15 @@ module.exports = class Processor {
for (let i = 0; i < this.decodedTxs.length; i++) {
const currentDecodedTx = this.decodedTxs[i];

// First transaction must be a ChangeL2BlockTx if the batch is not a forced one. Otherwise, invalid batch
// This will be ensured by the blob
if (i === 0 && currentDecodedTx.tx.type !== Constants.TX_CHANGE_L2_BLOCK && !this.isForced) {
this.isInvalid = true;
// skip verification first tx is a changeL2Block
if (this.options.skipFirstChangeL2Block !== true) {
// First transaction must be a ChangeL2BlockTx if the batch is not a forced one. Otherwise, invalid batch
// This will be ensured by the blob
if (i === 0 && currentDecodedTx.tx.type !== Constants.TX_CHANGE_L2_BLOCK && !this.isForced) {
this.isInvalid = true;

return;
return;
}
}

// If it is a forced batch, we create a changeL2Block at the beginning
Expand Down Expand Up @@ -620,8 +625,14 @@ module.exports = class Processor {

// Write values at storage at the end of block processing
async consolidateBlock() {
// Set block gasUsed at block header on finshed processing al txs
// Set block gasUsed at block header on finished processing all txs
this.blockInfoRoot = await setBlockGasUsed(this.smt, this.blockInfoRoot, this.cumulativeGasUsed);

// set blockInfoRoot to write to 0 in order to avoid a SR change
if (this.options.skipWriteBlockInfoRoot === true) {
this.blockInfoRoot = [this.F.zero, this.F.zero, this.F.zero, this.F.zero];
}

// Set blockInfoRoot on storage
// Current state root will be the block hash, stored in SC at the begginning of next block
this.currentStateRoot = await stateUtils.setContractStorage(
Expand Down Expand Up @@ -925,6 +936,17 @@ module.exports = class Processor {
l1InfoTree: this.l1InfoTree,
db: await getCurrentDB(this.oldStateRoot, this.db, this.F),
};

// add flags
// skipFirstChangeL2Block
if (this.options.skipFirstChangeL2Block === true) {
this.starkInput.skipFirstChangeL2Block = true;
}

// skipWriteBlockInfoRoot
if (this.options.skipWriteBlockInfoRoot === true) {
this.starkInput.skipWriteBlockInfoRoot = true;
}
}

/**
Expand Down
112 changes: 112 additions & 0 deletions test/helpers/test-vectors/processor/state-transition.json
Original file line number Diff line number Diff line change
Expand Up @@ -1567,5 +1567,117 @@
"oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestampLimit": 1944498031,
"expectedNewAccInputHash": "0x8dc5830f519013db61a65260335637ff848d9713706a01a19be6008615c0b0da"
},
{
"id": 14,
"description": "2 accounts and 3 valid transactions",
"chainID": 1000,
"forkID": 7,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"timestampLimit": 1944498031,
"genesis": [
{
"address": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"pvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"balance": "100000000000000000000",
"nonce": "0"
},
{
"address": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff",
"pvtKey": "0x4d27a600dce8c29b7bd080e29a26972377dbb04d7a27d919adbb602bf13cfd23",
"balance": "200000000000000000000",
"nonce": "0"
}
],
"expectedOldRoot": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d",
"txs": [
{
"type": 11,
"deltaTimestamp": "1944498031",
"l1Info": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
"customRawTx": "0x0b73e6af6f00000000"
},
{
"id": 0,
"from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff",
"nonce": 0,
"value": "100000000000000000",
"gasLimit": 100000,
"gasPrice": "1000000000",
"chainId": 1000,
"rawTx": "0xf86e80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808207f3a01cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e7a05d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad73",
"reason": "",
"customRawTx": "0xee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731bff"
},
{
"id": 1,
"from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff",
"nonce": 1,
"value": "200000000000000000",
"gasLimit": 100000,
"gasPrice": "1000000000",
"chainId": 1000,
"rawTx": "0xf86e01843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8802c68af0bb140000808207f4a0225fd92907efb068a8bee3f95a26f2c5d67db2750bb9993083e0df217ff3a266a06f412c311280066d1717f309c248fdbd853ce738363db08775999b2f2d2a8d5e",
"reason": "",
"customRawTx": "0xee01843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8802c68af0bb140000808203e88080225fd92907efb068a8bee3f95a26f2c5d67db2750bb9993083e0df217ff3a2666f412c311280066d1717f309c248fdbd853ce738363db08775999b2f2d2a8d5e1cff"
},
{
"id": 2,
"from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff",
"nonce": 2,
"value": "300000000000000000",
"gasLimit": 100000,
"gasPrice": "1000000000",
"chainId": 1000,
"rawTx": "0xf86e02843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff880429d069189e0000808207f4a0dc5f4215d7bf1d48547ffbe35e57dadcb338fc8cc7e3e8bb6a686becf1eea3eba056a0ac4b56810a3394ddff7345987ba3b324cd2c1def30a952e6c54ac300966b",
"reason": "",
"customRawTx": "0xee02843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff880429d069189e0000808203e88080dc5f4215d7bf1d48547ffbe35e57dadcb338fc8cc7e3e8bb6a686becf1eea3eb56a0ac4b56810a3394ddff7345987ba3b324cd2c1def30a952e6c54ac300966b1cff"
}
],
"expectedNewRoot": "0xfe847ba4b65fb3fda324d8a7c29fa62489c974f5ef94a17594a099ed78ff0dbf",
"expectedNewLeafs": {
"0x617b3a3528f9cdd6630fd3301b9c8911f7bf063d": {
"balance": "99400000000000000000",
"nonce": "3",
"storage": null,
"hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000",
"bytecodeLength": 0
},
"0x4d5cf5032b2a844602278b01199ed191a86c93ff": {
"balance": "200600000000000000000",
"nonce": "0",
"storage": null,
"hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000",
"bytecodeLength": 0
},
"0x000000000000000000000000000000005ca1ab1e": {
"balance": "0",
"nonce": "0",
"storage": {
"0x0000000000000000000000000000000000000000000000000000000000000000": "0x01",
"0x0000000000000000000000000000000000000000000000000000000000000002": "0x73e6af6f",
"0xa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb49": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d",
"0x0000000000000000000000000000000000000000000000000000000000000003": "0x40690fd4d68368502784a5be87ec0f5e48cf8ee9acd8c0f0ac13e12a5c949a30"
},
"hashBytecode": "0x0000000000000000000000000000000000000000000000000000000000000000",
"bytecodeLength": 0
}
},
"batchL2Data": "0x0b73e6af6f00000000ee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731bffee01843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff8802c68af0bb140000808203e88080225fd92907efb068a8bee3f95a26f2c5d67db2750bb9993083e0df217ff3a2666f412c311280066d1717f309c248fdbd853ce738363db08775999b2f2d2a8d5e1cffee02843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff880429d069189e0000808203e88080dc5f4215d7bf1d48547ffbe35e57dadcb338fc8cc7e3e8bb6a686becf1eea3eb56a0ac4b56810a3394ddff7345987ba3b324cd2c1def30a952e6c54ac300966b1cff",
"l1InfoRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9",
"newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"batchHashData": "0xf07c8d0d9e693c11096e51fbb2317685cd4646374fc61b82f9e3407ad295d201",
"oldLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"expectedNewAccInputHash": "0xe370dc3c8565d2a86a77705ef263cf48715964f133cc738d8795dfc6362be687"
}
]

0 comments on commit 3c5dee6

Please sign in to comment.