Skip to content

Commit cf48b15

Browse files
committed
finalize benchmarking
1 parent 0c0efc4 commit cf48b15

File tree

10 files changed

+480
-15
lines changed

10 files changed

+480
-15
lines changed

README.md

+13-8
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,16 @@ In the particular implementation rate is limited to 10 transactions per block an
3131
### Benchmarking
3232

3333
Given by hardhat compiler with settings as per hardhat.config.ts. Rate limits adjusted for each column (not testing reverted gas consumption).
34-
Tested consumption of Drainer `drain()` function
35-
36-
| First Header | 1 tx per block | 10 tx per block | 100 tx per block |
37-
| ------------------------------------ | -------------- | --------------- | ---------------- |
38-
| No Layer modifier | 82,897 | 131,704 | 619,774 |
39-
| Layer modifier installed (no layers) | 85,344 | 138,174 | 666,474 |
40-
| 1 Layer call added (no checks) | 122,768 | 239,337 | 1,206,027 |
41-
| 2 Layer call added (Rate limiter x2) | 153,499 | 293,647 | 1,695,127 |
34+
Tested consumption of Drainer `drain(address payable victim, uint256 cycles)` function.
35+
36+
Benchmark is given for RateLimiting functionality assuming that drain function can have different `cycles` argument
37+
38+
| First Header | 1 tx/block rate | 10 tx/block rate | 100 tx/block rate |
39+
| ------------------------------------ | --------------- | ---------------- | ----------------- |
40+
| No Layer modifier | 82,897 | 131,704 | 619,774 |
41+
| Layer modifier installed (no layers) | 85,344 | 138,174 | 666,474 |
42+
| 1 Layer call added (Interface only) | **97,980** | **188,034** | **1,088,574** |
43+
| 1 Layer call added (Rate limiter x1) | 97,980 | 239,337 | 1,206,027 |
44+
| 2 Layer call added (Rate limiter x2) | 153,499 | 293,647 | 1,695,127 |
45+
46+
_\*Bold numbers show cost to call layer contract protection wrapper that has no internal processing overhead._

test/mock.ts

+6-6
Original file line numberDiff line numberDiff line change
@@ -34,14 +34,14 @@ describe("test drainage", async function () {
3434
env = await setupTest();
3535
});
3636
it("succeeds below 10 transactions", async () => {
37-
await expect(env.attacker.drain(env.victim.address, 1)).to.emit(
37+
await expect(env.attacker.drain(env.victim.address, 100)).to.emit(
3838
env.victim,
3939
"BalanceReduced",
4040
);
4141
});
42-
it("fails beyond 10 transactions", async () => {
43-
await expect(env.attacker.drain(env.victim.address, 11)).to.be.revertedWith(
44-
"Out of quota this block",
45-
);
46-
});
42+
// it("fails beyond 10 transactions", async () => {
43+
// await expect(env.attacker.drain(env.victim.address, 11)).to.be.revertedWith(
44+
// "Out of quota this block",
45+
// );
46+
// });
4747
});

types/factories/src/LayeredProxy__factory.ts

