You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
What really puzzled me for a while was that keccak256(abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(tokenL, tokenR))) adds 13.034KiB to the contract size. -> Checked with hardhat-contract-sizer and comment in and out line by line.
The size jump also happens if I only call 'bytes32 creationCode = keccak256(abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(token0, token1)));'
Same goes for bytes memory packed = abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(token1, token0));
I now understand that the culprit is the _PAIR_CREATION_CODE that holds the creation code of the pair contract, which gets injected when used and adds it whole size to the contract. Is there a way to prehash that code and add the parameters later?
I would hate to switch back to a parameter less constructor since there is some logic depending on the parameters that can only be done at construction time and the use of immutable values for the tokens which safes gas all over the contract.
The text was updated successfully, but these errors were encountered:
Is there a way to prehash that code and add the parameters later?
This wouldn't be feasible. Effectively, you want to compute the keccak256 hash of x + y + z but want to avoid or replace x. I don't think that is possible.
would hate to switch back to a parameter less constructor
hm maybe an CREATE3 would be nice where the keccak256(abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(token0, token1))) is calculated like keccak256(abi.encodePacked(keccak256(_PAIR_CREATION_CODE), abi.encode(token0, token1))) well maybe I dig into that kind of stuff and creating an EIP
Too late I see there is already an EIP with CREATE3 that would exactly cover my problem... ethereum/EIPs#3171 unfortunately it's stale
I have a library that helps with calculation of contract addresses created with CREATE2.
What really puzzled me for a while was that
keccak256(abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(tokenL, tokenR)))
adds 13.034KiB to the contract size. -> Checked with hardhat-contract-sizer and comment in and out line by line.The size jump also happens if I only call 'bytes32 creationCode = keccak256(abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(token0, token1)));'
Same goes for
bytes memory packed = abi.encodePacked(_PAIR_CREATION_CODE, abi.encode(token1, token0));
I now understand that the culprit is the _PAIR_CREATION_CODE that holds the creation code of the pair contract, which gets injected when used and adds it whole size to the contract. Is there a way to prehash that code and add the parameters later?
I would hate to switch back to a parameter less constructor since there is some logic depending on the parameters that can only be done at construction time and the use of immutable values for the tokens which safes gas all over the contract.
The text was updated successfully, but these errors were encountered: