Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mask Immutables in Local Verify Task #691

Merged
merged 1 commit into from
Nov 1, 2023
Merged

Mask Immutables in Local Verify Task #691

merged 1 commit into from
Nov 1, 2023

Conversation

nlordell
Copy link
Collaborator

Fixes #689

The local verification task does not work correctly for contracts with immutables. This is because, immutable values get written when the contract's init code executes on-chain, but uses 0 place holders in the deployedBytecode compiler output.

This causes the code that is fetched from the deployed contract to differ slightly from the compiler's byte code output (fetched code has non-0 immutable values, while the compiler output has 0 immutable values).

The fix is to mask the immutables from the fetched code with 0's before comparing.

With this fix, local-verify script now works for the SimulateTxAccessor contract:

$ npx hardhat local-verify --network localhost
Verification status for CompatibilityFallbackHandler: SUCCESS
Verification status for CreateCall: SUCCESS
Verification status for MultiSend: SUCCESS
Verification status for MultiSendCallOnly: SUCCESS
Verification status for Safe: SUCCESS
Verification status for SafeL2: SUCCESS
Verification status for SafeProxyFactory: SUCCESS
Verification status for SignMessageLib: SUCCESS
Verification status for SimulateTxAccessor: SUCCESS
Verification status for TokenCallbackHandler: SUCCESS

@nlordell nlordell requested review from a team, rmeissner, akshay-ap and mmv08 and removed request for a team October 31, 2023 09:11
@github-actions
Copy link

github-actions bot commented Oct 31, 2023

CLA Assistant Lite bot All contributors have signed the CLA ✍️ ✅

@nlordell
Copy link
Collaborator Author

I have read the CLA Document and I hereby sign the CLA

github-actions bot added a commit that referenced this pull request Oct 31, 2023
@nlordell
Copy link
Collaborator Author

I looked into it, and the constructor arguments are not included in the Hardhat deployment data.

@mmv08
Copy link
Member

mmv08 commented Oct 31, 2023

I looked into it, and the constructor arguments are not included in the Hardhat deployment data.

We don't have any arguments, do we? There is an "args" field in the artifacts with an empty array.

@nlordell
Copy link
Collaborator Author

Also I found this: https://ethereum.stackexchange.com/questions/94396/how-to-get-the-actual-runtime-bytecode-from-creation-bytecode-and-constructor-ar

You can also do an eth_call to do the comparison. For example, the following command will show no diff:

diff -u --color \
    <(cat deployments/localhost/SafeProxyFactory.json | jq '.deployedBytecode') \
    <(curl -s "$NODE_URL" -X POST -H 'content-type: application/json' --data "{\"jsonrpc\":\"2.0\",\"method\":\"eth_call\",\"id\":0,\"params\":[{\"data\":$(cat deployments/localhost/SafeProxyFactory.json | jq '.bytecode')}]}" | jq '.result')

@nlordell
Copy link
Collaborator Author

We don't have any arguments, do we?

🤦 - correct. For some reason I assumed that the ACCESSOR_SINGLETON immutable was set from a constructor argument, but it is just read from the transaction context. The difficulty here is that the value for this that is used to set the immutable value is not easy to fudge.

@mmv08
Copy link
Member

mmv08 commented Nov 1, 2023

We don't have any arguments, do we?

🤦 - correct. For some reason I assumed that the ACCESSOR_SINGLETON immutable was set from a constructor argument, but it is just read from the transaction context. The difficulty here is that the value for this that is used to set the immutable value is not easy to fudge.

Then I'd say it's good as is

@@ -11,24 +11,31 @@ task("local-verify", "Verifies that the local deployment files correspond to the
delete meta.compiler;
delete meta.output;
delete meta.version;
const sources = Object.values<any>(meta.sources);
const sources = Object.values<Record<string, unknown>>(meta.sources);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

huge props for fixing types 💪

@nlordell nlordell merged commit fd05d21 into main Nov 1, 2023
18 checks passed
@github-actions github-actions bot locked and limited conversation to collaborators Nov 1, 2023
@nlordell nlordell deleted the fix-local-verify branch April 16, 2024 12:36
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LocalVerify Failures
2 participants