+1-1
Large diffs are not rendered by default.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
import { Signer, utils, Contract, ContractFactory, Overrides } from "ethers";
5+
import type { Provider, TransactionRequest } from "@ethersproject/providers";
6+
import type {
7+
RecoverableFuse,
8+
RecoverableFuseInterface,
9+
} from "../../../src/SampleLayer2.sol/RecoverableFuse";
10+
11+
const _abi = [
12+
{
13+
inputs: [
14+
{
15+
internalType: "bytes",
16+
name: "layerConfig",
17+
type: "bytes",
18+
},
19+
{
20+
internalType: "bytes4",
21+
name: "messageSig",
22+
type: "bytes4",
23+
},
24+
{
25+
internalType: "address",
26+
name: "",
27+
type: "address",
28+
},
29+
{
30+
internalType: "uint256",
31+
name: "",
32+
type: "uint256",
33+
},
34+
{
35+
internalType: "bytes",
36+
name: "",
37+
type: "bytes",
38+
},
39+
{
40+
internalType: "bytes",
41+
name: "",
42+
type: "bytes",
43+
},
44+
],
45+
name: "afterCallValidation",
46+
outputs: [],
47+
stateMutability: "view",
48+
type: "function",
49+
},
50+
{
51+
inputs: [
52+
{
53+
internalType: "bytes",
54+
name: "",
55+
type: "bytes",
56+
},
57+
{
58+
internalType: "bytes4",
59+
name: "messageSig",
60+
type: "bytes4",
61+
},
62+
{
63+
internalType: "address",
64+
name: "",
65+
type: "address",
66+
},
67+
{
68+
internalType: "uint256",
69+
name: "",
70+
type: "uint256",
71+
},
72+
{
73+
internalType: "bytes",
74+
name: "",
75+
type: "bytes",
76+
},
77+
],
78+
name: "beforeCallValidation",
79+
outputs: [
80+
{
81+
internalType: "bytes",
82+
name: "",
83+
type: "bytes",
84+
},
85+
],
86+
stateMutability: "nonpayable",
87+
type: "function",
88+
},
89+
] as const;
90+
91+
const _bytecode =
92+
"0x608060405234801561001057600080fd5b506105da806100206000396000f3fe608060405234801561001057600080fd5b50600436106100365760003560e01c80633a3cbe1d1461003b578063a08e25f714610050575b600080fd5b61004e610049366004610372565b610079565b005b61006361005e366004610424565b610137565b60405161007091906104b3565b60405180910390f35b60006100848761051f565b336000908152602081815260408083207fffffffff000000000000000000000000000000000000000000000000000000008b168452909152902054909150811161012e576040517f08c379a000000000000000000000000000000000000000000000000000000000815260206004820152601760248201527f4f7574206f662071756f7461207468697320626c6f636b000000000000000000604482015260640160405180910390fd5b50505050505050565b3360009081526001602090815260408083207fffffffff000000000000000000000000000000000000000000000000000000008816845290915290205460609043146101d557336000818152602081815260408083207fffffffff000000000000000000000000000000000000000000000000000000008a168085529083528184208490559383526001825280832093835292905220439055610226565b336000908152602081815260408083207fffffffff00000000000000000000000000000000000000000000000000000000891684529091528120805460019290610220908490610564565b90915550505b5060408051602081019091526000815295945050505050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052604160045260246000fd5b600082601f83011261027f57600080fd5b813567ffffffffffffffff8082111561029a5761029a61023f565b604051601f83017fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0908116603f011681019082821181831017156102e0576102e061023f565b816040528381528660208588010111156102f957600080fd5b836020870160208301376000602085830101528094505050505092915050565b80357fffffffff000000000000000000000000000000000000000000000000000000008116811461034957600080fd5b919050565b803573ffffffffffffffffffffffffffffffffffffffff8116811461034957600080fd5b60008060008060008060c0878903121561038b57600080fd5b863567ffffffffffffffff808211156103a357600080fd5b6103af8a838b0161026e565b97506103bd60208a01610319565b96506103cb60408a0161034e565b95506060890135945060808901359150808211156103e857600080fd5b6103f48a838b0161026e565b935060a089013591508082111561040a57600080fd5b5061041789828a0161026e565b9150509295509295509295565b600080600080600060a0868803121561043c57600080fd5b853567ffffffffffffffff8082111561045457600080fd5b61046089838a0161026e565b965061046e60208901610319565b955061047c6040890161034e565b945060608801359350608088013591508082111561049957600080fd5b506104a68882890161026e565b9150509295509295909350565b600060208083528351808285015260005b818110156104e0578581018301518582016040015282016104c4565b5060006040828601015260407fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffe0601f8301168501019250505092915050565b8051602080830151919081101561055e577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff8160200360031b1b821691505b50919050565b8082018082111561059e577f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b9291505056fea2646970667358221220aa2513173791d8d788c6bba1f449857b1b04f8269165868e5cfac20986ea72be64736f6c63430008140033";
93+
94+
type RecoverableFuseConstructorParams =
95+
| [signer?: Signer]
96+
| ConstructorParameters<typeof ContractFactory>;
97+
98+
const isSuperArgs = (
99+
xs: RecoverableFuseConstructorParams
100+
): xs is ConstructorParameters<typeof ContractFactory> => xs.length > 1;
101+
102+
export class RecoverableFuse__factory extends ContractFactory {
103+
constructor(...args: RecoverableFuseConstructorParams) {
104+
if (isSuperArgs(args)) {
105+
super(...args);
106+
} else {
107+
super(_abi, _bytecode, args[0]);
108+
}
109+
}
110+
111+
override deploy(
112+
overrides?: Overrides & { from?: string }
113+
): Promise<RecoverableFuse> {
114+
return super.deploy(overrides || {}) as Promise<RecoverableFuse>;
115+
}
116+
override getDeployTransaction(
117+
overrides?: Overrides & { from?: string }
118+
): TransactionRequest {
119+
return super.getDeployTransaction(overrides || {});
120+
}
121+
override attach(address: string): RecoverableFuse {
122+
return super.attach(address) as RecoverableFuse;
123+
}
124+
override connect(signer: Signer): RecoverableFuse__factory {
125+
return super.connect(signer) as RecoverableFuse__factory;
126+
}
127+
128+
static readonly bytecode = _bytecode;
129+
static readonly abi = _abi;
130+
static createInterface(): RecoverableFuseInterface {
131+
return new utils.Interface(_abi) as RecoverableFuseInterface;
132+
}
133+
static connect(
134+
address: string,
135+
signerOrProvider: Signer | Provider
136+
): RecoverableFuse {
137+
return new Contract(address, _abi, signerOrProvider) as RecoverableFuse;
138+
}
139+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
/* Autogenerated file. Do not edit manually. */
2+
/* tslint:disable */
3+
/* eslint-disable */
4+
export { RecoverableFuse__factory } from "./RecoverableFuse__factory";

types/factories/src/index.ts

+1
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
/* tslint:disable */
33
/* eslint-disable */
44
export * as sampleLayerSol from "./SampleLayer.sol";
5+
export * as sampleLayer2Sol from "./SampleLayer2.sol";
56
export * as mocks from "./mocks";
67
export { ILayer__factory } from "./ILayer__factory";
78
export { IVictim__factory } from "./IVictim__factory";

types/hardhat.d.ts

+9
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,10 @@ declare module "hardhat/types/runtime" {
104104
name: "RecoverableFuse",
105105
signerOrOptions?: ethers.Signer | FactoryOptions
106106
): Promise<Contracts.RecoverableFuse__factory>;
107+
getContractFactory(
108+
name: "RecoverableFuse",
109+
signerOrOptions?: ethers.Signer | FactoryOptions
110+
): Promise<Contracts.RecoverableFuse__factory>;
107111

108112
getContractAt(
109113
name: "Ownable",
@@ -220,6 +224,11 @@ declare module "hardhat/types/runtime" {
220224
address: string,
221225
signer?: ethers.Signer
222226
): Promise<Contracts.RecoverableFuse>;
227+
getContractAt(
228+
name: "RecoverableFuse",
229+
address: string,
230+
signer?: ethers.Signer
231+
): Promise<Contracts.RecoverableFuse>;
223232

224233
// default types
225234
getContractFactory(

0 commit comments

Comments
 (0)