From 734a393076012e7f0f85e69f3b10153081f057d1 Mon Sep 17 00:00:00 2001 From: Alex Forshtat Date: Wed, 15 Mar 2023 06:00:36 +0400 Subject: [PATCH] Revert change - do pick the smaller of worker/paymaster balance for dry run (#954) * Revert change - do pick the smaller of worker/paymaster balance for dry run * minViewableGasLimit: '300000' --- README.md | 1 - packages/common/src/ContractInteractor.ts | 6 ++++-- packages/provider/src/GSNConfigurator.ts | 2 +- 3 files changed, 5 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 51b6389ad..eb327e473 100644 --- a/README.md +++ b/README.md @@ -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/) - diff --git a/packages/common/src/ContractInteractor.ts b/packages/common/src/ContractInteractor.ts index b42841437..f819a4072 100644 --- a/packages/common/src/ContractInteractor.ts +++ b/packages/common/src/ContractInteractor.ts @@ -1310,6 +1310,7 @@ calculateTransactionMaxPossibleGas: result: ${result} maxViewableGasLimit: BN, minViewableGasLimit: BN ): Promise { + 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') @@ -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))) } } diff --git a/packages/provider/src/GSNConfigurator.ts b/packages/provider/src/GSNConfigurator.ts index 2aa129e23..80004ac3a 100644 --- a/packages/provider/src/GSNConfigurator.ts +++ b/packages/provider/src/GSNConfigurator.ts @@ -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,