-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Hash & gather factory deps to snapshot (#42)
Factory deps (smart contracts in zkSync) are stored separately in snapshots, but they must be gathered together with storage log entries when fetching the state from L1. This change will do preliminary work required for writing out the separate factory dep snapshot file.
- Loading branch information
Showing
4 changed files
with
107 additions
and
31 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
use ethers::types::H256; | ||
|
||
// These are copied from zkSync-era project to avoid pulling in full dependency. | ||
pub fn bytes_to_chunks(bytes: &[u8]) -> Vec<[u8; 32]> { | ||
assert!( | ||
bytes.len() % 32 == 0, | ||
"Bytes must be divisible by 32 to split into chunks" | ||
); | ||
|
||
bytes | ||
.chunks(32) | ||
.map(|el| { | ||
let mut chunk = [0u8; 32]; | ||
chunk.copy_from_slice(el); | ||
chunk | ||
}) | ||
.collect() | ||
} | ||
|
||
pub fn hash_bytecode(code: &[u8]) -> H256 { | ||
let chunked_code = bytes_to_chunks(code); | ||
let hash = | ||
zkevm_opcode_defs::utils::bytecode_to_code_hash(&chunked_code).expect("Invalid bytecode"); | ||
|
||
H256(hash) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters