Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/options tool tree #147

Merged
merged 5 commits into from
Mar 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,3 +86,4 @@ module.exports.GLOBAL_INDEX_MAINNET_FLAG = Scalar.pow(2, 64);

// Common
module.exports.ZERO_BYTES32 = '0x0000000000000000000000000000000000000000000000000000000000000000';
module.exports.L1_INFO_DATA_ZERO = '0x3cac317908c699fe873a7f6ee4e8cd63fbe9918b2315c97be91585590168e301';
13 changes: 11 additions & 2 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -862,21 +862,30 @@ module.exports = class Processor {
const l1Info = this.extraData.l1Info[tx.indexL1InfoTree];

// Verify l1Info & indexL1InfoTree belong to l1InfoRoot
const valueLeaf = getL1InfoTreeValue(
let valueLeaf = getL1InfoTreeValue(
l1Info.globalExitRoot,
l1Info.blockHash,
l1Info.timestamp,
);

if (Scalar.eq(valueLeaf, Constants.L1_INFO_DATA_ZERO)) {
valueLeaf = Constants.ZERO_BYTES32;
}

if (!this.options.skipVerifyL1InfoRoot) {
if (typeof this.extraData.l1Info[tx.indexL1InfoTree] === 'undefined') {
throw new Error(`${getFuncName()}: BatchProcessor:_processChangeL2BlockTx:: missing smtProof`);
throw new Error('BatchProcessor:_processChangeL2BlockTx:: missing smtProof');
}

// fulfill l1InfoTree information
this.l1InfoTree[tx.indexL1InfoTree] = l1Info;

if (!verifyMerkleProof(valueLeaf, l1Info.smtProof, tx.indexL1InfoTree, smtUtils.h4toString(this.l1InfoRoot))) {
throw new Error('BatchProcessor:_processChangeL2BlockTx:: invalid l1 info tree index');
}

// invalid batch if valueLeaf is 0
if (valueLeaf === Constants.ZERO_BYTES32) {
return true;
}
}
Expand Down
2 changes: 1 addition & 1 deletion test/contract-utils.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ describe('contractUtils', function () {
const expectedBatchHashData = '0x5e7875ab198c4d93379c92990a5d0111af59a0e62b2c4a0e3898e5bd24a18e58';
// TODO: input taken from pil-stark
const expectedStarkHashExecutor = '0xcfae2cfa3b8f3f12abce1bccd90e9b203dfdbe56c0c412114f2d3e67c9a897db';
const expectedSnarkInputHash = '14261007919052674347941079765745619634521069459113175679360275962408703057507';
const expectedSnarkInputHash = '14744991293971375789164639158836701110243288198095088376701471320299286035170';

before(async () => {
testVector = JSON.parse(fs.readFileSync(path.join(pathTestVectors, 'inputs-executor/input_executor.json')));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": 0,
"description": "Get timestamp",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"genesis": [
Expand Down Expand Up @@ -536,7 +536,7 @@
"id": 1,
"description": "Verify skip flags",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"genesis": [
Expand Down Expand Up @@ -828,7 +828,7 @@
"id": 2,
"description": "Previous batch partition in just one batch",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"genesis": [
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test-vectors/block-info/block-info.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": 0,
"description": "Get timestamp",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"genesis": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"description": "Test end to end",
"bridgeDeployed": true,
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"genesis": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
"oldNumBatch": 0,
"newNumBatch": 1,
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"forcedBlockHashL1": "0x0000000000000000000000000000000000000000000000000000000000000000",
"batchL2Data": "0x0b73e6af6e00000001ee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731bff0b0000000100000002",
"l1InfoRoot": "0x462ed3d694d640f04f637e5e3893e8d12f407a53f50201401fd992bb5ab0faf0",
Expand Down
157 changes: 154 additions & 3 deletions test/helpers/test-vectors/processor/state-transition-etrog.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"id": 0,
"description": "2 accounts and 1 valid transaction.",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"timestampLimit": 1944498031,
"forcedBlockHashL1": "0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down Expand Up @@ -181,7 +181,7 @@
"id": 1,
"description": "Forced batch: 2 accounts and 1 valid transaction",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"timestampLimit": 1944498031,
"forcedBlockHashL1": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
Expand Down Expand Up @@ -265,7 +265,7 @@
"id": 2,
"description": "Forced batch: starts with changeL2Block --> invalid batch",
"chainID": 1000,
"forkID": 8,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"timestampLimit": 1944498031,
"forcedBlockHashL1": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
Expand Down Expand Up @@ -411,5 +411,156 @@
"oldLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"expectedNewAccInputHash": "0x0336efc1bf6e35a64d3d4e654f18ca445635db7df54e894e82899e7b7f63ef95"
},
{
"id": 3,
"description": "invalid l1 info tree index",
"chainID": 1000,
"forkID": 9,
"sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"timestampLimit": 1944498031,
"forcedBlockHashL1": "0x0000000000000000000000000000000000000000000000000000000000000000",
"genesis": [
{
"address": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"pvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"balance": "100000000000000000000",
"nonce": "0"
},
{
"address": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff",
"pvtKey": "0x4d27a600dce8c29b7bd080e29a26972377dbb04d7a27d919adbb602bf13cfd23",
"balance": "200000000000000000000",
"nonce": "0"
}
],
"expectedOldRoot": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d",
"txs": [
{
"type": 11,
"deltaTimestamp": "1944498030",
"l1Info": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42",
"smtProof": [
"0x3cac317908c699fe873a7f6ee4e8cd63fbe9918b2315c97be91585590168e301",
"0xb5d05e7ec69f076afd4596fab0aa7a8d887b6444d11e1d1074b4379e9c75ce7a",
"0xb4c11951957c6f8f642c4af61cd6b24640fec6dc7fc607ee8206a99e92410d30",
"0x21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85",
"0xe58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344",
"0x0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d",
"0x887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968",
"0xffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83",
"0x9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af",
"0xcefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0",
"0xf9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5",
"0xf8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892",
"0x3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c",
"0xc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb",
"0x5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc",
"0xda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2",
"0x2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f",
"0xe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a",
"0x5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0",
"0xb46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0",
"0xc65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2",
"0xf4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9",
"0x5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377",
"0x4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652",
"0xcdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef",
"0x0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d",
"0xb8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0",
"0x838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e",
"0x662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e",
"0x388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322",
"0x93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735",
"0x8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9"
]
},
"indexL1InfoTree": 1,
"reason": "",
"customRawTx": "0x0b73e6af6e00000001"
},
{
"id": 0,
"from": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D",
"to": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff",
"nonce": 0,
"value": "100000000000000000",
"gasLimit": 100000,
"gasPrice": "1000000000",
"chainId": 1000,
"rawTx": "0xf86e80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808207f3a01cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e7a05d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad73",
"reason": "",
"customRawTx": "0xee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731bff"
},
{
"type": 11,
"deltaTimestamp": "1",
"l1Info": {
"globalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"timestamp": "0",
"smtProof": [
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0xad3228b676f7d3cd4284a5443f17f1962b36e491b30a40b2405849e597ba5fb5",
"0x972a8798db6341eb60eb7b513251a55c0641c98ca6f99f88332edecddb53b2a4",
"0x21ddb9a356815c3fac1026b6dec5df3124afbadb485c9ba5a3e3398a04b7ba85",
"0xe58769b32a1beaf1ea27375a44095a0d1fb664ce2dd358e7fcbfb78c26a19344",
"0x0eb01ebfc9ed27500cd4dfc979272d1f0913cc9f66540d7e8005811109e1cf2d",
"0x887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968",
"0xffd70157e48063fc33c97a050f7f640233bf646cc98d9524c6b92bcf3ab56f83",
"0x9867cc5f7f196b93bae1e27e6320742445d290f2263827498b54fec539f756af",
"0xcefad4e508c098b9a7e1d8feb19955fb02ba9675585078710969d3440f5054e0",
"0xf9dc3e7fe016e050eff260334f18a5d4fe391d82092319f5964f2e2eb7c1c3a5",
"0xf8b13a49e282f609c317a833fb8d976d11517c571d1221a265d25af778ecf892",
"0x3490c6ceeb450aecdc82e28293031d10c7d73bf85e57bf041a97360aa2c5d99c",
"0xc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb",
"0x5c67add7c6caf302256adedf7ab114da0acfe870d449a3a489f781d659e8becc",
"0xda7bce9f4e8618b6bd2f4132ce798cdc7a60e7e1460a7299e3c6342a579626d2",
"0x2733e50f526ec2fa19a22b31e8ed50f23cd1fdf94c9154ed3a7609a2f1ff981f",
"0xe1d3b5c807b281e4683cc6d6315cf95b9ade8641defcb32372f1c126e398ef7a",
"0x5a2dce0a8a7f68bb74560f8f71837c2c2ebbcbf7fffb42ae1896f13f7c7479a0",
"0xb46a28b6f55540f89444f63de0378e3d121be09e06cc9ded1c20e65876d36aa0",
"0xc65e9645644786b620e2dd2ad648ddfcbf4a7e5b1a3a4ecfe7f64667a3f0b7e2",
"0xf4418588ed35a2458cffeb39b93d26f18d2ab13bdce6aee58e7b99359ec2dfd9",
"0x5a9c16dc00d6ef18b7933a6f8dc65ccb55667138776f7dea101070dc8796e377",
"0x4df84f40ae0c8229d0d6069e5c8f39a7c299677a09d367fc7b05e3bc380ee652",
"0xcdc72595f74c7b1043d0e1ffbab734648c838dfb0527d971b602bc216c9619ef",
"0x0abf5ac974a1ed57f4050aa510dd9c74f508277b39d7973bb2dfccc5eeb0618d",
"0xb8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0",
"0x838c5655cb21c6cb83313b5a631175dff4963772cce9108188b34ac87c81c41e",
"0x662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e",
"0x388ab20e2573d171a88108e79d820e98f26c0b84aa8b2f4aa4968dbb818ea322",
"0x93237c50ba75ee485f4c22adf2f741400bdf8d6a9cc7df7ecae576221665d735",
"0x8448818bb4ae4562849e949e17ac16e0be16688e156b5cf15e098c627c0056a9"
]
},
"indexL1InfoTree": 7,
"reason": "",
"customRawTx": "0x0b0000000100000007"
}
],
"expectedNewRoot": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d",
"expectedNewLeafs": {
"0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D": {
"pvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e",
"balance": "100000000000000000000",
"nonce": "0"
},
"0x4d5Cf5032B2a844602278b01199ED191A86c93ff": {
"pvtKey": "0x4d27a600dce8c29b7bd080e29a26972377dbb04d7a27d919adbb602bf13cfd23",
"balance": "200000000000000000000",
"nonce": "0"
}
},
"batchL2Data": "0x0b73e6af6e00000001ee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731bff0b0000000100000007",
"l1InfoRoot": "0x6d6736762e8abbaf9a855c16a9bdd5bf3aae639b92b9bdf36af78b18833ba7ab",
"newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"batchHashData": "0x69a921af83ec2106c2e311bef9a6d6907c8b6b92b0f008fb847914baff87b3a5",
"oldLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"expectedNewAccInputHash": "0x5fb71959d81b5d982511e22a5f7db2aee66d17f9016c333f7ad531fca0610869"
}
]
Loading
Loading