Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix/remediations #57

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions contracts/common/Errors.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ contract SponsorshipPaymasterErrors {
*/
error VerifyingSignerCannotBeZero();

/**
* @notice Throws when the paymaster id provided is a deployed contract
*/
error PaymasterIdCannotBeContract();

/**
* @notice Throws when the fee collector address provided is a deployed contract
*/
error FeeCollectorCannotBeContract();

/**
* @notice Throws when the fee collector address provided is address(0)
*/
Expand Down
30 changes: 30 additions & 0 deletions contracts/libs/AddressUtils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;


/**
* Utility library of inline functions on addresses
*/
library AddressUtils {

/**
* Returns whether the target address is a contract
* @dev This function will return false if invoked during the constructor of a contract,
* as the code is not actually created until after the constructor finishes.
* @param _addr address to check
* @return whether the target address is a contract
*/
function isContract(address _addr) internal view returns (bool) {
uint256 size;
// XXX Currently there is no better way to check if there is a contract in an address
// than to check the size of the code at that address.
// See https://ethereum.stackexchange.com/a/14016/36603
// for more details about how this works.
// TODO Check this again before the Serenity release, because all addresses will be
// contracts then.
// solium-disable-next-line security/no-inline-assembly
assembly { size := extcodesize(_addr) }
return size > 0;
}

}
9 changes: 5 additions & 4 deletions contracts/sponsorship/SponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {UserOperation, UserOperationLib} from "@account-abstraction/contracts/in
import "../BasePaymaster.sol";
import {SponsorshipPaymasterErrors} from "../common/Errors.sol";
import {MathLib} from "../libs/MathLib.sol";
import {AddressUtils} from "../libs/AddressUtils.sol";
import {ISponsorshipPaymaster} from "../interfaces/paymasters/ISponsorshipPaymaster.sol";

/**
Expand All @@ -29,6 +30,7 @@ contract SponsorshipPaymaster is
ISponsorshipPaymaster
{
using ECDSA for bytes32;
using AddressUtils for address;
using UserOperationLib for UserOperation;

uint32 private constant PRICE_DENOMINATOR = 1e6;
Expand Down Expand Up @@ -72,11 +74,10 @@ contract SponsorshipPaymaster is
* @param paymasterId dapp identifier for which deposit is being made
*/
function depositFor(address paymasterId) external payable nonReentrant {
if(paymasterId.isContract()) revert PaymasterIdCannotBeContract();
if (paymasterId == address(0)) revert PaymasterIdCannotBeZero();
if (msg.value == 0) revert DepositCanNotBeZero();
paymasterIdBalances[paymasterId] =
paymasterIdBalances[paymasterId] +
msg.value;
paymasterIdBalances[paymasterId] += msg.value;
entryPoint.depositTo{value: msg.value}(address(this));
emit GasDeposited(paymasterId, msg.value);
}
Expand Down Expand Up @@ -110,6 +111,7 @@ contract SponsorshipPaymaster is
function setFeeCollector(
address _newFeeCollector
) external payable onlyOwner {
if(_newFeeCollector.isContract()) revert FeeCollectorCannotBeContract();
if (_newFeeCollector == address(0)) revert FeeCollectorCannotBeZero();
address oldFeeCollector = feeCollector;
assembly {
Expand Down Expand Up @@ -324,7 +326,6 @@ contract SponsorshipPaymaster is
require(priceMarkup <= 2e6, "Verifying PM:high markup %");

uint32 dynamicMarkup = MathLib.maxuint32(priceMarkup, fixedPriceMarkup);
require(dynamicMarkup >= 1e6, "Verifying PM:low markup %");

uint256 effectiveCost = (requiredPreFund * dynamicMarkup) /
PRICE_DENOMINATOR;
Expand Down
Loading