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

evmVersion not set in the "metadata" field but set in "rawMetadata" #6707

Closed
2 tasks done
kuzdogan opened this issue Jan 5, 2024 · 1 comment · Fixed by #6708
Closed
2 tasks done

evmVersion not set in the "metadata" field but set in "rawMetadata" #6707

kuzdogan opened this issue Jan 5, 2024 · 1 comment · Fixed by #6708
Labels
T-bug Type: bug

Comments

@kuzdogan
Copy link

kuzdogan commented Jan 5, 2024

Component

Forge

Have you ensured that all of these are up to date?

  • Foundry
  • Foundryup

What version of Foundry are you on?

forge 0.2.0 (6fc7463 2024-01-05T00:17:41.668342000Z)

What command(s) is the bug in?

forge verify-contract

Operating System

macOS (Apple Silicon)

Describe the bug

A Sourcify user encountered a bug while trying to verify their contracts through Foundry.

I noticed the bug does not happen in pre 0.8.20 which led me to thinking it's something about the evmVersion changed to shanghai on that version. Indeed I was able to track down the issue to the missing evmVersion field in the "metadata" field of the contract artifacts whereas evmVersion is present in "rawMetadata".

To reproduce:

Run a Sourcify instance:

mkdir /tmp/temp-repo
docker run -it -p 5555:5555 -e NODE_ENV=debug -v /tmp/temp-repo:/tmp/sourcify/repository ghcr.io/ethereum/sourcify/server:1.4.4

Init project and build

mkdir foundry-evmVersion-bug && cd foundry-evmVersion-bug && forge init
forge build

Verify

forge verify-contract 0xA1aba1b97125881636eAe6F4338dF864d9052F54 src/Counter.sol:Counter --chain-id 11155111 --verifier sourcify --verifier-url http://localhost:5555

This will fail to verify. Now we try to add the correct evmVersion: paris.

At this stage I wasn't able to manually change the evmVersion in the file being sent to Sourcify. If I try to add an evmVersion in out/Counter.sol/Counter.json's metadata.settings it gets removed before being sent to Sourcify. Foundry probably does some validation and removes this field?

Instead I replicate the issue by sending the rawMetadata and metadata contents in requests (stringified).

If you verify the contract in these steps you can remove and re-verify it by rm -r /tmp/temp-repo/contracts/

Failing with "metadata" contents:

curl --location 'http://localhost:5555/verify' \
--header 'Content-Type: application/json' \
--data '{
    "address": "0xA1aba1b97125881636eAe6F4338dF864d9052F54",
    "chainId": "11155111",
    "files": {
        "metadata.json": "{\"compiler\":{\`"version\":\"0.8.23+commit.f704f362\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\",\"name\":\"increment\"},{\"inputs\":[],\"stateMutability\":\"view\",\"type\":\"function\",\"name\":\"number\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}]},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"newNumber\",\"type\":\"uint256\"}],\"stateMutability\":\"nonpayable\",\"type\":\"function\",\"name\":\"setNumber\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"remappings\":[\"ds-test/=lib/forge-std/lib/ds-test/src/\",\"forge-std/=lib/forge-std/src/\"],\"optimizer\":{\"enabled\":true,\"runs\":200},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"compilationTarget\":{\"src/Counter.sol\":\"Counter\"},\"libraries\":{}},\"sources\":{\"src/Counter.sol\":{\"keccak256\":\"0x09277f949d59a9521708c870dc39c2c434ad8f86a5472efda6a732ef728c0053\",\"urls\":[\"bzz-raw://94cd5258357da018bf911aeda60ed9f5b130dce27445669ee200313cd3389200\",\"dweb:/ipfs/QmNbEfWAqXCtfQpk6u7TpGa8sTHXFLpUz7uebz2FVbchSC\"],\"license\":\"UNLICENSED\"}},\"version\":1}",
        "src/Counter.sol": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\n\ncontract Counter {\n    uint256 public number;\n\n    function setNumber(uint256 newNumber) public {\n        number = newNumber;\n    }\n\n    function increment() public {\n        number++;\n    }\n}\n"
    }
}'

Success with "rawMetadata" contents:

curl --location 'http://localhost:5555/verify' \
--header 'Content-Type: application/json' \
--data '{
    "address": "0xA1aba1b97125881636eAe6F4338dF864d9052F54",
    "chainId": "11155111",
    "files": {
        "metadata.json": "{\"compiler\":{\"version\":\"0.8.23+commit.f704f362\"},\"language\":\"Solidity\",\"output\":{\"abi\":[{\"inputs\":[],\"name\":\"increment\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"},{\"inputs\":[],\"name\":\"number\",\"outputs\":[{\"internalType\":\"uint256\",\"name\":\"\",\"type\":\"uint256\"}],\"stateMutability\":\"view\",\"type\":\"function\"},{\"inputs\":[{\"internalType\":\"uint256\",\"name\":\"newNumber\",\"type\":\"uint256\"}],\"name\":\"setNumber\",\"outputs\":[],\"stateMutability\":\"nonpayable\",\"type\":\"function\"}],\"devdoc\":{\"kind\":\"dev\",\"methods\":{},\"version\":1},\"userdoc\":{\"kind\":\"user\",\"methods\":{},\"version\":1}},\"settings\":{\"compilationTarget\":{\"src/Counter.sol\":\"Counter\"},\"evmVersion\":\"paris\",\"libraries\":{},\"metadata\":{\"bytecodeHash\":\"ipfs\"},\"optimizer\":{\"enabled\":true,\"runs\":200},\"remappings\":[\":ds-test/=lib/forge-std/lib/ds-test/src/\",\":forge-std/=lib/forge-std/src/\"]},\"sources\":{\"src/Counter.sol\":{\"keccak256\":\"0x09277f949d59a9521708c870dc39c2c434ad8f86a5472efda6a732ef728c0053\",\"license\":\"UNLICENSED\",\"urls\":[\"bzz-raw://94cd5258357da018bf911aeda60ed9f5b130dce27445669ee200313cd3389200\",\"dweb:/ipfs/QmNbEfWAqXCtfQpk6u7TpGa8sTHXFLpUz7uebz2FVbchSC\"]}},\"version\":1}",
        "src/Counter.sol": "// SPDX-License-Identifier: UNLICENSED\npragma solidity ^0.8.13;\n\ncontract Counter {\n    uint256 public number;\n\n    function setNumber(uint256 newNumber) public {\n        number = newNumber;\n    }\n\n    function increment() public {\n        number++;\n    }\n}\n"
    }
}'

Here you can either add \"evmVersion\":\"paris\" to "metadata" request above or remove the same field from the \"rawMetadata"\ request below.

Notes

  • I see that Foundry does some validation as I tried to modify fields in "metadata" and if I add an invalid field, like "random": "blabla" or change a valid one "remappinadasdsas" this gets removed. I guess the same thing's happening to the evmVersion.
  • Any reason why you are sending the "metadata" instead of the "rawMetadata"? Because it looks like the "rawMetadata" is the actual output by the compiler. I can understand it because the keys are canonicalized by alphabetically sorting, as the compiler always does, but the "metadata" field looks a bit random in the ordering.
  • Could it be related to "EvmError: NotActivated" when trying to use a deployed contract compiled with Shanghai but with evm_version set to Paris for scripts #6228 ?
@mattsse
Copy link
Member

mattsse commented Jan 5, 2024

thanks for flagging, this was indeed introduced in 0.8.20 https://docs.soliditylang.org/en/v0.8.20/metadata.html

will upstream once foundry-rs/compilers#41 is merged

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-bug Type: bug
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

2 participants