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

Compiler error on Sourcify, not with truffle/hardhat #928

Closed
marcocastignoli opened this issue Feb 16, 2023 · 14 comments
Closed

Compiler error on Sourcify, not with truffle/hardhat #928

marcocastignoli opened this issue Feb 16, 2023 · 14 comments
Assignees
Labels
🪲 bug Something isn't working

Comments

@marcocastignoli
Copy link
Member

marcocastignoli commented Feb 16, 2023

  • I git cloned the repo: https://github.com/CryptoBlades/cryptoblades/tree/production
  • installed dependencies
  • compiled the contracts with truffle successfully (I tried also with hardhat, again, success)
  • uploaded all the following files on Sourcify using the UI:
    • node_modules/@openzeppelin/**/*.sol
    • node_modules/abdk-libraries-solidity/**/*.sol
    • contracts/**/*.sol
    • extracted the metadata from build/contracts/BurningManager.json (even if sourcify is capable of extracting it by its own)
  • tried to verify
    • address: 0x4442df5910aded5fbbaf9ad9d6763f9e46e1cdb2
    • chain: Meter mainnet
  • got error:
Compiler error:
 [{"component":"general","formattedMessage":"/mnt/f2df8c49-401c-40e8-8334-f56d10c7cdfa/prj/ef/ext/cryptoblades/contracts/Blacksmith.sol:143:16: DeclarationError: Undeclared identifier.\n        return SafeRandoms(links[LINK_SAFE_RANDOMS]).hasSingleSeedRequest(msg.sender, getSeed(seedId, shieldType));\n               ^---------^\n","message":"Undeclared identifier.","severity":"error","sourceLocation":{"end":5317,"file":"/mnt/f2df8c49-401c-40e8-8334-f56d10c7cdfa/prj/ef/ext/cryptoblades/contracts/Blacksmith.sol","start":5306},"type":"DeclarationError"},{"component":"general","formattedMessage":"/mnt/f2df8c49-401c-40e8-8334-f56d10c7cdfa/prj/ef/ext/cryptoblades/contracts/Blacksmith.sol:150:9: DeclarationError: Undeclared identifier.\n        SafeRandoms(links[LINK_SAFE_RANDOMS]).requestSingleSeed(msg.sender, getSeed(uint(SHIELD_SEED), shieldType));\n        ^---------^\n","message":"Undeclared identifier.","severity":"error","sourceLocation":{"end":5679,"file":"/mnt/f2df8c49-401c-40e8-8334-f56d10c7cdfa/prj/ef/ext/cryptoblades/contracts/Blacksmith.sol","start":5668},"type":"DeclarationError"},{"component":"general","formattedMessage":"/mnt/f2df8c49-401c-40e8-8334-f56d10c7cdfa/prj/ef/ext/cryptoblades/contracts/Blacksmith.sol:159:24: DeclarationError: Undeclared identifier.\n        uint256 seed = SafeRandoms(links[LINK_SAFE_RANDOMS]).popSingleSeed(msg.sender, getSeed(uint(SHIELD_SEED), shieldType), true, false);\n                       ^---------^\n","message":"Undeclared identifier.","severity":"error","sourceLocation":{"end":6103,"file":"/mnt/f2df8c49-401c-40e8-8334-f56d10c7cdfa/prj/ef/ext/cryptoblades/contracts/Blacksmith.sol","start":6092},"type":"DeclarationError"}]

The error is:

project:/contracts/Blacksmith.sol:159:24: DeclarationError: Undeclared identifier.
        uint256 seed = SafeRandoms(links[LINK_SAFE_RANDOMS]).popSingleSeed(msg.sender, getSeed(uint(SHIELD_SEED), shieldType), true, false);
                       ^---------^

View in Huly HI-358

@marcocastignoli
Copy link
Member Author

I figured out that the --standard-json produced by Sourcify differs from the one of Hardhat and Truffle.

In particular the outputSelection is what causing the error. If I use the hardhat generated one compilation is then successful.

// sourcify generated
"outputSelection": {
      "contracts/BurningManager.sol": {
        "BurningManager": [
          "evm.bytecode.object",
          "evm.deployedBytecode.object",
          "metadata"
        ]
      }
    }
// hardhat generated
"outputSelection": {
      "*": {
        "*": [
          "abi",
          "evm.bytecode",
          "evm.deployedBytecode",
          "evm.methodIdentifiers"
        ],
        "": ["ast"]
      }
    }

@marcocastignoli
Copy link
Member Author

marcocastignoli commented Feb 16, 2023

Sourcify forces the output selection to be outputSelection[fileName][contractName], @kuzdogan are we sure is it right/necessary? Just to experiment I removed the line of code above and verification was successful! (partially successful)

solcJsonInput.settings.outputSelection =
solcJsonInput.settings.outputSelection || {};
solcJsonInput.settings.outputSelection[fileName] =
solcJsonInput.settings.outputSelection[fileName] || {};
solcJsonInput.settings.outputSelection[fileName][contractName] = [
"evm.bytecode.object",
"evm.deployedBytecode.object",
"metadata",
];

