Skip to content

Commit c3c317c

Browse files
committed
feat(gas): consider eth - erc20 transfers + event selection improvements
1 parent 98e4e1f commit c3c317c

7 files changed

Lines changed: 327 additions & 195 deletions

File tree

gas-benchmarks/src/privacy-pools/constants.ts

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -15,55 +15,91 @@ export const MAX_OF_LOGS = NUMBER_OF_TRANSACTIONS * 5;
1515
export const PRIVACY_POOLS_ENTRYPOINT_PROXY: Hex = "0x6818809EefCe719E480a7526D76bD3e561526b46";
1616

1717
/**
18-
* Event ABI for the Deposited event emitted by deposit -> _handleDeposit() function
19-
*/
20-
export const DEPOSITED_EVENT_ABI = {
21-
type: "event",
22-
name: "Deposited",
23-
inputs: [
24-
{ name: "depositor", type: "address", indexed: true },
25-
{ name: "pool", type: "address", indexed: true },
26-
{ name: "commitment", type: "uint256", indexed: false },
27-
{ name: "amount", type: "uint256", indexed: false },
28-
],
29-
} as const satisfies AbiEvent;
30-
31-
/**
32-
* A deposit function call emits:
18+
* Entrypoint.deposit function:
19+
* https://github.com/0xbow-io/privacy-pools-core/blob/7bc392dad5fa483f53cf74e25d7ad19f0fc6d85f/packages/contracts/src/contracts/Entrypoint.sol#L111
20+
*
21+
* Emits:
3322
* LeafInserted() - To notify the leaf insertion in the merkle tree
3423
* Deposited() - Emitted inside PrivacyPool.sol contract (internal)
3524
* Deposited() - Emitted inside Entrypoint.sol contract (external)
3625
*
3726
* Example:
3827
* https://etherscan.io/tx/0x87320aaae4868c6f5b7c8b31ba2fc82005bdd7522fdf85f9eb8dcc93a34cb475
3928
*/
40-
export const NUMBER_OF_SHIELD_EVENTS = 3;
29+
export const SHIELD_ETH_EVENTS = [
30+
{
31+
type: "event",
32+
name: "LeafInserted",
33+
inputs: [
34+
{ name: "_index", type: "uint256", indexed: false },
35+
{ name: "_leaf", type: "uint256", indexed: false },
36+
{ name: "_root", type: "uint256", indexed: false },
37+
],
38+
},
39+
{
40+
type: "event",
41+
name: "Deposited",
42+
inputs: [
43+
{ name: "_depositor", type: "address", indexed: true },
44+
{ name: "_commitment", type: "uint256", indexed: false },
45+
{ name: "_label", type: "uint256", indexed: false },
46+
{ name: "_value", type: "uint256", indexed: false },
47+
{ name: "_precommitmentHash", type: "uint256", indexed: false },
48+
],
49+
},
50+
{
51+
type: "event",
52+
name: "Deposited",
53+
inputs: [
54+
{ name: "depositor", type: "address", indexed: true },
55+
{ name: "pool", type: "address", indexed: true },
56+
{ name: "commitment", type: "uint256", indexed: false },
57+
{ name: "amount", type: "uint256", indexed: false },
58+
],
59+
},
60+
] as const satisfies readonly AbiEvent[];
4161

