From 4047088379d9c9804aeb82056425476787e212ee Mon Sep 17 00:00:00 2001 From: Bence Haromi Date: Thu, 12 Oct 2023 17:15:00 +0100 Subject: [PATCH] chore: changed hashes to array --- SystemContractsHashes.json | 72 ++++++++++++++++++------------------- scripts/calculate-hashes.ts | 60 +++++++++++++++---------------- 2 files changed, 64 insertions(+), 68 deletions(-) diff --git a/SystemContractsHashes.json b/SystemContractsHashes.json index 25b27bdb..47a77de4 100644 --- a/SystemContractsHashes.json +++ b/SystemContractsHashes.json @@ -1,149 +1,149 @@ -{ - "accountCodeStorage": { +[ + { "contractName": "AccountCodeStorage", "sourceCodePath": "contracts/AccountCodeStorage.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/AccountCodeStorage.sol/AccountCodeStorage.json", - "bytecodeHash": "0x0100009b0ceab34b1f47a4d98bc5d4860c1f5dbe81a64973b56a7e077129c5d6", + "bytecodeHash": "0x0100009b3cd9a137912ffbd406a1d73eaffbcf40a760f3956fea7e051f0c6101", "sourceCodeHash": "0x721f289059b0bf670fecc03ad7a1f58ca7da2fe1fd9802457708944a82418590" }, - "bootloaderUtilities": { + { "contractName": "BootloaderUtilities", "sourceCodePath": "contracts/BootloaderUtilities.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/BootloaderUtilities.sol/BootloaderUtilities.json", - "bytecodeHash": "0x01000975d391bac081e6efab97a9bd8c51f0bd058e00aa9fdddf9160decf7286", + "bytecodeHash": "0x01000975e811c2ba4a3b28f70426598129f0029feb086714980f9513f59531c7", "sourceCodeHash": "0xb03c4703cb68b22cd7f74e04fa8b5d43025b98737a53c830a50138e385e2628b" }, - "complexUpgrader": { + { "contractName": "ComplexUpgrader", "sourceCodePath": "contracts/ComplexUpgrader.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/ComplexUpgrader.sol/ComplexUpgrader.json", - "bytecodeHash": "0x0100005b0340555e81a4db927af6ef0df772a1baba6aaaff6f8cf19e35fa3a76", + "bytecodeHash": "0x0100005b2eef785c804dc40ec24b3c2339b11a314fec6eb91db551a2523d6a2b", "sourceCodeHash": "0x774da238fac06b112f94e0b10064ce5dbb45dab9378ae7bc88fe096127c36b78" }, - "compressor": { + { "contractName": "Compressor", "sourceCodePath": "contracts/Compressor.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/Compressor.sol/Compressor.json", - "bytecodeHash": "0x010001b7297c61d6172f0b23934d876f8899487a53a9b1244384b943cfbeea35", + "bytecodeHash": "0x010001b7a7bb988e52b8fca05d82bccf63ea34c6617ebea1765c91e911386756", "sourceCodeHash": "0x0c5acc4841941f31b2343c49ac16173a1078b166a88d0409a521b9eda5f9c768" }, - "contractDeployer": { + { "contractName": "ContractDeployer", "sourceCodePath": "contracts/ContractDeployer.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/ContractDeployer.sol/ContractDeployer.json", - "bytecodeHash": "0x010005bbf036d01f6419ced8d6c98d09366d23cdbce95b7b2b211cf3ec064cb1", + "bytecodeHash": "0x010005bb3e1bb343565920b37c6c0d716dcfca45bbdada20a305e80ab60a6916", "sourceCodeHash": "0x837fdb9e6f2616fe6e189417ff48f8960d1c79245d75b275684fa10c9ac7d6c3" }, - "defaultAccount": { + { "contractName": "DefaultAccount", "sourceCodePath": "contracts/DefaultAccount.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/DefaultAccount.sol/DefaultAccount.json", - "bytecodeHash": "0x0100065d134a862a777e50059f5e0fbe68b583f3617a67820f7edda0d7f253a0", + "bytecodeHash": "0x0100065d0ea6130f484f6cd4936f2d5114abc9961328d6acd8b311dd00b94546", "sourceCodeHash": "0x0af09156a1485eb2f398a082027504281a8224f8d611662570d8a43efd967372" }, - "emptyContract": { + { "contractName": "EmptyContract", "sourceCodePath": "contracts/EmptyContract.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/EmptyContract.sol/EmptyContract.json", "bytecodeHash": "0x01000007c08e60bc60d70f759bc49f2488b70054b0cec1a64f0cf27953448f4c", "sourceCodeHash": "0xa1ba9e2afa6b403f23d21b8f173d273f93b522daaaba03f4cc75692ebc71a853" }, - "immutableSimulator": { + { "contractName": "ImmutableSimulator", "sourceCodePath": "contracts/ImmutableSimulator.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/ImmutableSimulator.sol/ImmutableSimulator.json", - "bytecodeHash": "0x010000472873871d37121bd9d4d5c12cde1667d1e2dad6f1e39d80a7f5830fad", + "bytecodeHash": "0x01000047b7e40b0e0f7bd7051e20853a49b972c6c0ac16872425067cb3288f08", "sourceCodeHash": "0xcaaaa98efde534901cd80aee33fb65a8d69fe702ef0fffd1e840f607d8b67b7c" }, - "knownCodesStorage": { + { "contractName": "KnownCodesStorage", "sourceCodePath": "contracts/KnownCodesStorage.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/KnownCodesStorage.sol/KnownCodesStorage.json", - "bytecodeHash": "0x0100008b07383bc28891f5c3b16cb2106c1a69839eee0a4a86a1c6eaa64d7c43", + "bytecodeHash": "0x0100008b806f904a40cadb94318db1d8a8ae9a579f46ee0b50432e4c221572ee", "sourceCodeHash": "0x0900ec65dd10108eeb76e4123e5ee95db16e4caf76502698511c0ac0ac2e1c55" }, - "l1Messenger": { + { "contractName": "L1Messenger", "sourceCodePath": "contracts/L1Messenger.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/L1Messenger.sol/L1Messenger.json", - "bytecodeHash": "0x010002fb34f285e9173965a047ce210290969caf59f3f608154e5de619fa4394", + "bytecodeHash": "0x010002fb863dc09dbfdae276418c307eb39af03f335a0b23a2edc8bcd1835fce", "sourceCodeHash": "0x123b72389c2c7b6580db376f4b2740b97d016086a1490c2451031112da090e05" }, - "l2EthToken": { + { "contractName": "L2EthToken", "sourceCodePath": "contracts/L2EthToken.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/L2EthToken.sol/L2EthToken.json", - "bytecodeHash": "0x01000139ed677253912a2e182b65705249cb121ef9ae84dc1e7a0b8a4d8f19f5", + "bytecodeHash": "0x01000139b0930df0818b0f10f7c78feed9ca93020efcb72e749a7ea842d08576", "sourceCodeHash": "0xc563fe25f07906ef60b17ccb48884784543f02493648f4f5bf19c9a9c74464d5" }, - "msgValueSimulator": { + { "contractName": "MsgValueSimulator", "sourceCodePath": "contracts/MsgValueSimulator.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/MsgValueSimulator.sol/MsgValueSimulator.json", - "bytecodeHash": "0x0100006f533fae831a02ee1b011d2953f485f0ddf07484a1e3862fe6f4a19600", + "bytecodeHash": "0x0100006f5dab2685a586d5ebbd360a2c1c2d593df1ab8267d8e172d92a202bfa", "sourceCodeHash": "0x2f4be7f4afe5ac19b02d62ae9a107c2fd6268d9cd7d96e997f049cb7eecb2c97" }, - "nonceHolder": { + { "contractName": "NonceHolder", "sourceCodePath": "contracts/NonceHolder.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/NonceHolder.sol/NonceHolder.json", - "bytecodeHash": "0x0100012fbc3d55229519528949732618cb02c44e47d25b1e8718e50ee3939a7e", + "bytecodeHash": "0x0100012f7252eee16af884775bd3279b577bbed64f124349ac6179aeb6ae3cb8", "sourceCodeHash": "0xfdc19bf88e636b5128e9591c9b4a072e6bb0dbe24d767685d00101e83393fa06" }, - "systemContext": { + { "contractName": "SystemContext", "sourceCodePath": "contracts/SystemContext.sol", "bytecodePath": "artifacts-zk/cache-zk/solpp-generated-contracts/SystemContext.sol/SystemContext.json", - "bytecodeHash": "0x0100023f210105bd1188da7a15dc82f99bd86f4b0a57bb50eb7325849be9a0d7", + "bytecodeHash": "0x0100023f1761d12df53e8581fabcb359cb069bbd2a7a7a3ef0b49f2f5d46169a", "sourceCodeHash": "0xd41f5281ff1d10055be4a06af5d35d86406a397e7bf9bb766e9f015fa4b57dce" }, - "eventWriter": { + { "contractName": "EventWriter", "sourceCodePath": "contracts/EventWriter.yul", "bytecodePath": "contracts/artifacts/EventWriter.yul/EventWriter.yul.zbin", "bytecodeHash": "0x01000019642d87621fdd82cf65aa9146486c9256d5f8849af9a37c78ef519339", "sourceCodeHash": "0x55cfee65f174350edfd690c949bc0a29458f25da11f1d5f90b57621567df1fc3" }, - "ecAdd": { + { "contractName": "EcAdd", "sourceCodePath": "contracts/precompiles/EcAdd.yul", "bytecodePath": "contracts/precompiles/artifacts/EcAdd.yul/EcAdd.yul.zbin", "bytecodeHash": "0x010000c56c054a0de4a36b133d3c114ec514c3ce0334ad7759c202392386a913", "sourceCodeHash": "0xe73c8960a8b4060113adca9f03207d379580d172df9f0b499dd5353934a557a6" }, - "ecMul": { + { "contractName": "EcMul", "sourceCodePath": "contracts/precompiles/EcMul.yul", "bytecodePath": "contracts/precompiles/artifacts/EcMul.yul/EcMul.yul.zbin", "bytecodeHash": "0x010001378d31273c8e58caa12bcf1a5694e66a0aefdba2504adb8e3eb02b21c7", "sourceCodeHash": "0x6c4b11542bcf85e6e02ca193fc0548353b1f21c27e972b9e73781e8f7eaf50b0" }, - "ecrecover": { + { "contractName": "Ecrecover", "sourceCodePath": "contracts/precompiles/Ecrecover.yul", "bytecodePath": "contracts/precompiles/artifacts/Ecrecover.yul/Ecrecover.yul.zbin", "bytecodeHash": "0x010000114daca2ff44f27d543b8ef67d885bfed09a74ba9cb25f5912dd3d739c", "sourceCodeHash": "0x18eac0a993afec4112da99fc8e2978891598ab12566528628896f430c855fb81" }, - "keccak256": { + { "contractName": "Keccak256", "sourceCodePath": "contracts/precompiles/Keccak256.yul", "bytecodePath": "contracts/precompiles/artifacts/Keccak256.yul/Keccak256.yul.zbin", "bytecodeHash": "0x0100001fb52ca33668d01c230a1c3b13ede90fe2e37d77222410e9f183cb7a89", "sourceCodeHash": "0x6415e127a4e07907fb87d0cbdf480fff8c70326c4f2f670af0cf3248862e4df4" }, - "sHA256": { + { "contractName": "SHA256", "sourceCodePath": "contracts/precompiles/SHA256.yul", "bytecodePath": "contracts/precompiles/artifacts/SHA256.yul/SHA256.yul.zbin", "bytecodeHash": "0x010000178d93b2d7d6448866009892223caf018a8e8dbcf090c2b9053a285f8d", "sourceCodeHash": "0x8f5a719394836111c850774e89ffb22ef825ff4d24d116ca750888be906f0109" }, - "proved_batch": { + { "contractName": "proved_batch", "sourceCodePath": "bootloader/build/proved_batch.yul", "bytecodePath": "bootloader/build/artifacts/proved_batch.yul/proved_batch.yul.zbin", "bytecodeHash": "0x010009411d9c2342671c57d5ce038ce3e142c750df85ac5d23f67b4e4215fede", "sourceCodeHash": "0xd48e5abbfbb493eacfcbe6dc788eada867d58ab8596d55736b496b1c2e22c636" } -} \ No newline at end of file +] \ No newline at end of file diff --git a/scripts/calculate-hashes.ts b/scripts/calculate-hashes.ts index c335c7b2..5eb2dc2a 100644 --- a/scripts/calculate-hashes.ts +++ b/scripts/calculate-hashes.ts @@ -146,10 +146,6 @@ type Hashes = { type SystemContractHashes = ContractDetails & Hashes; -type SystemContractsHashes = { - [key: string]: SystemContractHashes; -}; - const makePathAbsolute = (path: string): string => { return join(__dirname, "..", path); }; @@ -203,14 +199,10 @@ const getHashes = ( } }; -const withLowercaseFirstLetter = (name: string) => { - return name.charAt(0).toLowerCase() + name.slice(1); -}; - const getSystemContractsHashes = ( systemContractsDetails: ContractDetails[] -): SystemContractsHashes => - systemContractsDetails.reduce((systemContractsHashes, contractDetails) => { +): SystemContractHashes[] => + systemContractsDetails.map((contractDetails) => { const sourceCode = readSourceCode(contractDetails); const bytecode = readBytecode(contractDetails); const hashes = getHashes( @@ -224,17 +216,14 @@ const getSystemContractsHashes = ( ...hashes, }; - const keyName = withLowercaseFirstLetter(contractDetails.contractName); - - return { - ...systemContractsHashes, - [keyName]: systemContractHashes, - }; - }, {}); + return systemContractHashes; + }); const OUTPUT_FILE_PATH = "SystemContractsHashes.json"; -const readSystemContractsHashesFile = (path: string): SystemContractsHashes => { +const readSystemContractsHashesFile = ( + path: string +): SystemContractHashes[] => { const absolutePath = makePathAbsolute(path); try { const file = fs.readFileSync(absolutePath, "utf8"); @@ -248,7 +237,7 @@ const readSystemContractsHashesFile = (path: string): SystemContractsHashes => { const saveSystemContractsHashesFile = ( path: string, - systemContractsHashes: SystemContractsHashes + systemContractsHashes: SystemContractHashes[] ) => { const absolutePath = makePathAbsolute(path); try { @@ -263,21 +252,28 @@ const saveSystemContractsHashesFile = ( }; const findDifferences = ( - newHashes: SystemContractsHashes, - oldHashes: SystemContractsHashes + newHashes: SystemContractHashes[], + oldHashes: SystemContractHashes[] ) => { - const differences = _.xorWith( - Object.entries(newHashes), - Object.entries(oldHashes), - _.isEqual + const differentElements = _.xorWith(newHashes, oldHashes, _.isEqual); + + const differentUniqueElements = _.uniqWith( + differentElements, + (a, b) => a.contractName === b.contractName ); - const differencesUniqueKeys = _.uniq(differences.map(([key]) => key)); + const differencesList = differentUniqueElements.map((diffElem) => { + const newHashesElem = newHashes.find( + (elem) => elem.contractName === diffElem.contractName + ); + + const oldHashesElem = oldHashes.find( + (elem) => elem.contractName === diffElem.contractName + ); - const differencesList = differencesUniqueKeys.map((key) => { const differingFields = _.xorWith( - Object.entries(newHashes[key] || {}), - Object.entries(oldHashes[key] || {}), + Object.entries(newHashesElem || {}), + Object.entries(oldHashesElem || {}), _.isEqual ); @@ -286,10 +282,10 @@ const findDifferences = ( ); return { - key: key, + contract: diffElem.contractName, differingFields: differingFieldsUniqueKeys, - old: oldHashes[key] || {}, - new: newHashes[key] || {}, + old: oldHashesElem || {}, + new: newHashesElem || {}, }; });