Skip to content

Commit

Permalink
Add estimateCCIPReadCallbackGas
Browse files Browse the repository at this point in the history
  ScrollVerifier
Gas estimate 2418085
    ✔ simple proofs for fixed values (2652ms)
Gas estimate 2419066
    ✔ simple proofs for dynamic values (1641ms)
Gas estimate 2282506
    ✔ nested proofs for dynamic values (1800ms)
Gas estimate 4773362
    ✔ nested proofs for long dynamic values (1960ms)
Gas estimate 3607123
    ✔ nested proofs with lookbehind (2488ms)
Gas estimate 3527831
    ✔ nested proofs with lookbehind for dynamic values (1810ms)
Gas estimate 2353134
    ✔ mappings with variable-length keys (1721ms)
Gas estimate 3608890
    ✔ nested proofs of mappings with variable-length keys (2086ms)
Gas estimate 2223797
    ✔ treats uninitialized storage elements as zeroes (1534ms)
Gas estimate 2228241
    ✔ treats uninitialized dynamic values as empty strings (1800ms)
  • Loading branch information
makoto committed May 6, 2024
1 parent 372ec98 commit e423972
Showing 1 changed file with 51 additions and 0 deletions.
51 changes: 51 additions & 0 deletions scroll-verifier/test/testScrollVerifier.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ import { HardhatEthersProvider } from '@nomicfoundation/hardhat-ethers/internal/
import type { HardhatEthersHelpers } from '@nomicfoundation/hardhat-ethers/types';
import { expect } from 'chai';
import {
AbiCoder,
concat,
Contract,
FetchRequest,
Provider,
Expand All @@ -14,6 +16,23 @@ import express from 'express';
import hre, { ethers } from 'hardhat';
import { EthereumProvider } from 'hardhat/types';
import request from 'supertest';
const estimateCCIPReadCallbackGas = async (provider, cb) => {
try{
await cb()
}catch(e){
const [sender, urls, data, callbackFunction, extraData ] = e.revert.args
const url = `http://localhost:8080/${sender}/${data}.json`
const responseData:any = await (await fetch(url)).json()
const encoder = new AbiCoder()
const encoded = encoder.encode([ "bytes", "bytes" ], [responseData.data, extraData]);
const newdata = concat([ callbackFunction, encoded ])
const result2 = await provider.estimateGas({
to: sender,
data:newdata
});
console.log(`Gas estimate ${result2}`)
}
}

type ethersObj = typeof ethersT &
Omit<HardhatEthersHelpers, 'provider'> & {
Expand Down Expand Up @@ -94,54 +113,86 @@ describe('ScrollVerifier', () => {
it('simple proofs for fixed values', async () => {
const result = await target.getLatest({ enableCcipRead: true });
expect(Number(result)).to.equal(42);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getLatest({ enableCcipRead: false });
})
});

it('simple proofs for dynamic values', async () => {
const result = await target.getName({ enableCcipRead: true });
expect(result).to.equal('Satoshi');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getName({ enableCcipRead: false });
})
});

it('nested proofs for dynamic values', async () => {
const result = await target.getHighscorer(42, { enableCcipRead: true });
expect(result).to.equal('Hal Finney');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getHighscorer(42, { enableCcipRead: false });
})
});

it('nested proofs for long dynamic values', async () => {
const result = await target.getHighscorer(1, { enableCcipRead: true });
expect(result).to.equal(
'Hubert Blaine Wolfeschlegelsteinhausenbergerdorff Sr.'
);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getHighscorer(1, { enableCcipRead: false });
})
});

it('nested proofs with lookbehind', async () => {
const result = await target.getLatestHighscore({ enableCcipRead: true });
expect(Number(result)).to.equal(12345);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getLatestHighscore({ enableCcipRead: false });
})
});

it('nested proofs with lookbehind for dynamic values', async () => {
const result = await target.getLatestHighscorer({ enableCcipRead: true });
expect(result).to.equal('Hal Finney');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getLatestHighscorer({ enableCcipRead: false });
})
});

it('mappings with variable-length keys', async () => {
const result = await target.getNickname('Money Skeleton', {
enableCcipRead: true,
});
expect(result).to.equal('Vitalik Buterin');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getNickname('Money Skeleton', {
enableCcipRead: false,
});
})
});

it('nested proofs of mappings with variable-length keys', async () => {
const result = await target.getPrimaryNickname({ enableCcipRead: true });
expect(result).to.equal('Hal Finney');
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getPrimaryNickname({ enableCcipRead: false });
})
});

it('treats uninitialized storage elements as zeroes', async () => {
const result = await target.getZero({ enableCcipRead: true });
expect(Number(result)).to.equal(0);
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getZero({ enableCcipRead: false });
})
});

it('treats uninitialized dynamic values as empty strings', async () => {
const result = await target.getNickname('Santa', { enableCcipRead: true });
expect(result).to.equal("");
await estimateCCIPReadCallbackGas(provider, ()=>{
return target.getNickname('Santa', { enableCcipRead: false });
})
})
});

0 comments on commit e423972

Please sign in to comment.