Skip to content

Commit 600b01b

Browse files
maureliansmartcontracts
authored andcommitted
test(contracts): Add logs to calculate gas savings
The cost of running benchmarks was determined by running them on the contracts at regenesis/0.4.0 (98e02cf/ PR #1148), then applied to the benchmarks here to calculate both absolute and relative amounts saed
1 parent e12709e commit 600b01b

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

packages/contracts/test/contracts/L1/messaging/deposit.gas.spec.ts

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,18 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
143143
)
144144

145145
const receipt = await res.wait()
146-
console.log(' - Gas used:', receipt.gasUsed.toNumber())
146+
const gasUsed = receipt.gasUsed.toNumber()
147+
const regenesis040Cost = 196_128
148+
console.log(' - Gas used:', gasUsed)
149+
console.log(
150+
' - Absolute savings vs regenesis/0.4.0:',
151+
regenesis040Cost - gasUsed
152+
)
153+
console.log(
154+
' - Relative savings vs regenesis/0.4.0:',
155+
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
156+
'%'
157+
)
147158
// Sanity check that the message was enqueued.
148159
expect(await CanonicalTransactionChain.getQueueLength()).to.equal(2)
149160
})
@@ -163,7 +174,19 @@ describe('[GAS BENCHMARK] Depositing via the standard bridge', () => {
163174
)
164175

165176
const receipt = await res.wait()
166-
console.log(' - Gas used:', receipt.gasUsed.toNumber())
177+
const gasUsed = receipt.gasUsed.toNumber()
178+
const regenesis040Cost = 244_358
179+
console.log(' - Gas used:', gasUsed)
180+
console.log(
181+
' - Absolute savings vs regenesis/0.4.0:',
182+
regenesis040Cost - gasUsed
183+
)
184+
console.log(
185+
' - Relative savings vs regenesis/0.4.0:',
186+
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
187+
'%'
188+
)
189+
167190
// Sanity check that the message was enqueued.
168191
expect(await CanonicalTransactionChain.getQueueLength()).to.equal(3)
169192
})

packages/contracts/test/contracts/L1/rollup/CanonicalTransactionChain.gas.spec.ts

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,19 @@ const appendSequencerBatch = async (
4141
})
4242
}
4343

44+
const printGasSavings = (gasUsed:number, regenesis040Cost:number):void => {
45+
console.log(' - Gas used:', gasUsed)
46+
console.log(
47+
' - Absolute savings vs regenesis/0.4.0:',
48+
regenesis040Cost - gasUsed
49+
)
50+
console.log(
51+
' - Relative savings vs regenesis/0.4.0:',
52+
(((regenesis040Cost - gasUsed) / regenesis040Cost) * 100).toFixed(2) +
53+
'%'
54+
)
55+
}
56+
4457
describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
4558
let sequencer: Signer
4659
before(async () => {
@@ -151,7 +164,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
151164
const gasUsed = receipt.gasUsed.toNumber()
152165

153166
console.log('Benchmark complete.')
154-
console.log('Gas used:', gasUsed)
167+
printGasSavings(gasUsed, 1_616_390)
155168

156169
console.log('Fixed calldata cost:', fixedCalldataCost)
157170
console.log(
@@ -199,7 +212,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
199212
const gasUsed = receipt.gasUsed.toNumber()
200213

201214
console.log('Benchmark complete.')
202-
console.log('Gas used:', gasUsed)
215+
printGasSavings(gasUsed, 1_787_052)
203216

204217
console.log('Fixed calldata cost:', fixedCalldataCost)
205218
console.log(
@@ -257,7 +270,7 @@ describe('[GAS BENCHMARK] CanonicalTransactionChain', () => {
257270
const gasUsed = receipt.gasUsed.toNumber()
258271

259272
console.log('Benchmark complete.')
260-
console.log('Gas used:', gasUsed)
273+
printGasSavings(gasUsed, 2_099_387)
261274

262275
console.log('Fixed calldata cost:', fixedCalldataCost)
263276
console.log(

0 commit comments

Comments
 (0)