Skip to content

Commit

Permalink
Naming refactors
Browse files Browse the repository at this point in the history
  • Loading branch information
ignasirv committed Mar 19, 2024
1 parent b267ca4 commit 659e8dd
Show file tree
Hide file tree
Showing 12 changed files with 31 additions and 41 deletions.
10 changes: 1 addition & 9 deletions src/contract-utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,6 @@ async function calculateSnarkInput(
// 32 bytes each field element for oldStateRoot
const strOldBatchAccInputHash = padZeros((Scalar.fromString(oldBatchAccInputHash, 16)).toString(16), 64);

// 8 bytes for oldNumBatch
const strOldNumBatch = padZeros(Scalar.e(oldNumBatch).toString(16), 16);

// 8 bytes for chainID
const strChainID = padZeros(Scalar.e(chainID).toString(16), 16);

Expand All @@ -55,20 +52,15 @@ async function calculateSnarkInput(
// 32 bytes each field element for oldStateRoot
const strNewLocalExitRoot = padZeros((Scalar.fromString(newLocalExitRoot, 16)).toString(16), 64);

// 8 bytes for newNumBatch
const strNewNumBatch = padZeros(Scalar.e(newNumBatch).toString(16), 16);

// build final bytes sha256
const finalStr = strAggregatorAddress
.concat(strOldStateRoot)
.concat(strOldBatchAccInputHash)
.concat(strOldNumBatch)
.concat(strChainID)
.concat(strForkID)
.concat(strNewStateRoot)
.concat(strNewBatchAccInputHash)
.concat(strNewLocalExitRoot)
.concat(strNewNumBatch);
.concat(strNewLocalExitRoot);

return sha256Snark(finalStr);
}
Expand Down
12 changes: 5 additions & 7 deletions src/processor.js
Original file line number Diff line number Diff line change
Expand Up @@ -844,7 +844,7 @@ module.exports = class Processor {
if (this.isForced) {
// get and verify forcedHashData
const computedForcedHashData = getL1InfoTreeValue(
this.forcedData.GER,
this.forcedData.globalExitRoot,
this.forcedData.blockHashL1,
this.forcedData.minTimestamp,
);
Expand All @@ -857,7 +857,7 @@ module.exports = class Processor {
// set forced data
const timestampForced = Scalar.e(this.forcedData.minTimestamp);
// set forced global exit root and default blockHash
finalGER = this.forcedData.GER;
finalGER = this.forcedData.globalExitRoot;
finalBlockHash = this.forcedData.blockHashL1;

// Update timestamp only if timestampForced > currentTimestamp
Expand Down Expand Up @@ -887,16 +887,16 @@ module.exports = class Processor {
throw new Error(`${getFuncName()}: BatchProcessor:_processChangeL2BlockTx:: missing l1Info`);
}

// Verify newTimestamp >= l1InfoRoot.timestamp
if (Scalar.lt(newTimestamp, l1Info.timestamp)) {
// Verify newTimestamp >= l1InfoRoot.minTimestamp
if (Scalar.lt(newTimestamp, l1Info.minTimestamp)) {
return true;
}

// Compute l1InfoTree
const infoTreeData = getL1InfoTreeValue(
l1Info.globalExitRoot,
l1Info.blockHash,
l1Info.timestamp,
l1Info.minTimestamp,
);

// fulfill l1InfoTree information
Expand Down Expand Up @@ -1004,8 +1004,6 @@ module.exports = class Processor {
newBatchAccInputHash, // output
newLocalExitRoot, // output
newTimestamp, // output
oldNumBatch: this.oldNumBatch,
newNumBatch: this.newNumBatch,
chainID: this.chainID,
forkID: this.forkID,
forcedHashData: this.forcedHashData,
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 @@ -10,7 +10,7 @@ describe('contractUtils', function () {
this.timeout(10000);
let testVector;

const expectedSnarkInputHash = '2fb8268c8d9d06cec48676c7cf3dbafde604d3202e25762ec5313b0f916f74dc';
const expectedSnarkInputHash = '1945042d70b86b81b1d301119ea2bffa6b131f651ebf66858796980298fb76f8';

before(async () => {
testVector = JSON.parse(fs.readFileSync(path.join(pathTestVectors, 'inputs-executor/input_executor.json')));
Expand Down
12 changes: 6 additions & 6 deletions test/helpers/test-vectors/block-info/block-info-batches.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -232,7 +232,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -409,7 +409,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -475,7 +475,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -591,7 +591,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -887,7 +887,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
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 @@ -50,7 +50,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@
"l1InfoTree": {
"globalExitRoot": "0x772a7e7f901e350a1943a7204f9bcc5da04bcb804d3b37c4debda567b05b13c4",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42",
"minTimestamp": "42",
"historicRoot": "0x27ae5ba08d7291c96c8cbddcc148bf48a6d68c7974b94356f53754ef6171d757",
"smtProofPreviousIndex": [
"0xcc4105312818e9b7f692c9c807ea09699f4f290e5e31671a8e0c2c937f1c43f0",
Expand Down
4 changes: 2 additions & 2 deletions test/helpers/test-vectors/inputs-executor/input_executor.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
"1": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42",
"minTimestamp": "42",
"historicRoot": "0x27ae5ba08d7291c96c8cbddcc148bf48a6d68c7974b94356f53754ef6171d757",
"smtProofPreviousIndex": [
"0xcc4105312818e9b7f692c9c807ea09699f4f290e5e31671a8e0c2c937f1c43f0",
Expand Down Expand Up @@ -60,7 +60,7 @@
"2": {
"globalExitRoot": "0x887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968",
"blockHash": "0xc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb",
"timestamp": "42",
"minTimestamp": "42",
"smtProofPreviousIndex": [
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0xf20741cd2005f97f7438e62c7d6a5e4140ce47c240a3f32469ddabfd265ac118",
Expand Down
16 changes: 8 additions & 8 deletions test/helpers/test-vectors/processor/state-transition-feijoa.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"l1InfoTree": {
"globalExitRoot": "0x887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968",
"blockHash": "0xc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb",
"timestamp": "42",
"minTimestamp": "42",
"smtProofPreviousIndex": [
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0xf20741cd2005f97f7438e62c7d6a5e4140ce47c240a3f32469ddabfd265ac118",
Expand Down Expand Up @@ -90,7 +90,7 @@
"l1InfoTree": {
"globalExitRoot": "0x662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e",
"blockHash": "0xb8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0",
"timestamp": "42",
"minTimestamp": "42",
"smtProofPreviousIndex": [
"0xd32085410db8c1abc5817e1e4a514fcc8d6345263aa02c5d8132182ce64dc243",
"0x5208554db01ad89751c5bfea8c72835636748e07c8214f8d7ea97a14953eac39",
Expand Down Expand Up @@ -212,7 +212,7 @@
"l1InfoTree": {
"globalExitRoot": "0x887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968",
"blockHash": "0xc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb",
"timestamp": "42",
"minTimestamp": "42",
"historicRoot": "0x4c9ea822b94a2367aeba9ce15cc881edfda28e1763e377b54a141068b08002f4",
"smtProofPreviousIndex": [
"0x0000000000000000000000000000000000000000000000000000000000000000",
Expand Down Expand Up @@ -272,7 +272,7 @@
"l1InfoTree": {
"globalExitRoot": "0x662ee4dd2dd7b2bc707961b1e646c4047669dcb6584f0d8d770daf5d7e7deb2e",
"blockHash": "0xb8cd74046ff337f0a7bf2c8e03e10f642c1886798d71806ab1e888d9e5ee87d0",
"timestamp": "42",
"minTimestamp": "42",
"smtProofPreviousIndex": [
"0xd32085410db8c1abc5817e1e4a514fcc8d6345263aa02c5d8132182ce64dc243",
"0x5208554db01ad89751c5bfea8c72835636748e07c8214f8d7ea97a14953eac39",
Expand Down Expand Up @@ -385,7 +385,7 @@
"oldStateRoot": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d",
"type": 2,
"forcedData": {
"GER": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHashL1": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"minTimestamp": "1944498031"
},
Expand Down Expand Up @@ -477,7 +477,7 @@
"oldStateRoot": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d",
"type": 2,
"forcedData": {
"GER": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHashL1": "0xd4e56740f876aef8c010b86a40d5f56745a118d0906a34e69aec8c0db1cb8fa3",
"minTimestamp": "1944498031"
},
Expand All @@ -491,7 +491,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42",
"minTimestamp": "42",
"smtProofPreviousIndex": [
"0xcc4105312818e9b7f692c9c807ea09699f4f290e5e31671a8e0c2c937f1c43f0",
"0xece5fbe7739fd48f4931ce884ee9cf5f373d0a6c63b80ce836bc0ae674e78540",
Expand Down Expand Up @@ -550,7 +550,7 @@
"l1InfoTree": {
"globalExitRoot": "0x887c22bd8750d34016ac3c66b5ff102dacdd73f6b014e710b51e8022af9a1968",
"blockHash": "0xc1df82d9c4b87413eae2ef048f94b4d3554cea73d92b0f7af96e0271c691e2bb",
"timestamp": "4242",
"minTimestamp": "4242",
"smtProofPreviousIndex": [
"0x0000000000000000000000000000000000000000000000000000000000000000",
"0xf20741cd2005f97f7438e62c7d6a5e4140ce47c240a3f32469ddabfd265ac118",
Expand Down
2 changes: 1 addition & 1 deletion test/helpers/test-vectors/selfdestruct/selfdestruct.json
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down
6 changes: 3 additions & 3 deletions test/helpers/test-vectors/zkevm-db/recursive.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -95,7 +95,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down Expand Up @@ -161,7 +161,7 @@
"newLocalExitRoot": "0x0000000000000000000000000000000000000000000000000000000000000000",
"newBatchAccInputHash": "0x2fc8173e6ee892814ac9b8f4eba51bf0378e06b75136041a3e932038ad0f09be",
"newNumBatch": 2,
"inputSnark": "0x2013a71d559dcc6bd5aee3e1cde7fb03a075fe5c3ad96c267368e79f1a9d6c5a",
"inputSnark": "0x2469468e919ccdafb49b2805eabcf953b8bdbd570e3c1c9cd75b044463047870",
"expectedOldRoot": "0x4a9bfcb163ec91c5beb22e6aca41592433092c8c7821b01d37fd0de483f9265d"
}
]
2 changes: 1 addition & 1 deletion test/helpers/test-vectors/zkevm-db/state-transition.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"l1InfoTree": {
"globalExitRoot": "0x16994edfddddb9480667b64174fc00d3b6da7290d37b8db3a16571b4ddf0789f",
"blockHash": "0x24a5871d68723340d9eadc674aa8ad75f3e33b61d5a9db7db92af856a19270bb",
"timestamp": "42"
"minTimestamp": "42"
},
"indexL1InfoTree": 0,
"reason": "",
Expand Down
2 changes: 1 addition & 1 deletion test/processor.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@ describe('Processor', async function () {
}
}
const computedForcedHashData = type === 2 ? getL1InfoTreeValue(
forcedData.GER,
forcedData.globalExitRoot,
forcedData.blockHashL1,
forcedData.minTimestamp,
) : Constants.ZERO_BYTES32;
Expand Down

0 comments on commit 659e8dd

Please sign in to comment.