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
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".
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.
Component
Forge
Have you ensured that all of these are up to date?
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 theevmVersion
changed toshanghai
on that version. Indeed I was able to track down the issue to the missingevmVersion
field in the"metadata"
field of the contract artifacts whereasevmVersion
is present in"rawMetadata"
.To reproduce:
Run a Sourcify instance:
Init project and build
Verify
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 anevmVersion
inout/Counter.sol/Counter.json
'smetadata.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
andmetadata
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:Success with
"rawMetadata"
contents:Here you can either add
\"evmVersion\":\"paris\"
to"metadata"
request above or remove the same field from the\"rawMetadata"\
request below.Notes
"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 theevmVersion
."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.The text was updated successfully, but these errors were encountered: