From cfb0ad89e31d069ba6161b141457d3a4cff3823b Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:38:53 +0400 Subject: [PATCH] fix: BICONOMYSPONSOR-007 minor fixes --- contracts/common/BiconomySponsorshipPaymasterErrors.sol | 7 ++++++- contracts/sponsorship/BiconomySponsorshipPaymaster.sol | 7 ++++--- test/unit/concrete/TestSponsorshipPaymaster.t.sol | 7 ++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/contracts/common/BiconomySponsorshipPaymasterErrors.sol b/contracts/common/BiconomySponsorshipPaymasterErrors.sol index 1760143..1ea4735 100644 --- a/contracts/common/BiconomySponsorshipPaymasterErrors.sol +++ b/contracts/common/BiconomySponsorshipPaymasterErrors.sol @@ -40,7 +40,7 @@ contract BiconomySponsorshipPaymasterErrors { /** * @notice Throws when insufficient funds to withdraw */ - error InsufficientFundsInGasTank(); + error InsufficientFunds(); /** * @notice Throws when invalid signature length in paymasterAndData @@ -67,6 +67,11 @@ contract BiconomySponsorshipPaymasterErrors { */ error CanNotWithdrawToZeroAddress(); + /** + * @notice Throws when trying to withdraw zero amount + */ + error CanNotWithdrawZeroAmount(); + /** * @notice Throws when trying unaccountedGas is too high */ diff --git a/contracts/sponsorship/BiconomySponsorshipPaymaster.sol b/contracts/sponsorship/BiconomySponsorshipPaymaster.sol index 64c0050..ab418ac 100644 --- a/contracts/sponsorship/BiconomySponsorshipPaymaster.sol +++ b/contracts/sponsorship/BiconomySponsorshipPaymaster.sol @@ -120,8 +120,8 @@ contract BiconomySponsorshipPaymaster is } /** - * @dev Set a new unaccountedEPGasOverhead value. - * @param value The new value to be set as the unaccountedEPGasOverhead. + * @dev Set a new unaccountedGas value. + * @param value The new value to be set as the unaccountedGas. * @notice only to be called by the owner of the contract. */ function setUnaccountedGas(uint256 value) external payable onlyOwner { @@ -158,9 +158,10 @@ contract BiconomySponsorshipPaymaster is */ function withdrawTo(address payable withdrawAddress, uint256 amount) external override nonReentrant { if (withdrawAddress == address(0)) revert CanNotWithdrawToZeroAddress(); + if (amount == 0) revert CanNotWithdrawZeroAmount(); uint256 currentBalance = paymasterIdBalances[msg.sender]; if (amount > currentBalance) { - revert InsufficientFundsInGasTank(); + revert InsufficientFunds(); } paymasterIdBalances[msg.sender] = currentBalance - amount; entryPoint.withdrawTo(withdrawAddress, amount); diff --git a/test/unit/concrete/TestSponsorshipPaymaster.t.sol b/test/unit/concrete/TestSponsorshipPaymaster.t.sol index 5eacdc9..3f23440 100644 --- a/test/unit/concrete/TestSponsorshipPaymaster.t.sol +++ b/test/unit/concrete/TestSponsorshipPaymaster.t.sol @@ -194,8 +194,13 @@ contract TestSponsorshipPaymasterWithPriceMarkup is TestBase { bicoPaymaster.withdrawTo(payable(address(0)), 0 ether); } + function test_RevertIf_WithdrawZeroAmount() external prankModifier(DAPP_ACCOUNT.addr) { + vm.expectRevert(abi.encodeWithSelector(CanNotWithdrawZeroAmount.selector)); + bicoPaymaster.withdrawTo(payable(BOB_ADDRESS), 0 ether); + } + function test_RevertIf_WithdrawToExceedsBalance() external prankModifier(DAPP_ACCOUNT.addr) { - vm.expectRevert(abi.encodeWithSelector(InsufficientFundsInGasTank.selector)); + vm.expectRevert(abi.encodeWithSelector(InsufficientFunds.selector)); bicoPaymaster.withdrawTo(payable(BOB_ADDRESS), 1 ether); }