@kuzdogan
Copy link
Member

kuzdogan commented Feb 16, 2023

I find it weird to have a different behavior for the ouput. My understanding is we are just telling the compiler to give us specific information out of all things produced by the compiler.

Can you try to narrow down to exactly which option level make the difference? Like what's inside the array [ "abi", "evm.bytecode"...], the level above or the level above?

@kuzdogan kuzdogan added the 🪲 bug Something isn't working label Feb 16, 2023
@marcocastignoli
Copy link
Member Author

I confirm that is about the "*". Tried replacing the outputSelections but nothing changed.

@kuzdogan
Copy link
Member

My last clue would be checking if Sourcify uses solc (not solc.js), try to force Sourcify to use solc.js, and see if it works.

In any case, I recommend saving both standard JSON inputs somewhere as we'll need them for debugging and to report this to Solidity. You can finally see if you can run the solc CLI with those JSONs.

@marcocastignoli
Copy link
Member Author

marcocastignoli commented Feb 16, 2023

You can finally see if you can run the solc CLI with those JSONs.

I'm using the solc CLI directly without passing through Sourcify

Ok I'll check solc.js

@marcocastignoli
Copy link
Member Author

compiling with solc-js (npx solc@0.6.5 --standard-json < standard-sourcify.json) gives the same error, so that's not the error

@marcocastignoli
Copy link
Member Author

Here a gist containing all the files (except the solc compiler)

https://gist.github.com/marcocastignoli/6011093fdab16749fe316597b6289424

@xiaohanzhu
Copy link

sorry, one correction. The deployed contract on Meter was from this branch https://github.com/CryptoBlades/cryptoblades/tree/production-contracts commit hash a7180afc8bfdc74a5450cc1c6362cafd627a0f26 but there is very little/no difference from the branch mentioned earlier for the contract we are verifying

@kuzdogan kuzdogan assigned kuzdogan and unassigned marcocastignoli Feb 20, 2023
@kuzdogan
Copy link
Member

Can you double check the address of the contract to be verified @xiaohanzhu? I see the address stated above is already verified and is a different contract https://scan.meter.io/address/0x4442df5910aded5fbbaf9ad9d6763f9e46e1cdb2

@kuzdogan
Copy link
Member

Taking this issue over @marcocastignoli

This seems to be a compiler issue. Opened an issue in the Solidity repo ethereum/solidity#13985

Let's see what comes out of this but it seems we need to work around this by outputting all files like this always when we compile:

    "outputSelection": {
      "*": {
        "BurningManager": [
          "evm.bytecode.object",
          "evm.deployedBytecode.object",
          "metadata"
        ]
      }
    }

@xiaohanzhu
Copy link

xiaohanzhu commented Feb 20, 2023

Can you double check the address of the contract to be verified @xiaohanzhu? I see the address stated above is already verified and is a different contract https://scan.meter.io/address/0x4442df5910aded5fbbaf9ad9d6763f9e46e1cdb2

Our explorer's automatic matching capability had a bug. Now it is shown as unverified

You could try 0x7740d99a135ca9dac4a00d407765e796151c8f40 as CharacterEarthTraitChangeConsumables The error message has also changed:
Compiler error:
[{"component":"general","formattedMessage":"project:/contracts/Blacksmith.sol:143:16: DeclarationError: Undeclared identifier.\n return SafeRandoms(links[LINK_SAFE_RANDOMS]).hasSingleSeedRequest(msg.sender, getSeed(seedId, shieldType));\n ^---------^\n","message":"Undeclared identifier.","severity":"error","sourceLocation":{"end":5317,"file":"project:/contracts/Blacksmith.sol","start":5306},"type":"DeclarationError"},{"component":"general","formattedMessage":"project:/contracts/Blacksmith.sol:150:9: DeclarationError: Undeclared identifier.\n SafeRandoms(links[LINK_SAFE_RANDOMS]).requestSingleSeed(msg.sender, getSeed(uint(SHIELD_SEED), shieldType));\n ^---------^\n","message":"Undeclared identifier.","severity":"error","sourceLocation":{"end":5679,"file":"project:/contracts/Blacksmith.sol","start":5668},"type":"DeclarationError"},{"component":"general","formattedMessage":"project:/contracts/Blacksmith.sol:159:24: DeclarationError: Undeclared identifier.\n uint256 seed = SafeRandoms(links[LINK_SAFE_RANDOMS]).popSingleSeed(msg.sender, getSeed(uint(SHIELD_SEED), shieldType), true, false);\n ^---------^\n","message":"Undeclared identifier.","severity":"error","sourceLocation":{"end":6103,"file":"project:/contracts/Blacksmith.sol","start":6092},"type":"DeclarationError"}]

@kuzdogan
Copy link
Member

Yes it's the same error. We started stringifying it before returning: 7292970

@kuzdogan
Copy link
Member

Closing this with the workaround mentioned. Will follow the opened Solidity issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🪲 bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants