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

Add constructor validation for verifyingSigner #5

Merged
merged 1 commit into from
Nov 1, 2023
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
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