From b5c0b04263cd7bb03b78692611f3b26f881672a1 Mon Sep 17 00:00:00 2001 From: livingrockrises <90545960+livingrockrises@users.noreply.github.com> Date: Thu, 14 Nov 2024 12:00:26 +0700 Subject: [PATCH] fix: remediations. allow receive eth and withdraw stuck eth --- .../common/BiconomyTokenPaymasterErrors.sol | 10 ++++++++++ contracts/token/BiconomyTokenPaymaster.sol | 17 +++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/contracts/common/BiconomyTokenPaymasterErrors.sol b/contracts/common/BiconomyTokenPaymasterErrors.sol index b77a63f..6188f11 100644 --- a/contracts/common/BiconomyTokenPaymasterErrors.sol +++ b/contracts/common/BiconomyTokenPaymasterErrors.sol @@ -75,4 +75,14 @@ contract BiconomyTokenPaymasterErrors { * @notice Throws when external signer's signature has invalid length */ error InvalidSignatureLength(); + + /** + * @notice Throws when ETH withdrawal fails + */ + error WithdrawalFailed(); + + /** + * @notice Emitted when ETH is withdrawn from the paymaster + */ + event EthWithdrawn(address indexed recipient, uint256 indexed amount); } diff --git a/contracts/token/BiconomyTokenPaymaster.sol b/contracts/token/BiconomyTokenPaymaster.sol index 75b5726..1642099 100644 --- a/contracts/token/BiconomyTokenPaymaster.sol +++ b/contracts/token/BiconomyTokenPaymaster.sol @@ -133,6 +133,10 @@ contract BiconomyTokenPaymaster is } } + receive() external payable { + // no need to emit an event here + } + /** * @dev pull tokens out of paymaster in case they were sent to the paymaster at any point. * @param token the token deposit to withdraw @@ -143,6 +147,19 @@ contract BiconomyTokenPaymaster is _withdrawERC20(token, target, amount); } + /** + * @dev Withdraw ETH from the paymaster + * @param recipient The address to send the ETH to + * @param amount The amount of ETH to withdraw + */ + function withdrawEth(address payable recipient, uint256 amount) external payable onlyOwner nonReentrant { + (bool success,) = recipient.call{ value: amount }(""); + if (!success) { + revert WithdrawalFailed(); + } + emit EthWithdrawn(recipient, amount); + } + /** * @dev pull tokens out of paymaster in case they were sent to the paymaster at any point. * @param token the token deposit to withdraw