Skip to content

Commit

Permalink
feat: fix proxy contract compiler settings (#118) (#121)
Browse files Browse the repository at this point in the history
* feat: fix proxy contract compiler settings

* fix slither

* slither ignore
  • Loading branch information
milapsheth authored Dec 14, 2023
1 parent e70afc5 commit c8fe9ca
Show file tree
Hide file tree
Showing 5 changed files with 86 additions and 27 deletions.
13 changes: 12 additions & 1 deletion .github/workflows/slither.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
57 changes: 34 additions & 23 deletions hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
},
Expand Down
2 changes: 1 addition & 1 deletion slither.config.json
Original file line number Diff line number Diff line change
@@ -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/)"
}
22 changes: 21 additions & 1 deletion test/governance/AxelarServiceGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});
});
19 changes: 18 additions & 1 deletion test/governance/InterchainGovernance.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -12,6 +12,7 @@ const {
waitFor,
getPayloadAndProposalHash,
getGasOptions,
getEVMVersion,
} = require('../utils');

describe('InterchainGovernance', () => {
Expand Down Expand Up @@ -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);
});
});

0 comments on commit c8fe9ca

Please sign in to comment.