Content pfp
Content
@
0 reply
0 recast
0 reaction

Pierre H. — q/dau pfp
Pierre H. — q/dau
@rektorship
https://github.com/zkSync-Community-Hub/zksync-developers/discussions/639#discussioncomment-10693912 why are zksync builds non-deterministic (both foundry and hardhat)? why does updating the smart account change the proxy bytecode? and why is there only one proxy bytecode that works for my account factory? @bountybot pays 100 USD to the person who can answer *all* these questions.
9 replies
1 recast
4 reactions

gatedude.eth pfp
gatedude.eth
@gatedude
Hey fam, I visited the repo and read the conversation. A contributor actually suggested using ---no-optimization flag with Hardhat to reduce variability. Another also suggested you exploring @openzeppelin/contracts for deterministic builds. Here's my take on the question you asked: First, you need to understand that zkSync's build process involves generating random numbers (salts) for cryptographic purposes. Also these random numbers affect the compiled contract bytecode. But Foundry and Hardhat generate different random values, leading to non-deterministic builds. Also, the reason why updating the contract actually changes the proxy bytecode is because zkSync's smart accounts actually uses a proxy contract to manage account upgrades. When you update the smart contract, the proxy contract bytecode changes due to the "New account Logic" and the "Updated account-specefic data" like the public key for example.
2 replies
0 recast
1 reaction

Pierre H. — q/dau pfp
Pierre H. — q/dau
@rektorship
Thanks, @gatedude, for your answers! How can the proxy bytecode be generated from the account factory configuration? It seems pretty isolated to me (c.f screen) Here's the deploy factory Hardhat task: https://github.com/openfort-xyz/openfort-zksync-contracts/blob/b89d4a262fd90522c00cd947c737828fa7ac95ff/tasks/deployFactory.ts#L32 I'll pay the bounty If you can make it work without hardcoding the proxy bytecode. You might ask how I got this bytecode in the first place. Well, `proxyArtifact.bytecode` used to work well in the factory deployment script. I shipped the first version of our accounts using that setup. Then, I started working on adding transaction batch support and noticed that the factory was deploying accounts with no associated bytecode. Even a single-byte update in `BaseOpenfortAccount.sol` produces a different proxy bytecode. I definitely need to dive deeper into the cryptographic purposes behind this. Thanks for pointing me in that direction.
1 reply
0 recast
1 reaction

gatedude.eth pfp
gatedude.eth
@gatedude
Hey fam, Here's how to make it work without hardcoding the bytecode: First, try and Compute Creation Code by Compiling `UpgradeableOpenfortProxy.sol` with the Solidity compiler (`solc`)., then you should extract the creation code from the compiled bytecode. Here's a simple Creation Code Formula: `creationCode = bytecode - initializationCode` where: - `bytecode` is the compiled bytecode. - `initializationCode` is the constructor code. Here's the Solidity Compiler Command: ``` bash solc --bin --abi UpgradeableOpenfortProxy.sol ``` Then Extract Creation Code: I'II recommended you try Using a tool like `solc` or a scripting language (e.g., Node.js) to extract the creation code.
1 reply
0 recast
1 reaction

gatedude.eth pfp
gatedude.eth
@gatedude
Here's a Node.js Example you should try: ``` const fs = require('fs'); const solc = require('solc'); // Load compiled bytecode const bytecode = fs.readFileSync('UpgradeableOpenfortProxy.bin', 'utf8'); // Extract creation code const initializationCodeLength = 32; // Constructor code length const creationCode = bytecode.slice(0, bytecode.length - initializationCodeLength); console.log(creationCode); ``` Also, Integrate with Factory by Computing the creation code dynamically, then Use the creation code to deploy proxy contracts. Since the Cryptographic Background EIP-1014: CREATE2 opcode enables predictable contract addresses. Keccak-256 is the Hash function used for bytecode hash computation. Also, you should Implement the creation code computation and Test the dynamic proxy bytecode generation.
0 reply
0 recast
0 reaction