4262
/**
43-
* Event ABI for the WithdrawalRelayed event emitted by Entrypoint.relay()
44-
*/
45-
export const WITHDRAWAL_RELAYED_EVENT_ABI = {
46-
type: "event",
47-
name: "WithdrawalRelayed",
48-
inputs: [
49-
{ name: "_relayer", type: "address", indexed: true },
50-
{ name: "_recipient", type: "address", indexed: true },
51-
{ name: "_asset", type: "address", indexed: true },
52-
{ name: "_amount", type: "uint256", indexed: false },
53-
{ name: "_feeAmount", type: "uint256", indexed: false },
54-
],
55-
} as const satisfies AbiEvent;
56-
57-
/**
58-
* Entrypoint.relay (unshield) function call emits:
63+
* Entrypoint.relay function:
64+
* https://github.com/0xbow-io/privacy-pools-core/blob/7bc392dad5fa483f53cf74e25d7ad19f0fc6d85f/packages/contracts/src/contracts/Entrypoint.sol#L133
65+
*
66+
* Emits:
5967
* LeafInserted() - Emitted inside State.sol -> insert()
60-
* Transfer() - move funds to entrypoint (Emitted inside PrivacyPoolComplex.sol -> _push)
6168
* Withdrawn() - Emitted inside PrivacyPool.sol -> withdraw()
62-
* Transfer() - Net amount to recipient
63-
* Transfer() - Fee to fee recipient
6469
* WithdrawalRelayed() - Emitted inside Entrypoint.relay()
6570
*
6671
* Example:
6772
* https://etherscan.io/tx/0x47e918eda32bc332a5684aa986733eb4fde7a4f8189e21443f23adf0807974b7
6873
*/
69-
export const NUMBER_OF_UNSHIELD_EVENTS = 6;
74+
export const UNSHIELD_ETH_EVENTS = [
75+
{
76+
type: "event",
77+
name: "LeafInserted",
78+
inputs: [
79+
{ name: "_index", type: "uint256", indexed: false },
80+
{ name: "_leaf", type: "uint256", indexed: false },
81+
{ name: "_root", type: "uint256", indexed: false },
82+
],
83+
},
84+
{
85+
type: "event",
86+
name: "Withdrawn",
87+
inputs: [
88+
{ name: "processor", type: "address", indexed: true },
89+
{ name: "value", type: "uint256", indexed: false },
90+
{ name: "spentNullifier", type: "uint256", indexed: false },
91+
{ name: "newCommitment", type: "uint256", indexed: false },
92+
],
93+
},
94+
{
95+
type: "event",
96+
name: "WithdrawalRelayed",
97+
inputs: [
98+
{ name: "relayer", type: "address", indexed: true },
99+
{ name: "recipient", type: "address", indexed: true },
100+
{ name: "asset", type: "address", indexed: true },
101+
{ name: "amount", type: "uint256", indexed: false },
102+
{ name: "feeAmount", type: "uint256", indexed: false },
103+
],
104+
},
105+
] as const satisfies readonly AbiEvent[];
Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,7 @@
1-
import { getEventLogs, getTransactionsWithNEvents, getUniqueLogs } from "../utils/rpc.js";
1+
import { getEventLogs, getTransactionsWithEvents, getUniqueLogs } from "../utils/rpc.js";
22
import { getAverageMetrics, saveGasMetrics } from "../utils/utils.js";
33

4-
import {
5-
DEPOSITED_EVENT_ABI,
6-
MAX_OF_LOGS,
7-
NUMBER_OF_SHIELD_EVENTS,
8-
NUMBER_OF_UNSHIELD_EVENTS,
9-
PRIVACY_POOLS_ENTRYPOINT_PROXY,
10-
WITHDRAWAL_RELAYED_EVENT_ABI,
11-
} from "./constants.js";
4+
import { MAX_OF_LOGS, PRIVACY_POOLS_ENTRYPOINT_PROXY, SHIELD_ETH_EVENTS, UNSHIELD_ETH_EVENTS } from "./constants.js";
125

136
export class PrivacyPools {
147
readonly name = "privacy-pools";
@@ -23,37 +16,38 @@ export class PrivacyPools {
2316
async benchmarkShield(): Promise<void> {
2417
const logs = await getEventLogs({
2518
contractAddress: PRIVACY_POOLS_ENTRYPOINT_PROXY,
26-
event: DEPOSITED_EVENT_ABI,
19+
event: SHIELD_ETH_EVENTS.at(-1)!,
2720
maxLogs: MAX_OF_LOGS,
2821
});
2922
const uniqueLogs = getUniqueLogs(logs);
3023

31-
const txs = await getTransactionsWithNEvents(uniqueLogs, NUMBER_OF_SHIELD_EVENTS);
24+
const txs = await getTransactionsWithEvents(uniqueLogs, SHIELD_ETH_EVENTS);
3225

3326
if (txs.length === 0) {
3427
throw new Error(`No shield transactions found for ${this.name}.`);
3528
}
3629

3730
const metrics = getAverageMetrics(txs);
3831

39-
await saveGasMetrics(metrics, `${this.name}_${this.version}`, "shield");
32+
await saveGasMetrics(metrics, `${this.name}_${this.version}`, "shield_eth");
4033
}
4134

4235
async benchmarkUnshield(): Promise<void> {
4336
const logs = await getEventLogs({
4437
contractAddress: PRIVACY_POOLS_ENTRYPOINT_PROXY,
45-
event: WITHDRAWAL_RELAYED_EVENT_ABI,
38+
event: UNSHIELD_ETH_EVENTS.at(-1)!,
4639
maxLogs: MAX_OF_LOGS,
4740
});
4841
const uniqueLogs = getUniqueLogs(logs);
4942

50-
const txs = await getTransactionsWithNEvents(uniqueLogs, NUMBER_OF_UNSHIELD_EVENTS);
43+
const txs = await getTransactionsWithEvents(uniqueLogs, UNSHIELD_ETH_EVENTS);
5144

5245
if (txs.length === 0) {
5346
throw new Error(`No unshield transactions found for ${this.name}.`);
5447
}
48+
5549
const metrics = getAverageMetrics(txs);
5650

57-
await saveGasMetrics(metrics, `${this.name}_${this.version}`, "unshield");
51+
await saveGasMetrics(metrics, `${this.name}_${this.version}`, "unshield_eth");
5852
}
5953
}

0 commit comments

Comments
 (0)