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

Verify smart contracts #10730

Merged
merged 6 commits into from
Nov 20, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions packages/protocol/.env.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"celoScanApiKey": "[Celo scan api]"
}
32 changes: 32 additions & 0 deletions packages/protocol/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,36 @@ Compared to the normal test command, quicktest will:
1. Not run the pretest script of building solidity (will still be run as part of truffle test) and compiling typescript. This works because truffle can run typescript "natively".
2. Only migrate selected migrations as set in `backupmigrations.sh` (you'll likely need at least one compilation step since truffle seems to only run compiled migrations)

## Verify released smart contracts
1. Update CeloScanApi in env.json file
2. Run verification command

```bash
yarn truffle-verify [ContractName]@[Contract address] --network [network] --forno [network rpc url]
```

example:
```bash
yarn truffle-verify MentoFeeHandlerSeller@0x4efa274b7e33476c961065000d58ee09f7921a74 --network mainnet --forno https://forno.celo.org
```

### Possible problems
1. Some of old smart contracts have slightly different bytecode when verified (it is usually just few bytes difference). Some of the smart contracts were originally deployed with version 0.5.8 instead of 0.5.13 even though there is no history trace about this in our monorepo.
2. Bytecode differs because of missing library addresses on CeloScan. Json file that will be manually uploaded to CeloScan needs to have libraries root element updated. Library addresses is possible to get either manually or with command which will generate libraries.json.
```bash
yarn verify-deployed -n $NETWORK -b $PREVIOUS_RELEASE -f
```

```javascript
{
"libraries": {
"/contracts/governance/Governance.sol": {
"Proposals": "0x38afc0dc55415ae27b81c24b5a5fbfe433ebfba8",
"IntegerSortedLinkedList": "0x411b40a81a07fcd3542ce5b3d7e215178c4ca2ef",
"AddressLinkedList": "0xd26d896d258e258eba71ff0873a878ec36538f8d",
"Signatures": "0x69baecd458e7c08b13a18e11887dbb078fb3cbb4",
"AddressSortedLinkedList": "0x4819ad0a0eb1304b1d7bc3afd7818017b52a87ab"
}
}
}
```
6 changes: 4 additions & 2 deletions packages/protocol/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,8 @@
"devchain": "ts-node scripts/devchain.ts",
"devchain:reset": "yarn devchain generate-tar .tmp/devchain.tar.gz --upto 28",
"view-tags": "git for-each-ref 'refs/tags/core-contracts.*' --sort=-committerdate --format='%(color:magenta)%(committerdate:short) %(color:blue)%(tree) %(color:green)github.com/celo-org/celo-monorepo/releases/tag/%(color:yellow)%(refname:short)'",
"generate-stabletoken-files": "ts-node ./scripts/generate-stabletoken-files.ts"
"generate-stabletoken-files": "ts-node ./scripts/generate-stabletoken-files.ts",
"truffle-verify": "yarn truffle run verify"
},
"dependencies": {
"@0x/sol-compiler": "^4.8.3",
Expand Down Expand Up @@ -98,7 +99,8 @@
"web3-core": "1.10.0",
"web3-core-helpers": "1.10.0",
"web3-provider-engine": "^16.0.5",
"web3-utils": "1.10.0"
"web3-utils": "1.10.0",
"truffle-plugin-verify": "^0.6.5"
},
"devDependencies": {
"@celo/phone-utils": "^5.0.5",
Expand Down
11 changes: 9 additions & 2 deletions packages/protocol/truffle-config.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ const SOLC_VERSION = '0.5.13'

const parent = require('./truffle-config-parent.js')
const networks = { ...parent.networks }
const { celoScanApiKey } = require('./.env.json')

console.log(`Using truffle version for Solidity ${SOLC_VERSION}`)

module.exports = {
plugins: ['truffle-security', 'truffle-plugin-blockscout-verify'],
plugins: ['truffle-plugin-verify'],
api_keys: {
celoscan: celoScanApiKey,
},
compilers: {
solc: {
version: SOLC_VERSION,
Expand All @@ -30,7 +34,10 @@ if (process.argv.includes('--gas')) {
},
},
},
plugins: ['truffle-security', 'truffle-plugin-blockscout-verify'],
plugins: ['truffle-plugin-verify'],
api_keys: {
celoscan: celoScanApiKey,
},
networks,
reporter: 'eth-gas-reporter',
reporterOptions: {
Expand Down
11 changes: 9 additions & 2 deletions packages/protocol/truffle-config0.8.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,15 @@ const SOLC_VERSION = '0.8.19'

const parent = require('./truffle-config-parent.js')
const networks = { ...parent.networks }
const { celoScanApiKey } = require('./.env.json')

console.log(`Using truffle version for Solidity ${SOLC_VERSION}`)

module.exports = {
plugins: ['truffle-security', 'truffle-plugin-blockscout-verify'],
plugins: ['truffle-plugin-verify'],
api_keys: {
celoscan: celoScanApiKey,
},
compilers: {
solc: {
version: SOLC_VERSION,
Expand All @@ -28,7 +32,10 @@ if (process.argv.includes('--gas')) {
},
},
},
plugins: ['truffle-security', 'truffle-plugin-blockscout-verify'],
plugins: ['truffle-plugin-verify'],
api_keys: {
celoscan: celoScanApiKey,
},
networks,
reporter: 'eth-gas-reporter',
reporterOptions: {
Expand Down
Loading