From 5db4cd606be239e190193253352689f8a4428b2f Mon Sep 17 00:00:00 2001 From: Milap Sheth Date: Tue, 12 Dec 2023 17:59:29 -0500 Subject: [PATCH] feat: fix proxy contract compiler settings (#118) * feat: fix proxy contract compiler settings * fix slither * slither ignore --- .github/workflows/slither.yml | 13 ++++- hardhat.config.js | 57 +++++++++++++--------- slither.config.json | 2 +- test/governance/AxelarServiceGovernance.js | 22 ++++++++- test/governance/InterchainGovernance.js | 19 +++++++- 5 files changed, 86 insertions(+), 27 deletions(-) diff --git a/.github/workflows/slither.yml b/.github/workflows/slither.yml index ce618da6..6c424fba 100644 --- a/.github/workflows/slither.yml +++ b/.github/workflows/slither.yml @@ -5,10 +5,21 @@ on: jobs: analyze: - runs-on: ubuntu-latest + strategy: + matrix: + node-version: + - 18.x + os: + - ubuntu-latest + runs-on: ${{ matrix.os }} steps: - uses: actions/checkout@v4 + - name: Install Node.js + uses: actions/setup-node@v3 + with: + node-version: ${{ matrix.node-version }} + - name: Install Dependencies run: npm ci diff --git a/hardhat.config.js b/hardhat.config.js index 4e922cd2..b2e01c53 100644 --- a/hardhat.config.js +++ b/hardhat.config.js @@ -10,39 +10,50 @@ const chains = require(`@axelar-network/axelar-chains-config/info/${env}.json`); const keys = readJSON(`${__dirname}/keys.json`); const { networks, etherscan } = importNetworks(chains, keys); +const optimizerSettings = { + enabled: true, + runs: 1000000, + details: { + peephole: process.env.COVERAGE === undefined, + inliner: process.env.COVERAGE === undefined, + jumpdestRemover: true, + orderLiterals: true, + deduplicate: true, + cse: process.env.COVERAGE === undefined, + constantOptimizer: true, + yul: true, + yulDetails: { + stackAllocation: true, + }, + }, +}; +const compilerSettings = { + version: '0.8.19', + settings: { + evmVersion: process.env.EVM_VERSION || 'london', + optimizer: optimizerSettings, + }, +}; + /** * @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: { - version: '0.8.19', - settings: { - evmVersion: process.env.EVM_VERSION || 'london', - optimizer: { - enabled: true, - runs: 1000000, - details: { - peephole: process.env.COVERAGE === undefined, - inliner: process.env.COVERAGE === undefined, - jumpdestRemover: true, - orderLiterals: true, - deduplicate: true, - cse: process.env.COVERAGE === undefined, - constantOptimizer: true, - yul: true, - yulDetails: { - stackAllocation: true, - }, - }, - }, + compilers: [compilerSettings], + // Fix the Proxy bytecodes + overrides: { + 'contracts/deploy/Create2Deployer.sol': compilerSettings, + 'contracts/deploy/Create3Deployer.sol': compilerSettings, + 'contracts/upgradable/Proxy.sol': compilerSettings, + 'contracts/upgradable/InitProxy.sol': compilerSettings, + 'contracts/upgradable/FinalProxy.sol': compilerSettings, + 'contracts/upgradable/FixedProxy.sol': compilerSettings, }, }, defaultNetwork: 'hardhat', networks, etherscan, - paths: { - sources: './contracts', - }, mocha: { timeout: 4 * 60 * 60 * 1000, // 4 hrs }, diff --git a/slither.config.json b/slither.config.json index aaee1af2..a133237e 100644 --- a/slither.config.json +++ b/slither.config.json @@ -1,4 +1,4 @@ { "detectors_to_exclude": "assembly,low-level-calls,solc-version,missing-zero-check,timestamp", - "filter_paths": "(contracts/test/|node_modules/)" + "filter_paths": "(contracts/test/|contracts/libs/SafeNativeTransfer.sol|node_modules/)" } diff --git a/test/governance/AxelarServiceGovernance.js b/test/governance/AxelarServiceGovernance.js index bcbebd26..aa02d431 100644 --- a/test/governance/AxelarServiceGovernance.js +++ b/test/governance/AxelarServiceGovernance.js @@ -8,7 +8,11 @@ const { Wallet, } = ethers; const { expect } = chai; -const { isHardhat, getPayloadAndProposalHash } = require('../utils'); +const { + isHardhat, + getPayloadAndProposalHash, + getEVMVersion, +} = require('../utils'); describe('AxelarServiceGovernance', () => { let ownerWallet; @@ -540,4 +544,20 @@ describe('AxelarServiceGovernance', () => { const newBalance = await ethers.provider.getBalance(target); expect(newBalance).to.equal(oldBalance.add(nativeValue)); }); + + it('should preserve the bytecode [ @skip-on-coverage ]', async () => { + const bytecode = serviceGovernanceFactory.bytecode; + const bytecodeHash = keccak256(bytecode); + + const expected = { + istanbul: + '0x319301da0b03f0811bc506a7c251a4a8277de0959a64485ee834b4e33c6be302', + berlin: + '0x9528162b0e350e8bc3d181949c8b91e41750a7e8740b4b3d69edb49ff1e7e2b1', + london: + '0xb763a5922bb74458426c83bea5205fd371418c220d896f9f1e500841c6134904', + }[getEVMVersion()]; + + expect(bytecodeHash).to.be.equal(expected); + }); }); diff --git a/test/governance/InterchainGovernance.js b/test/governance/InterchainGovernance.js index 76f05b03..ea7e7a18 100644 --- a/test/governance/InterchainGovernance.js +++ b/test/governance/InterchainGovernance.js @@ -3,7 +3,7 @@ const chai = require('chai'); const { ethers } = require('hardhat'); const { - utils: { defaultAbiCoder, Interface }, + utils: { defaultAbiCoder, Interface, keccak256 }, constants: { AddressZero, HashZero }, } = ethers; const { expect } = chai; @@ -12,6 +12,7 @@ const { waitFor, getPayloadAndProposalHash, getGasOptions, + getEVMVersion, } = require('../utils'); describe('InterchainGovernance', () => { @@ -599,4 +600,20 @@ describe('InterchainGovernance', () => { .and.to.emit(targetContract, 'TargetCalled'); }); }); + + it('should preserve the bytecode [ @skip-on-coverage ]', async () => { + const bytecode = interchainGovernanceFactory.bytecode; + const bytecodeHash = keccak256(bytecode); + + const expected = { + istanbul: + '0x2534d1533c9ffce84d3174c1f846a4041d07b56d1e7b5cb7138e06fb42086325', + berlin: + '0x1084d7de843267ed6f4ad87cbdc541bfb2aa003c67c285d0b4f90b3026370f7e', + london: + '0x9d89dce5b3087d6f9a1b80cc3e96ae9c204a1ce3c2c4eb5bce7671a20a635f97', + }[getEVMVersion()]; + + expect(bytecodeHash).to.be.equal(expected); + }); });