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 1 commit
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
22 changes: 18 additions & 4 deletions contracts/sponsorship/SponsorshipPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -72,11 +72,10 @@ contract SponsorshipPaymaster is
* @param paymasterId dapp identifier for which deposit is being made
*/
function depositFor(address paymasterId) external payable nonReentrant {
if(isContract(paymasterId)) 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 +109,7 @@ contract SponsorshipPaymaster is
function setFeeCollector(
address _newFeeCollector
) external payable onlyOwner {
if(isContract(_newFeeCollector)) revert FeeCollectorCannotBeContract();
if (_newFeeCollector == address(0)) revert FeeCollectorCannotBeZero();
address oldFeeCollector = feeCollector;
assembly {
Expand Down Expand Up @@ -324,7 +324,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 Expand Up @@ -361,4 +360,19 @@ contract SponsorshipPaymaster is
maxPriorityFeePerGas + block.basefee
);
}

/**
* @notice Will return true if provided address is a contract
* @param account Address to verify if contract or not
* @dev This contract will return false if called within the constructor of
* a contract's deployment, as the code is not yet stored on-chain.
*/
function isContract(address account) internal view returns (bool) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be moved to a utils library

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

updated please check

uint256 csize;
// solhint-disable-next-line no-inline-assembly
assembly {
csize := extcodesize(account)
}
return csize != 0;
}
}
Loading