Skip to content

Commit

Permalink
Revert change - do pick the smaller of worker/paymaster balance for d…
Browse files Browse the repository at this point in the history
…ry run (#954)

* Revert change - do pick the smaller of worker/paymaster balance for dry run

* minViewableGasLimit: '300000'
  • Loading branch information
forshtat authored Mar 15, 2023
1 parent 4d5ae09 commit 734a393
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -166,4 +166,3 @@ include any support for meta-transactions and requires at least a single call to
## Live demo

Make a transaction and capture the flag on-chain without paying for gas. [Try it now!](https://ctf-react.opengsn.org/)

6 changes: 4 additions & 2 deletions packages/common/src/ContractInteractor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1310,6 +1310,7 @@ calculateTransactionMaxPossibleGas: result: ${result}
maxViewableGasLimit: BN,
minViewableGasLimit: BN
): Promise<BN> {
const paymasterBalance = await this.hubBalanceOf(paymasterAddress)
let workerBalance = constants.MAX_UINT256 // skipping worker address balance check in dry-run
if (!isSameAddress(workerAddress, constants.DRY_RUN_ADDRESS)) {
const workerBalanceStr = await this.getBalance(workerAddress, 'pending')
Expand All @@ -1319,12 +1320,13 @@ calculateTransactionMaxPossibleGas: result: ${result}
// using base fee override to avoid division by zero
maxFeePerGas = toBN((await this.getGasFees(5, 50)).baseFeePerGas)
}
const workerBalanceGasLimit = workerBalance.div(maxFeePerGas)
const smallerBalance = BN.min(paymasterBalance, workerBalance)
const smallerBalanceGasLimit = smallerBalance.div(maxFeePerGas)
.muln(9).divn(10) // hard-coded to use 90% of available worker/paymaster balance
const blockGasLimitNum = await this.getBlockGasLimit()
const blockGasLimit = toBN(blockGasLimitNum)
.muln(3).divn(4) // hard-coded to use 75% of available block gas limit
return BN.max(minViewableGasLimit, BN.min(maxViewableGasLimit, BN.min(workerBalanceGasLimit, blockGasLimit)))
return BN.max(minViewableGasLimit, BN.min(maxViewableGasLimit, BN.min(smallerBalanceGasLimit, blockGasLimit)))
}
}

Expand Down
2 changes: 1 addition & 1 deletion packages/provider/src/GSNConfigurator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export const defaultGsnConfig: GSNConfig = {
clientId: '1',
requestValidSeconds: 172800, // 2 days
maxViewableGasLimit: '12000000',
minViewableGasLimit: '50000',
minViewableGasLimit: '300000',
environment: defaultEnvironment,
maxApprovalDataLength: 0,
maxPaymasterDataLength: 0,
Expand Down

0 comments on commit 734a393

Please sign in to comment.