Skip to content
This repository was archived by the owner on Oct 20, 2024. It is now read-only.

Commit e70171f

Browse files
authored
Reduce diff between tracer and binary search for callGasLimit (#222)
1 parent 121fad8 commit e70171f

File tree

14 files changed

+94
-88
lines changed

14 files changed

+94
-88
lines changed

.github/workflows/compliance.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
--dev \
6262
--allow-insecure-unlock \
6363
--rpc.allow-unprotected-txs \
64-
--dev.gaslimit 20000000 &
64+
--miner.gaslimit 12000000 &
6565
6666
- name: Install bundler dependencies
6767
run: go mod download
@@ -87,6 +87,7 @@ jobs:
8787
ERC4337_BUNDLER_ETH_CLIENT_URL: http://localhost:8545/
8888
ERC4337_BUNDLER_PORT: 3000
8989
ERC4337_BUNDLER_DEBUG_MODE: true
90+
ERC4337_BUNDLER_MAX_BATCH_GAS_LIMIT: 12000000
9091
# This key is for testing purposes only. Do not use for anything else.
9192
ERC4337_BUNDLER_PRIVATE_KEY: c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb
9293

.github/workflows/e2e.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ jobs:
8282
--dev \
8383
--allow-insecure-unlock \
8484
--rpc.allow-unprotected-txs \
85-
--dev.gaslimit 20000000 &
85+
--miner.gaslimit 12000000 &
8686
8787
- name: Install all dependencies
8888
run: |
@@ -110,6 +110,7 @@ jobs:
110110
env:
111111
ERC4337_BUNDLER_ETH_CLIENT_URL: http://localhost:8545/
112112
ERC4337_BUNDLER_DEBUG_MODE: true
113+
ERC4337_BUNDLER_MAX_BATCH_GAS_LIMIT: 12000000
113114
# This key is for testing purposes only. Do not use for anything else.
114115
ERC4337_BUNDLER_PRIVATE_KEY: c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb
115116

e2e/README.md

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,18 +21,17 @@ First, we'll need to run a local instance of geth with the following command:
2121

2222
```bash
2323
geth \
24-
--miner.gaslimit 12000000 \
25-
--http \
26-
--http.api personal,eth,net,web3,debug \
27-
--allow-insecure-unlock \
28-
--rpc.allow-unprotected-txs \
2924
--http.vhosts '*,localhost,host.docker.internal' \
25+
--http \
26+
--http.api eth,net,web3,debug \
3027
--http.corsdomain '*' \
3128
--http.addr "0.0.0.0" \
32-
--dev \
3329
--nodiscover --maxpeers 0 --mine \
34-
--miner.threads 1 \
35-
--ignore-legacy-receipts
30+
--networkid 1337 \
31+
--dev \
32+
--allow-insecure-unlock \
33+
--rpc.allow-unprotected-txs \
34+
--miner.gaslimit 12000000
3635
```
3736

3837
In a separate process, navigate to the [eth-infinitism/account-abstraction](https://github.com/eth-infinitism/account-abstraction/) directory and run the following command to deploy the required contracts:
@@ -52,6 +51,7 @@ Lastly, run the bundler with the following config:
5251
```
5352
ERC4337_BUNDLER_ETH_CLIENT_URL=http://localhost:8545
5453
ERC4337_BUNDLER_PRIVATE_KEY=c6cbc5ffad570fdad0544d1b5358a36edeb98d163b6567912ac4754e144d4edb
54+
ERC4337_BUNDLER_MAX_BATCH_GAS_LIMIT=12000000
5555
ERC4337_BUNDLER_DEBUG_MODE=true
5656
```
5757

e2e/config.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,8 @@ const config: IConfig = {
1313
nodeUrl: "http://localhost:8545",
1414
bundlerUrl: "http://localhost:4337",
1515
testERC20Token: "0x3870419Ba2BBf0127060bCB37f69A1b1C090992B",
16-
testGas: "0xE057Fe015a4cf6838403213E3576B73383428500",
16+
// https://github.com/stackup-wallet/contracts/blob/main/contracts/test/TestGas.sol
17+
testGas: "0x310de3671FCDA16eC24433e7610c2F48DEE7f8c2",
1718
};
1819

1920
export default config;

e2e/src/abi.ts

Lines changed: 7 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -160,56 +160,25 @@ export const testGasABI = [
160160
{
161161
inputs: [],
162162
name: "offset",
163-
outputs: [
164-
{
165-
internalType: "uint256",
166-
name: "",
167-
type: "uint256",
168-
},
169-
],
163+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
170164
stateMutability: "view",
171165
type: "function",
172166
},
173167
{
174168
inputs: [
175-
{
176-
internalType: "uint8",
177-
name: "depth",
178-
type: "uint8",
179-
},
180-
{
181-
internalType: "uint8",
182-
name: "count",
183-
type: "uint8",
184-
},
169+
{ internalType: "uint256", name: "depth", type: "uint256" },
170+
{ internalType: "uint256", name: "width", type: "uint256" },
171+
{ internalType: "uint256", name: "count", type: "uint256" },
185172
],
186173
name: "recursiveCall",
187-
outputs: [
188-
{
189-
internalType: "uint256",
190-
name: "",
191-
type: "uint256",
192-
},
193-
],
174+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
194175
stateMutability: "payable",
195176
type: "function",
196177
},
197178
{
198-
inputs: [
199-
{
200-
internalType: "uint256",
201-
name: "",
202-
type: "uint256",
203-
},
204-
],
179+
inputs: [{ internalType: "uint256", name: "", type: "uint256" }],
205180
name: "store",
206-
outputs: [
207-
{
208-
internalType: "uint256",
209-
name: "",
210-
type: "uint256",
211-
},
212-
],
181+
outputs: [{ internalType: "uint256", name: "", type: "uint256" }],
213182
stateMutability: "view",
214183
type: "function",
215184
},

e2e/src/helpers.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export const fundIfRequired = async (
2626
if (accountBalance.eq(0)) {
2727
const response = await signer.sendTransaction({
2828
to: account,
29-
value: ethers.constants.WeiPerEther,
29+
value: ethers.constants.WeiPerEther.mul(2),
3030
});
3131
await response.wait();
32-
console.log("Funded Account with 1 ETH...");
32+
console.log("Funded Account with 2 ETH...");
3333
}
3434

3535
if (accountTokenBalance.eq(0)) {

e2e/test/withoutPaymaster.test.ts

Lines changed: 28 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -113,16 +113,16 @@ describe("Without Paymaster", () => {
113113
acc.execute(
114114
config.testGas,
115115
0,
116-
testGas.interface.encodeFunctionData("recursiveCall", [32, 32])
116+
testGas.interface.encodeFunctionData("recursiveCall", [32, 0, 32])
117117
)
118118
);
119119
} catch (error: any) {
120-
expect(error?.error.code).toBe(errorCodes.invalidFields);
120+
expect(error?.error.code).toBe(errorCodes.executionReverted);
121121
}
122122
});
123123

124124
describe("With increasing call stack size", () => {
125-
describe("With zero value calls", () => {
125+
describe("With zero value", () => {
126126
[0, 2, 4, 8, 16].forEach((depth) => {
127127
test(`Sender can make contract interactions with ${depth} recursive calls`, async () => {
128128
const response = await client.sendUserOperation(
@@ -131,6 +131,7 @@ describe("Without Paymaster", () => {
131131
0,
132132
testGas.interface.encodeFunctionData("recursiveCall", [
133133
depth,
134+
0,
134135
depth,
135136
])
136137
)
@@ -142,7 +143,7 @@ describe("Without Paymaster", () => {
142143
});
143144
});
144145

145-
describe("With non-zero value calls", () => {
146+
describe("With non-zero value", () => {
146147
[0, 2, 4, 8, 16].forEach((depth) => {
147148
test(`Sender can make contract interactions with ${depth} recursive calls`, async () => {
148149
const response = await client.sendUserOperation(
@@ -151,6 +152,29 @@ describe("Without Paymaster", () => {
151152
ethers.utils.parseEther("0.001"),
152153
testGas.interface.encodeFunctionData("recursiveCall", [
153154
depth,
155+
0,
156+
depth,
157+
])
158+
)
159+
);
160+
const event = await response.wait();
161+
162+
expect(event?.args.success).toBe(true);
163+
});
164+
});
165+
});
166+
167+
describe("With multiple stacks per depth", () => {
168+
[0, 1, 2, 3].forEach((depth) => {
169+
test(`Sender can make contract interactions with ${depth} recursive calls`, async () => {
170+
const width = depth;
171+
const response = await client.sendUserOperation(
172+
acc.execute(
173+
config.testGas,
174+
0,
175+
testGas.interface.encodeFunctionData("recursiveCall", [
176+
depth,
177+
width,
154178
depth,
155179
])
156180
)

internal/start/private.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ func PrivateMode() {
9999
// Init Client
100100
c := client.New(mem, ov, chain, conf.SupportedEntryPoints)
101101
c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth))
102-
c.SetGetGasEstimateFunc(client.GetGasEstimateWithEthClient(rpc, ov, chain))
102+
c.SetGetGasEstimateFunc(client.GetGasEstimateWithEthClient(rpc, ov, chain, conf.MaxBatchGasLimit))
103103
c.SetGetUserOpByHashFunc(client.GetUserOpByHashWithEthClient(eth))
104104
c.UseLogger(logr)
105105
c.UseModules(

internal/start/searcher.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ func SearcherMode() {
9090
// Init Client
9191
c := client.New(mem, ov, chain, conf.SupportedEntryPoints)
9292
c.SetGetUserOpReceiptFunc(client.GetUserOpReceiptWithEthClient(eth))
93-
c.SetGetGasEstimateFunc(client.GetGasEstimateWithEthClient(rpc, ov, chain))
93+
c.SetGetGasEstimateFunc(client.GetGasEstimateWithEthClient(rpc, ov, chain, conf.MaxBatchGasLimit))
9494
c.SetGetUserOpByHashFunc(client.GetUserOpByHashWithEthClient(eth))
9595
c.UseLogger(logr)
9696
c.UseModules(

pkg/client/utils.go

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -48,14 +48,16 @@ func GetGasEstimateWithEthClient(
4848
rpc *rpc.Client,
4949
ov *gas.Overhead,
5050
chain *big.Int,
51+
maxGasLimit *big.Int,
5152
) GetGasEstimateFunc {
5253
return func(ep common.Address, op *userop.UserOperation) (verificationGas uint64, callGas uint64, err error) {
5354
return gas.EstimateGas(&gas.EstimateInput{
54-
Rpc: rpc,
55-
EntryPoint: ep,
56-
Op: op,
57-
Ov: ov,
58-
ChainID: chain,
55+
Rpc: rpc,
56+
EntryPoint: ep,
57+
Op: op,
58+
Ov: ov,
59+
ChainID: chain,
60+
MaxGasLimit: maxGasLimit,
5961
})
6062
}
6163
}

0 commit comments

Comments
 (0)