diff --git a/.gitignore b/.gitignore index d5997389..9be58020 100644 --- a/.gitignore +++ b/.gitignore @@ -117,4 +117,8 @@ package-lock.json tools/fill-genesis/*.ignore.json # input examples -tools/inputs-examples/ \ No newline at end of file +tools/inputs-examples/ + +# ignore +*.ignore/ +tools/*.ignore/ \ No newline at end of file diff --git a/package.json b/package.json index bd936ca1..530eca0e 100644 --- a/package.json +++ b/package.json @@ -12,7 +12,7 @@ "test:selfdestruct": "npx mocha ./test/processor.test.js --selfdestruct", "eslint": "npx eslint src/** test/*.test.js && npx eslint tools", "eslint:fix": "npx eslint src/** test/*.test.js --fix && npx eslint tools --fix", - "test:update": "./tools/update-tests/update-tests.sh", + "test:update": "cd test && npx hardhat compile && cd .. && ./tools/update-tests/update-tests.sh", "test:database": "npx mocha ./test/database.test.js", "build:inputs": "npx mocha ./test/processor.test.js --update --geninputs && npx mocha ./test/processor.test.js --etrog --update --geninputs" }, diff --git a/src/processor.js b/src/processor.js index 962059c8..a65e98d5 100644 --- a/src/processor.js +++ b/src/processor.js @@ -202,6 +202,17 @@ module.exports = class Processor { try { const decodedObject = decodeCustomRawTxProverMethod(rawTx); txDecoded = decodedObject.txDecoded; + /* + * The RLP encoding, encodes the 0 integer as "0x" ( empty byte array), + * In order to be compatible with Scalar or Number we will update the 0x integer cases with 0x00 + */ + const txParams = Object.keys(txDecoded); + + txParams.forEach((key) => { + if (txDecoded[key] === '0x' && key !== 'data' && key !== 'to') { + txDecoded[key] = '0x00'; + } + }); rlpSignData = decodedObject.rlpSignData; } catch (error) { this.decodedTxs.push({ isInvalid: true, reason: 'TX INVALID: Failed to RLP decode signing data', tx: txDecoded }); @@ -231,17 +242,6 @@ module.exports = class Processor { continue; } - /* - * The RLP encoding, encodes the 0 integer as "0x" ( empty byte array), - * In order to be compatible with Scalar or Number we will update the 0x integer cases with 0x00 - */ - const txParams = Object.keys(txDecoded); - - txParams.forEach((key) => { - if (txDecoded[key] === '0x' && key !== 'data' && key !== 'to') { - txDecoded[key] = '0x00'; - } - }); this.decodedTxs.push({ isInvalid: false, reason: '', tx: txDecoded }); } } @@ -773,7 +773,7 @@ module.exports = class Processor { async _processChangeL2BlockTx(tx) { // Reduce counters - this.vcm.computeFunctionCounters('processChangeL2Block'); + this.vcm.computeFunctionCounters('processChangeL2Block', { verifyMerkleProof: tx.indexL1InfoTree !== 0 }); // write old blockhash (oldStateRoot) on storage // Get old blockNumber diff --git a/src/virtual-counters-manager.js b/src/virtual-counters-manager.js index 143c86e1..cf4d5ec9 100644 --- a/src/virtual-counters-manager.js +++ b/src/virtual-counters-manager.js @@ -7,7 +7,6 @@ /* eslint-disable no-use-before-define */ /* eslint-disable prefer-destructuring */ -const totalSteps = 2 ** 23; // Maximum counters poseidon level when interacting with a small smt (blockInfoTree, touchedAccountsTree..), is constant const MCPL = 23; // Maximum counters poseidon level when interacting with a big smt (stateTree), is variable and can be updated @@ -19,7 +18,6 @@ const FPEC = Scalar.e('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF const FNEC = Scalar.e('0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEBAAEDCE6AF48A03BBFD25E8CD0364141'); const FNEC_MINUS_ONE = Scalar.sub(FNEC, Scalar.e(1)); const spentCountersByFunction = {}; - module.exports = class VirtualCountersManager { /** * constructor class @@ -27,48 +25,54 @@ module.exports = class VirtualCountersManager { * @param {Boolean} config.verbose - Activate or deactivate verbose mode, default: false */ constructor(config = {}) { + this.configSteps = config.steps || 2 ** 23; + // safe guard counters to not take into account (%RANGE = 1 / SAFE_RANGE) + this.safeRange = config.safeRange || 20; + this.totalSteps = Math.floor(this.configSteps - this.configSteps / this.safeRange); this.verbose = config.verbose || false; + this.consumptionReport = []; + this.MCPReduction = config.MCPReduction || 0.6; // Compute counter initial amounts this.currentCounters = { S: { - amount: totalSteps, + amount: this.totalSteps, name: 'steps', - initAmount: totalSteps, + initAmount: this.totalSteps, }, A: { - amount: Math.floor(totalSteps / 32), + amount: Math.floor(this.totalSteps / 32), name: 'arith', - initAmount: Math.floor(totalSteps / 32), + initAmount: Math.floor(this.totalSteps / 32), }, B: { - amount: Math.floor(totalSteps / 16), + amount: Math.floor(this.totalSteps / 16), name: 'binary', - initAmount: Math.floor(totalSteps / 16), + initAmount: Math.floor(this.totalSteps / 16), }, M: { - amount: Math.floor(totalSteps / 32), + amount: Math.floor(this.totalSteps / 32), name: 'memAlign', - initAmount: Math.floor(totalSteps / 32), + initAmount: Math.floor(this.totalSteps / 32), }, K: { - amount: Math.floor((totalSteps / 155286) * 44), + amount: Math.floor((this.totalSteps / 155286) * 44), name: 'keccaks', - initAmount: Math.floor((totalSteps / 155286) * 44), + initAmount: Math.floor((this.totalSteps / 155286) * 44), }, D: { - amount: Math.floor(totalSteps / 56), + amount: Math.floor(this.totalSteps / 56), name: 'padding', - initAmount: Math.floor(totalSteps / 56), + initAmount: Math.floor(this.totalSteps / 56), }, P: { - amount: Math.floor(totalSteps / 30), + amount: Math.floor(this.totalSteps / 31), name: 'poseidon', - initAmount: Math.floor(totalSteps / 30), + initAmount: Math.floor(this.totalSteps / 31), }, SHA: { - amount: Math.floor((totalSteps - 1) / 31488) * 7, + amount: Math.floor((this.totalSteps - 1) / 31488) * 7, name: 'sha256', - initAmount: Math.floor((totalSteps - 1) / 31488) * 7, + initAmount: Math.floor((this.totalSteps - 1) / 31488) * 7, }, }; this.currentCountersSnapshot = {}; @@ -110,7 +114,7 @@ module.exports = class VirtualCountersManager { * @param {Number} levels number of levels */ setSMTLevels(levels) { - MCP = levels; + MCP = Math.floor(levels * this.MCPReduction); } /** @@ -130,6 +134,10 @@ module.exports = class VirtualCountersManager { spentCounters[this.currentCountersSnapshot[counter].name] = this.currentCountersSnapshot[counter].amount - this.currentCounters[counter].amount; }); this._verbose(spentCounters); + this.consumptionReport.push({ + function: this.calledFunc, + vcounters: spentCounters, + }); this.currentCountersSnapshot = spentCounters; // Fill counters consumption by function if (!spentCountersByFunction[this.calledFunc]) { @@ -242,18 +250,22 @@ module.exports = class VirtualCountersManager { this._processContractCall({ ...input, ...{ isCreate: false, isCreate2: false } }); } - processChangeL2Block() { + processChangeL2Block(input) { + this._checkInput(input, ['verifyMerkleProof']); this._reduceCounters(70, 'S'); this._reduceCounters(4 + 4, 'B'); this._reduceCounters(6 * MCP, 'P'); this._reduceCounters(2, 'K'); this._consolidateBlock(); this._setupNewBlockInfoTree(); - this._verifyMerkleProof(); + if (input.verifyMerkleProof) { + this._verifyMerkleProof(); + } } _verifyMerkleProof() { this._reduceCounters(250, 'S'); + this._reduceCounters(1, 'B'); this._reduceCounters(33, 'K'); } @@ -279,9 +291,9 @@ module.exports = class VirtualCountersManager { _ecAdd() { // Worst case scenario - this._reduceCounters(323, 'S'); - this._reduceCounters(33, 'B'); - this._reduceCounters(40, 'A'); + this._reduceCounters(800, 'S'); + this._reduceCounters(50, 'B'); + this._reduceCounters(50, 'A'); } preECMul() { @@ -295,9 +307,9 @@ module.exports = class VirtualCountersManager { _ecMul() { // Worst case scenario - this._reduceCounters(162890, 'S'); - this._reduceCounters(16395, 'B'); - this._reduceCounters(19161, 'A'); + this._reduceCounters(175000, 'S'); + this._reduceCounters(20000, 'B'); + this._reduceCounters(20000, 'A'); } preECPairing(input) { @@ -313,9 +325,9 @@ module.exports = class VirtualCountersManager { _ecPairing(inputsCount) { // worst case scenario - this._reduceCounters(16 + inputsCount * 184017 + 171253, 'S'); - this._reduceCounters(inputsCount * 3986 + 650, 'B'); - this._reduceCounters(inputsCount * 13694 + 15411, 'A'); + this._reduceCounters(16 + inputsCount * 200000 + 175000, 'S'); + this._reduceCounters(inputsCount * 4100 + 750, 'B'); + this._reduceCounters(inputsCount * 15000 + 17500, 'A'); } preModExp(input) { @@ -353,7 +365,7 @@ module.exports = class VirtualCountersManager { this._checkInput(input, ['calldataLength']); this._reduceCounters(100, 'S'); this._reduceCounters(1, 'B'); - this._reduceCounters(Math.ceil((input.calldataLength + 1) / 64), 'SHA'); + this._reduceCounters(Math.ceil((input.calldataLength + 1 + 8) / 64), 'SHA'); this._multiCall('_divArith', 2); this._mStore32(); this._mStoreX(); @@ -660,28 +672,24 @@ module.exports = class VirtualCountersManager { this._opcode(input); this._reduceCounters(10, 'S'); this._reduceCounters(1, 'B'); - this._reduceCounters(MCP, 'P'); } opOr(input) { this._opcode(input); this._reduceCounters(10, 'S'); this._reduceCounters(1, 'B'); - this._reduceCounters(MCP, 'P'); } opXor(input) { this._opcode(input); this._reduceCounters(10, 'S'); this._reduceCounters(1, 'B'); - this._reduceCounters(MCP, 'P'); } opNot(input) { this._opcode(input); this._reduceCounters(10, 'S'); this._reduceCounters(1, 'B'); - this._reduceCounters(MCP, 'P'); } opByte(input) { @@ -916,7 +924,7 @@ module.exports = class VirtualCountersManager { this._opcode(input); this._checkInput(input, ['inputSize']); this._reduceCounters(40, 'S'); - this._reduceCounters(Math.ceil((input.inputSize + 1) / 32), 'K'); + this._reduceCounters(Math.ceil((input.inputSize + 1) / 136), 'K'); this._saveMem({ length: input.inputSize }); this._multiCall('_divArith', 2); this._mulArith(); @@ -996,7 +1004,7 @@ module.exports = class VirtualCountersManager { this._divArith(); this._reduceCounters(Math.ceil(input.inputSize / 56) + 4, 'P'); this._reduceCounters(Math.ceil(input.inputSize / 56) + 4, 'D'); - this._multiCall('_opLogLoop', Math.floor(input.inputSize + 1 / 32)); + this._multiCall('_opLogLoop', Math.floor((input.inputSize + 1) / 32)); this._mLoadX(); this._SHRarith(); this._fillBlockInfoTreeWithLog(); @@ -1154,6 +1162,7 @@ module.exports = class VirtualCountersManager { this._reduceCounters(10, 'S'); for (let i = 0; i < input.pushBytes; i++) { this._reduceCounters(10, 'S'); + this._SHLarith(); } } } else { @@ -1351,7 +1360,7 @@ module.exports = class VirtualCountersManager { _opcode(input) { this._reduceCounters(12, 'S'); - if (input.isCreate2 || input.isCreate || input.isDeploy) { + if (input.isCreate2 || input.isCreate) { this._mLoadX(); this._SHRarith(); } @@ -1514,7 +1523,7 @@ module.exports = class VirtualCountersManager { } _mLoadX() { - this._reduceCounters(40, 'S'); + this._reduceCounters(30, 'S'); this._reduceCounters(2, 'B'); this._reduceCounters(1, 'M'); this._offsetUtil(); @@ -1523,7 +1532,7 @@ module.exports = class VirtualCountersManager { } _mStoreX() { - this._reduceCounters(100, 'S'); + this._reduceCounters(80, 'S'); this._reduceCounters(1, 'B'); this._reduceCounters(1, 'M'); this._offsetUtil(); @@ -1532,7 +1541,7 @@ module.exports = class VirtualCountersManager { } _mStore32() { - this._reduceCounters(100, 'S'); + this._reduceCounters(80, 'S'); this._reduceCounters(1, 'B'); this._reduceCounters(1, 'M'); this._offsetUtil(); @@ -1685,7 +1694,7 @@ module.exports = class VirtualCountersManager { } _mulArith() { - this._reduceCounters(50, 'S'); + this._reduceCounters(40, 'S'); this._reduceCounters(1, 'B'); this._reduceCounters(1, 'A'); } @@ -1697,8 +1706,8 @@ module.exports = class VirtualCountersManager { } _SHLarith() { - this._reduceCounters(100, 'S'); - this._reduceCounters(4, 'B'); + this._reduceCounters(40, 'S'); + this._reduceCounters(2, 'B'); this._reduceCounters(2, 'A'); } @@ -1725,7 +1734,7 @@ module.exports = class VirtualCountersManager { } _SHRarith() { - this._reduceCounters(50, 'S'); + this._reduceCounters(40, 'S'); this._reduceCounters(2, 'B'); this._reduceCounters(1, 'A'); this._divArith(); @@ -1739,11 +1748,11 @@ module.exports = class VirtualCountersManager { this._reduceCounters(200, 'S'); this._reduceCounters(2, 'K'); this._reduceCounters(MCP, 'P'); - this._reduceCounters(1, 'B'); + this._reduceCounters(2, 'B'); } _divArith() { - this._reduceCounters(50, 'S'); + this._reduceCounters(40, 'S'); this._reduceCounters(3, 'B'); this._reduceCounters(1, 'A'); } diff --git a/test/contract-utils.test.js b/test/contract-utils.test.js index 79ff370a..703058a3 100644 --- a/test/contract-utils.test.js +++ b/test/contract-utils.test.js @@ -13,7 +13,7 @@ describe('contractUtils', function () { const expectedBatchHashData = '0x5e7875ab198c4d93379c92990a5d0111af59a0e62b2c4a0e3898e5bd24a18e58'; // TODO: input taken from pil-stark const expectedStarkHashExecutor = '0xcfae2cfa3b8f3f12abce1bccd90e9b203dfdbe56c0c412114f2d3e67c9a897db'; - const expectedSnarkInputHash = '14744991293971375789164639158836701110243288198095088376701471320299286035170'; + const expectedSnarkInputHash = '19704504443275424030853930423657339055467823429269903357094355701515609372092'; before(async () => { testVector = JSON.parse(fs.readFileSync(path.join(pathTestVectors, 'inputs-executor/input_executor.json'))); diff --git a/test/helpers/test-vectors/block-info/block-info-batches.json b/test/helpers/test-vectors/block-info/block-info-batches.json index c875e40a..d54bd1c6 100644 --- a/test/helpers/test-vectors/block-info/block-info-batches.json +++ b/test/helpers/test-vectors/block-info/block-info-batches.json @@ -3,7 +3,7 @@ "id": 0, "description": "Get timestamp", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ @@ -536,7 +536,7 @@ "id": 1, "description": "Verify skip flags", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ @@ -828,7 +828,7 @@ "id": 2, "description": "Previous batch partition in just one batch", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ diff --git a/test/helpers/test-vectors/block-info/block-info.json b/test/helpers/test-vectors/block-info/block-info.json index 81fb4fd1..ea6cf6c3 100644 --- a/test/helpers/test-vectors/block-info/block-info.json +++ b/test/helpers/test-vectors/block-info/block-info.json @@ -3,7 +3,7 @@ "id": 0, "description": "Get timestamp", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ diff --git a/test/helpers/test-vectors/end-to-end/state-transition-e2e.json b/test/helpers/test-vectors/end-to-end/state-transition-e2e.json index 27e8b2fe..b4c74206 100644 --- a/test/helpers/test-vectors/end-to-end/state-transition-e2e.json +++ b/test/helpers/test-vectors/end-to-end/state-transition-e2e.json @@ -4,7 +4,7 @@ "description": "Test end to end", "bridgeDeployed": true, "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ diff --git a/test/helpers/test-vectors/inputs-executor/input_executor.json b/test/helpers/test-vectors/inputs-executor/input_executor.json index 1dad5ddc..68be7920 100644 --- a/test/helpers/test-vectors/inputs-executor/input_executor.json +++ b/test/helpers/test-vectors/inputs-executor/input_executor.json @@ -7,7 +7,7 @@ "oldNumBatch": 0, "newNumBatch": 1, "chainID": 1000, - "forkID": 9, + "forkID": 12, "forcedBlockHashL1": "0x0000000000000000000000000000000000000000000000000000000000000000", "batchL2Data": "0x0b73e6af6e00000001ee80843b9aca00830186a0944d5cf5032b2a844602278b01199ed191a86c93ff88016345785d8a0000808203e880801cee7e01dc62f69a12c3510c6d64de04ee6346d84b6a017f3e786c7d87f963e75d8cc91fa983cd6d9cf55fff80d73bd26cd333b0f098acc1e58edb1fd484ad731bff0b0000000100000002", "l1InfoRoot": "0x462ed3d694d640f04f637e5e3893e8d12f407a53f50201401fd992bb5ab0faf0", diff --git a/test/helpers/test-vectors/l1-info-tree/l1-info-tree.json b/test/helpers/test-vectors/l1-info-tree/l1-info-tree.json new file mode 100644 index 00000000..861bb0cb --- /dev/null +++ b/test/helpers/test-vectors/l1-info-tree/l1-info-tree.json @@ -0,0 +1,73 @@ +[ + { + "description": "empty tree", + "leafs": [], + "expectedRoot": "0x27ae5ba08d7291c96c8cbddcc148bf48a6d68c7974b94356f53754ef6171d757" + }, + { + "description": "one leaf", + "leafs": [ + { + "leafData": { + "ger": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f", + "blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb", + "timestamp": "1697231573" + }, + "expectedLeafValue": "0xf62f487534b899b1c362242616725878188ca891fab60854b792ca0628286de7" + } + ], + "expectedRoot": "0x0a45670382cab3b636561952f7cc1ebbd5f9734e907d762875e89b419ce89c04" + }, + { + "description": "two leafs", + "leafs": [ + { + "leafData": { + "ger": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f", + "blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb", + "timestamp": "1697231573" + }, + "expectedLeafValue": "0xf62f487534b899b1c362242616725878188ca891fab60854b792ca0628286de7" + }, + { + "leafData": { + "ger": "0x356682567c5d485bbabe89590d3d72b08671a0a07899dcbaddccbe0599491669", + "blockHash": "0x8f9cfb43c0f6bc7ce9f9e43e8761776a2ef9657ccf87318e2487c313d119b8cf", + "timestamp": "658736476" + }, + "expectedLeafValue": "0xba9c9985e6c9cee54f57991049af0c42439fa2b2915a0597f4d63f63d31c1d4f" + } + ], + "expectedRoot": "0xce3937cebcd96734c492f13d47a8bc22e466cce44117fec1c28e2636d8cf543b" + }, + { + "description": "three leafs", + "leafs": [ + { + "leafData": { + "ger": "0x0000000000000000000000000000000000000000000000000000000000000000", + "blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000", + "timestamp": "0" + }, + "expectedLeafValue": "0x3cac317908c699fe873a7f6ee4e8cd63fbe9918b2315c97be91585590168e301" + }, + { + "leafData": { + "ger": "0x356682567c5d485bbabe89590d3d72b08671a0a07899dcbaddccbe0599491669", + "blockHash": "0x8f9cfb43c0f6bc7ce9f9e43e8761776a2ef9657ccf87318e2487c313d119b8cf", + "timestamp": "658736476" + }, + "expectedLeafValue": "0xba9c9985e6c9cee54f57991049af0c42439fa2b2915a0597f4d63f63d31c1d4f" + }, + { + "leafData": { + "ger": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "blockHash": "0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff", + "timestamp": "0xffffffffffffffff" + }, + "expectedLeafValue": "0xc2db4c8d173afd8fff4a7344663525d3ae155f2a60db2f157850eccb46887589" + } + ], + "expectedRoot": "0xe4f94a9663b007e7a1186cf27047aa2b85387c65c840e3811b7ac63c97555091" + } +] \ No newline at end of file diff --git a/test/helpers/test-vectors/processor/state-transition-etrog.json b/test/helpers/test-vectors/processor/state-transition-etrog.json index cf43bd87..d8b00f37 100644 --- a/test/helpers/test-vectors/processor/state-transition-etrog.json +++ b/test/helpers/test-vectors/processor/state-transition-etrog.json @@ -3,7 +3,7 @@ "id": 0, "description": "2 accounts and 1 valid transaction.", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "timestampLimit": 1944498031, "forcedBlockHashL1": "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -181,7 +181,7 @@ "id": 1, "description": "Forced batch: 2 accounts and 1 valid transaction", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "timestampLimit": 1944498031, "forcedBlockHashL1": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", @@ -265,7 +265,7 @@ "id": 2, "description": "Forced batch: starts with changeL2Block --> invalid batch", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "timestampLimit": 1944498031, "forcedBlockHashL1": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3", @@ -416,7 +416,7 @@ "id": 3, "description": "invalid l1 info tree index", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "timestampLimit": 1944498031, "forcedBlockHashL1": "0x0000000000000000000000000000000000000000000000000000000000000000", diff --git a/test/helpers/test-vectors/processor/state-transition.json b/test/helpers/test-vectors/processor/state-transition.json index 5bbb32c8..f4e9a7ad 100644 --- a/test/helpers/test-vectors/processor/state-transition.json +++ b/test/helpers/test-vectors/processor/state-transition.json @@ -3,7 +3,7 @@ "id": 0, "description": "2 accounts and 1 valid transaction.", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "timestampLimit": 1944498031, "genesis": [ @@ -89,7 +89,7 @@ "id": 1, "description": "5 accounts. 2 valid tx, 3 invalid tx (same amount as balance, invalid nonce, invalid chain id 1)", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { @@ -266,7 +266,7 @@ "id": 2, "description": "2 accounts and 1 invalid tx (tx with more value than balance). Old root equals new root.", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { @@ -348,7 +348,7 @@ "id": 3, "description": "2 accounts and 4 invalid transactions. Two of the transactions have invalid from and to address so no rawTx is provided for them, can be ignored.Tx with same amount than balance and tx with invalid chain id (different chain id than sequencer). Old root equals new root", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { @@ -465,7 +465,7 @@ "id": 4, "description": "2 accounts and 1 invalid transaction. Wrong encode of the tx (invalid signature). Old root equals new root", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { @@ -536,7 +536,7 @@ "id": 5, "description": "2 accounts and 1 valid transaction, from and to are the same", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", "genesis": [ { @@ -622,7 +622,7 @@ "id": 6, "description": "2 accounts. 1 valid tx, 3 invalid tx (same amount as balance, invalid nonce, invalid chain id", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", "genesis": [ { @@ -747,7 +747,7 @@ "id": 7, "description": "2 accounts and 1 valid transaction, from, to and sequencer are the same", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { @@ -833,7 +833,7 @@ "id": 8, "description": "2 accounts and 2 valid transaction, sequencer is able to do the transaction because the fees are payed at the end of every tx", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { @@ -932,7 +932,7 @@ "id": 9, "description": "2 accounts and 4 valid transaction, 4 transactions from the same account", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x4d5Cf5032B2a844602278b01199ED191A86c93ff", "genesis": [ { @@ -1057,7 +1057,7 @@ "id": 10, "description": "2 accounts + 1 contract + and 2 valid transaction.", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ @@ -1184,7 +1184,7 @@ "id": 11, "description": "2 accounts + 2 contract + and 1 tx to contract + contract call ", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ @@ -1306,7 +1306,7 @@ "id": 12, "description": "2 accounts + 2 contract with constructor + and 1 tx to contract + 1 contract call", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ @@ -1439,7 +1439,7 @@ "id": 13, "description": "2 accounts + and 1 tx to contract deploy + 1 call to deplyed contract", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ @@ -1572,7 +1572,7 @@ "id": 14, "description": "2 accounts and 3 valid transactions", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "timestampLimit": 1944498031, "genesis": [ diff --git a/test/helpers/test-vectors/selfdestruct/selfdestruct.json b/test/helpers/test-vectors/selfdestruct/selfdestruct.json index 1b2b00c4..e806fbce 100644 --- a/test/helpers/test-vectors/selfdestruct/selfdestruct.json +++ b/test/helpers/test-vectors/selfdestruct/selfdestruct.json @@ -3,7 +3,7 @@ "id": 0, "description": "Selfdestruct", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "sequencerPvtKey": "0x28b2b0318721be8c8339199172cd7cc8f5e273800a35616ec893083a4b32c02e", "genesis": [ diff --git a/test/helpers/test-vectors/zkevm-db/recursive.json b/test/helpers/test-vectors/zkevm-db/recursive.json index f85b9f65..e60e3215 100644 --- a/test/helpers/test-vectors/zkevm-db/recursive.json +++ b/test/helpers/test-vectors/zkevm-db/recursive.json @@ -3,7 +3,7 @@ "id": 0, "description": "2 accounts and 1 valid transaction.", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "l1InfoRoot": "0x090bcaf734c4f06c93954a827b45a6e8c67b8e0fd1e0a35a1c5982d6961828f9", "oldAccInputHash": "0x0000000000000000000000000000000000000000000000000000000000000000", @@ -214,6 +214,6 @@ "finalLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000", "finalAccInputHash": "0xe2d4571827432a99c09609d8f95dc8b207bfd6010b08e22462cf717597f788ff", "finalNumBatch": 2, - "inputSnark": "0x0d0c2dbe320dac28e92bc27bff78a5dc2a6e77a97ddbb3d6e6818a49c4fb3f64" + "inputSnark": "0x1d2f2dc2f3a9b2a6957bcd5c5bc7c18c5410ed74a3b0621dab79f61697346246" } ] \ No newline at end of file diff --git a/test/helpers/test-vectors/zkevm-db/state-transition.json b/test/helpers/test-vectors/zkevm-db/state-transition.json index 95f30c46..52ee10e8 100644 --- a/test/helpers/test-vectors/zkevm-db/state-transition.json +++ b/test/helpers/test-vectors/zkevm-db/state-transition.json @@ -3,7 +3,7 @@ "id": 0, "description": "2 accounts and 1 valid transaction.", "chainID": 1000, - "forkID": 9, + "forkID": 12, "sequencerAddress": "0x617b3a3528F9cDd6630fd3301B9c8911F7Bf063D", "genesis": [ { diff --git a/test/l1-info-tree.test.js b/test/l1-info-tree.test.js new file mode 100644 index 00000000..ef1c4966 --- /dev/null +++ b/test/l1-info-tree.test.js @@ -0,0 +1,63 @@ +const fs = require('fs'); +const path = require('path'); +const { expect } = require('chai'); +const { argv } = require('yargs'); + +const { pathTestVectors } = require('./helpers/test-utils'); +const { MTBridge, l1InfoTreeUtils } = require('../index'); + +describe('l1 Info Tree', async function () { + this.timeout(50000); + + const pathFullL1InfoTree = path.join(pathTestVectors, 'l1-info-tree/l1-info-tree.json'); + + let update; + let testVectors; + + before(async () => { + testVectors = JSON.parse(fs.readFileSync(pathFullL1InfoTree)); + + update = argv.update === true; + }); + + it('Should check test vectors', async () => { + const height = 32; + + // build tree and check root + for (let i = 0; i < testVectors.length; i++) { + const { leafs, expectedRoot } = testVectors[i]; + + const l1InfoTree = new MTBridge(height); + + for (let j = 0; j < leafs.length; j++) { + const { leafData, expectedLeafValue } = leafs[j]; + + const valueLeaf = l1InfoTreeUtils.getL1InfoTreeValue( + leafData.ger, + leafData.blockHash, + leafData.timestamp, + ); + + l1InfoTree.add(valueLeaf); + + if (update) { + testVectors[i].leafs[j].expectedLeafValue = valueLeaf; + } else { + expect(valueLeaf).to.be.equal(expectedLeafValue); + } + } + + const root = l1InfoTree.getRoot(); + + if (update) { + testVectors[i].expectedRoot = root; + } else { + expect(root).to.be.equal(expectedRoot); + } + } + + if (update) { + fs.writeFileSync(pathFullL1InfoTree, JSON.stringify(testVectors, null, 2)); + } + }); +}); diff --git a/test/zkevm-db.test.js b/test/zkevm-db.test.js index 9427d048..08b1af51 100644 --- a/test/zkevm-db.test.js +++ b/test/zkevm-db.test.js @@ -46,7 +46,7 @@ describe('ZkEVMDB', function () { const genesis = []; const db = new MemDB(F); const chainID = 1000; - const forkID = 9; + const forkID = 12; // create a zkEVMDB and build a batch const zkEVMDB = await ZkEVMDB.newZkEVM(