Skip to content

Commit

Permalink
remove balance overrides during estimation (#364)
Browse files Browse the repository at this point in the history
* remove balance overrides during estimation

* revert changes

* uncomment second check

---------

Co-authored-by: mouseless <[email protected]>
  • Loading branch information
mouseless0x and mouseless0x authored Dec 2, 2024
1 parent d10c8e3 commit 3ea094a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 36 deletions.
23 changes: 12 additions & 11 deletions src/rpc/estimation/gasEstimationHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import type { UserOperation } from "@alto/types"
import type { StateOverrides, UserOperationV07 } from "@alto/types"
import { deepHexlify, isVersion06 } from "@alto/utils"
import type { Hex } from "viem"
import { type Address, toHex } from "viem"
import { toHex, type Address, parseEther } from "viem"
import { GasEstimatorV06 } from "./gasEstimationsV06"
import { GasEstimatorV07 } from "./gasEstimationsV07"
import type { SimulateHandleOpResult } from "./types"
Expand All @@ -11,18 +11,18 @@ import type { AltoConfig } from "../../createConfig"
function getStateOverrides({
addSenderBalanceOverride,
userOperation,
stateOverride = {}
stateOverrides = {}
}: {
addSenderBalanceOverride: boolean
stateOverride: StateOverrides
stateOverrides: StateOverrides
userOperation: UserOperation
}) {
const result: StateOverrides = { ...stateOverride }
const result: StateOverrides = { ...stateOverrides }

if (addSenderBalanceOverride) {
result[userOperation.sender] = {
...deepHexlify(stateOverride?.[userOperation.sender] || {}),
balance: toHex(100000_000000000000000000n)
...deepHexlify(stateOverrides?.[userOperation.sender] || {}),
balance: toHex(parseEther("1000000"))
}
}

Expand All @@ -43,28 +43,29 @@ export class GasEstimationHandler {
userOperation,
queuedUserOperations,
addSenderBalanceOverride,
balanceOverrideEnabled,
entryPoint,
targetAddress,
targetCallData,
balanceOverrideEnabled,
stateOverrides = {}
}: {
userOperation: UserOperation
queuedUserOperations: UserOperation[]
addSenderBalanceOverride: boolean
balanceOverrideEnabled: boolean
entryPoint: Address
targetAddress: Address
targetCallData: Hex
balanceOverrideEnabled: boolean
stateOverrides?: StateOverrides
}): Promise<SimulateHandleOpResult> {
let finalStateOverride = undefined

if (balanceOverrideEnabled) {
// Add balance override only for v0.6 userOperations (so that prefund check during simulation passes).
if (balanceOverrideEnabled && isVersion06(userOperation)) {
finalStateOverride = getStateOverrides({
userOperation,
addSenderBalanceOverride,
stateOverride: stateOverrides
stateOverrides
})
}

Expand All @@ -82,7 +83,7 @@ export class GasEstimationHandler {
userOperation: userOperation as UserOperationV07,
queuedUserOperations: queuedUserOperations as UserOperationV07[],
entryPoint,
stateOverrides: finalStateOverride
stateOverrides
})
}
}
27 changes: 3 additions & 24 deletions src/rpc/rpcHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -534,9 +534,9 @@ export class RpcHandler implements IRpcEndpoint {
)
}

// If a balance override is provided for the sender, perform an additional simulation
// to verify the userOperation succeeds with the specified balance.
if (stateOverrides?.[userOperation.sender]?.balance !== undefined) {
// TODO: uncomment this
// Check if userOperation passes
if (isVersion06(userOperation)) {
await this.validator.getExecutionResult(
{
...userOperation,
Expand All @@ -548,29 +548,8 @@ export class RpcHandler implements IRpcEndpoint {
},
entryPoint,
queuedUserOperations,
false,
deepHexlify(stateOverrides)
)
} else {
// Temporarily log reverts in event of user not having enough balance.
try {
await this.validator.getExecutionResult(
{
...userOperation,
preVerificationGas,
verificationGasLimit,
callGasLimit,
paymasterVerificationGasLimit,
paymasterPostOpGasLimit
},
entryPoint,
queuedUserOperations,
false,
deepHexlify(stateOverrides)
)
} catch (e) {
this.logger.error(e, "Second simulation failed")
}
}

if (isVersion07(userOperation)) {
Expand Down
2 changes: 1 addition & 1 deletion test/e2e/alto-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
"log-environment": "production",
"enable-debug-endpoints": true,
"entrypoints": "0x5ff137d4b0fdcd49dca30c7cf57e578a026d2789,0x0000000071727De22E5E9d8BAf0edAc6f37da032",
"balance-override-enabled": "true",
"entrypoint-simulation-contract": "0xBbe8A301FbDb2a4CD58c4A37c262ecef8f889c47",
"balance-override-enabled": "true",
"api-version": "v1,v2",
"rpc-url": "http://anvil:8545",
"min-balance": "0",
Expand Down

0 comments on commit 3ea094a

Please sign in to comment.