Skip to content

Commit

Permalink
Add constructor validation for verifyingSigner (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdehoog authored Nov 1, 2023
1 parent f0cade3 commit 6dbc718
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
2 changes: 2 additions & 0 deletions src/Paymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ contract Paymaster is BasePaymaster {
uint256 private constant SIGNATURE_OFFSET = VALID_TIMESTAMP_OFFSET + 64;

constructor(IEntryPoint _entryPoint, address _verifyingSigner) BasePaymaster(_entryPoint) {
require(_verifyingSigner != address(0), "Paymaster: verifyingSigner cannot be address(0)");
require(_verifyingSigner != msg.sender, "Paymaster: verifyingSigner cannot be the owner");
verifyingSigner = _verifyingSigner;
}

Expand Down
10 changes: 10 additions & 0 deletions test/Paymaster.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,16 @@ contract PaymasterTest is Test {
account = factory.createAccount(ACCOUNT_OWNER, 0);
}

function test_zeroAddressVerifyingSigner() public {
vm.expectRevert("Paymaster: verifyingSigner cannot be address(0)");
new Paymaster(entrypoint, address(0));
}

function test_ownerVerifyingSigner() public {
vm.expectRevert("Paymaster: verifyingSigner cannot be the owner");
new Paymaster(entrypoint, address(this));
}

function test_parsePaymasterAndData() public {
bytes memory paymasterAndData = abi.encodePacked(address(paymaster), abi.encode(MOCK_VALID_UNTIL, MOCK_VALID_AFTER), MOCK_SIG);
(uint48 validUntil, uint48 validAfter, bytes memory signature) = paymaster.parsePaymasterAndData(paymasterAndData);
Expand Down

0 comments on commit 6dbc718

Please sign in to comment.