Skip to content

Commit 93cb636

Browse files
authored
Enable Solidity IR Optimizations (#71)
This PR turns on the IR optimization flag when invoking the Solidity compiler for the Safe token lock contracts. There are small gas savings across the board (exception with small gas overhead when withdrawing 0 amounts, which we do not need to optimize for) and moderate code size savings: ### Before ``` ·----------------------------------|---------------------------|------------------|-----------------------------· | Solc version: 0.8.23 · Optimizer enabled: true · Runs: 10000000 · Block limit: 30000000 gas │ ···································|···························|··················|······························ | Methods │ ··················|················|·············|·············|··················|·············|················ | Contract · Method · Min · Max · Avg · # calls · usd (avg) │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · lock · 44146 · 87946 · 74071 · 31 · - │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · recoverERC20 · - · - · 52052 · 1 · - │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · unlock · 52127 · 52151 · 52128 · 78 · - │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · withdraw · 24190 · 82140 · 68218 · 25 · - │ ·-----------------|----------------|-------------|-------------|------------------|-------------|---------------· ``` ``` SafeTokenLock 5089 bytes (limit is 24576) ``` ### After ``` ·----------------------------------|---------------------------|------------------|-----------------------------· | Solc version: 0.8.23 · Optimizer enabled: true · Runs: 10000000 · Block limit: 30000000 gas │ ···································|···························|··················|······························ | Methods │ ··················|················|·············|·············|··················|·············|················ | Contract · Method · Min · Max · Avg · # calls · usd (avg) │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · lock · 43639 · 87439 · 73564 · 31 · - │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · recoverERC20 · - · - · 51886 · 1 · - │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · unlock · 51633 · 51657 · 51634 · 78 · - │ ··················|················|·············|·············|··················|·············|················ | SafeTokenLock · withdraw · 24261 · 81598 · 67836 · 25 · - │ ·-----------------|----------------|-------------|-------------|------------------|-------------|---------------· ``` ``` SafeTokenLock 4536 bytes (limit is 24576) ```
1 parent 2226f29 commit 93cb636

File tree

4 files changed

+27
-55
lines changed

4 files changed

+27
-55
lines changed

hardhat.config.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const soliditySettings = SOLIDITY_SETTINGS
3838
? JSON.parse(SOLIDITY_SETTINGS)
3939
: {
4040
evmVersion: 'paris',
41+
viaIR: true,
4142
optimizer: {
4243
enabled: true,
4344
runs: 10_000_000,

package-lock.json

Lines changed: 9 additions & 38 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
"test": "hardhat test",
1010
"test:e2e": "HARDHAT_FORK=1 hardhat test",
1111
"test:all": "npm run test && npm run test:e2e",
12-
"coverage": "hardhat coverage --network hardhat",
12+
"coverage": "hardhat coverage",
1313
"coverage:check": "istanbul check-coverage ./coverage.json --statements 100 --branches 100 --functions 100 --lines 100",
1414
"deploy-all": "hardhat deploy-contracts --network",
1515
"deploy": "hardhat deploy --network",

test/SafeTokenLock.spec.ts

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -963,22 +963,7 @@ describe('SafeTokenLock', function () {
963963
})
964964

965965
describe('Token Rescue', function () {
966-
it('Should not allow non-owner to recover', async () => {
967-
const { safeTokenLock, alice } = await setupTests()
968-
expect(safeTokenLock.connect(alice).rescueToken(ZeroAddress, ZeroAddress, 0))
969-
.to.be.revertedWithCustomError(safeTokenLock, 'OwnableUnauthorizedAccount')
970-
.withArgs(alice)
971-
})
972-
973-
it('Should not allow Safe token recovery', async () => {
974-
const { safeToken, safeTokenLock, owner } = await setupTests()
975-
expect(safeTokenLock.connect(owner).rescueToken(safeToken, ZeroAddress, 0)).to.be.revertedWithCustomError(
976-
safeTokenLock,
977-
'CannotRecoverSafeToken',
978-
)
979-
})
980-
981-
it('Should allow ERC20 recovery other than Safe token', async () => {
966+
it('Should allow rescuing tokens other other than Safe token', async () => {
982967
const { safeToken, safeTokenLock, owner, alice } = await setupTests()
983968
const erc20 = await (await ethers.getContractFactory('TestERC20')).deploy('TEST', 'TEST')
984969

@@ -1012,6 +997,21 @@ describe('SafeTokenLock', function () {
1012997
await expect(safeTokenLock.connect(owner).rescueToken(erc20ReturnFalseOnFailure, owner, 1)).to.be.reverted
1013998
await expect(safeTokenLock.connect(owner).rescueToken(erc20ReturnNothingOnSuccess, owner, 1)).to.not.be.reverted
1014999
})
1000+
1001+
it('Should not allow rescuing Safe token', async () => {
1002+
const { safeToken, safeTokenLock, owner } = await setupTests()
1003+
expect(safeTokenLock.connect(owner).rescueToken(safeToken, ZeroAddress, 0)).to.be.revertedWithCustomError(
1004+
safeTokenLock,
1005+
'CannotRecoverSafeToken',
1006+
)
1007+
})
1008+
1009+
it('Should not allow rescuing as non-owner', async () => {
1010+
const { safeTokenLock, alice } = await setupTests()
1011+
expect(safeTokenLock.connect(alice).rescueToken(ZeroAddress, ZeroAddress, 0))
1012+
.to.be.revertedWithCustomError(safeTokenLock, 'OwnableUnauthorizedAccount')
1013+
.withArgs(alice)
1014+
})
10151015
})
10161016

10171017
describe('Operations', function () {

0 commit comments

Comments
 (0)