Calculate bytecodehash in solidity on a ZK Stack based chain #718
-
Module Affected
Rust Version1.80.1 Operating System
Issue DescriptionWhen I Expected BehaviorShould compile without errors. Current BehaviorError (6933)
ParserError: Expected primary expression.
--> lib/era-contracts/system-contracts/contracts/Constants.sol:20:44:
|
20 | uint160 constant SYSTEM_CONTRACTS_OFFSET = {{SYSTEM_CONTRACTS_OFFSET}}; // 2^15```
### Repository Link (if applicable)
_No response_
### Additional Details
It's clear that ` {{SYSTEM_CONTRACTS_OFFSET}}; ` is not going to compile, the git commit adding it mentions preprocessing .
My question is if there is another way of doing the calculation (maybe with an already deployed system contract?), or something else. I also found there's another implementation for `hashL2Bytecode`, but under `l1-contracts`, the `L2ContractHelper.sol`, I assume that is not for this usecase.
### Prior Research
- [X] Yes, I searched for similar issues and did not find any matching ones. |
Beta Was this translation helpful? Give feedback.
Replies: 4 comments 1 reply
-
It seems like you are encountering a preprocessing issue with the Regarding the calculation of the bytecode hash on ZKsync, the process typically involves specific system contracts designed to handle such operations. As you mentioned, there is an implementation under For calculating the bytecode hash directly on ZKsync, you might want to consider the following approaches:
If these options do not resolve your issue, or if you need more specific guidance on interacting with system contracts for bytecode hashing, I recommend checking the ZKsync documentation or reaching out to the ZKsync development team for more detailed support. Your feedback helps us serve you better. If this fully addresses your question, please give it a thumbs up. If it doesn't, please give it a thumbs down. This will inform the community and team so we can improve our support. |
Beta Was this translation helpful? Give feedback.
-
Hi @vmaark, there is an implementation you may be able to use from the You should also just be able to change your own chain contract manually. If that doesn't work for your needs, can you explain in more depth where & how you are trying to use this? |
Beta Was this translation helpful? Give feedback.
-
hey @sarahschwartz, thanks for the reply! I've looked at the package, but realized there's another obstacle for using it - the function is expecting /// @dev calculates the CREATE2 address for a pair without making any external calls
function pairFor(address factory, address tokenA, address tokenB) internal pure returns (address pair) {
(address token0, address token1) = sortTokens(tokenA, tokenB);
pair = address(
uint160(
uint256(
keccak256(
abi.encodePacked(
hex"ff",
factory,
keccak256(abi.encodePacked(token0, token1)),
hex"5ef2d07853620860a5e77bae863f7dc2bd883e28f5e9c837541f791fb45076c7" // init code hash, keccak256(type(UniswapV2Pair).creationCode)
)
)
)
)
);
} I've looked at some zksync forks of uniswap v2, one solution I saw was storing them in a mapping and do a look-up instead of calculating it. Based on the notice in the |
Beta Was this translation helpful? Give feedback.
-
thanks @dutterbutter, I'll look into integrating this |
Beta Was this translation helpful? Give feedback.
@vmaark I would suggest the approach taken here: https://github.com/uniswap-zksync/era-universal-router/blob/v1.2.2-zksync-era/contracts/modules/uniswap/v2/UniswapV2Library.sol or you use the lib itself.