Skip to content

Commit

Permalink
Merge pull request #9 from coinbase/v0.7
Browse files Browse the repository at this point in the history
Update encoding, fix tests
  • Loading branch information
chunter-cb authored Oct 24, 2024
2 parents c4945d2 + 94651fb commit 14a0b21
Show file tree
Hide file tree
Showing 2 changed files with 389 additions and 19 deletions.
31 changes: 12 additions & 19 deletions src/VerifyingPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,6 @@ contract VerifyingPaymaster is BasePaymaster, Ownable2Step {
/// @param newSigner Address of the new signer
event VerifyingSignerRotated(address oldSigner, address newSigner);

/// @notice Error for invalid entrypoint
error InvalidEntryPoint();

/// @notice Error for an invalid signature length
error InvalidSignatureLength();

Expand Down Expand Up @@ -132,10 +129,6 @@ contract VerifyingPaymaster is BasePaymaster, Ownable2Step {
BasePaymaster(entryPoint)
Ownable2Step()
{
if (address(entryPoint).code.length == 0) {
revert InvalidEntryPoint();
}

_transferOwnership(initialOwner);
verifyingSigner = initialVerifyingSigner;
}
Expand Down Expand Up @@ -223,7 +216,7 @@ contract VerifyingPaymaster is BasePaymaster, Ownable2Step {
override
returns (bytes memory context, uint256 validationData)
{
(PaymasterData memory paymasterData, bytes memory signature) = _parsePaymasterAndData(userOp.paymasterAndData);
(PaymasterData memory paymasterData, bytes memory signature) = _parsePaymasterData(userOp.paymasterAndData[UserOperationLib.PAYMASTER_DATA_OFFSET:]);

// Only support 65-byte signatures, to avoid potential replay attacks.
if (signature.length != 65) {
Expand Down Expand Up @@ -319,21 +312,21 @@ contract VerifyingPaymaster is BasePaymaster, Ownable2Step {
///
/// @return paymasterData Filled in PaymasterData struct
/// @return signature Paymaster signature
function _parsePaymasterAndData(bytes calldata paymasterAndData)
function _parsePaymasterData(bytes calldata paymasterAndData)
internal
pure
returns (PaymasterData memory paymasterData, bytes calldata signature)
{
paymasterData.validUntil = uint48(bytes6(paymasterAndData[20:26]));
paymasterData.validAfter = uint48(bytes6(paymasterAndData[26:32]));
paymasterData.sponsorUUID = uint128(bytes16(paymasterAndData[32:48]));
paymasterData.precheckBalance = paymasterAndData[48] > 0;
paymasterData.prepaymentRequired = paymasterAndData[49] > 0;
paymasterData.token = address(bytes20(paymasterAndData[50:70]));
paymasterData.receiver = address(bytes20(paymasterAndData[70:90]));
paymasterData.exchangeRate = uint256(bytes32(paymasterAndData[90:122]));
paymasterData.postOpGas = uint48(bytes6(paymasterAndData[122:128]));
signature = paymasterAndData[128:];
paymasterData.validUntil = uint48(bytes6(paymasterAndData[0:6]));
paymasterData.validAfter = uint48(bytes6(paymasterAndData[6:12]));
paymasterData.sponsorUUID = uint128(bytes16(paymasterAndData[12:28]));
paymasterData.precheckBalance = paymasterAndData[28] > 0;
paymasterData.prepaymentRequired = paymasterAndData[29] > 0;
paymasterData.token = address(bytes20(paymasterAndData[30:50]));
paymasterData.receiver = address(bytes20(paymasterAndData[50:70]));
paymasterData.exchangeRate = uint256(bytes32(paymasterAndData[70:102]));
paymasterData.postOpGas = uint48(bytes6(paymasterAndData[102:108]));
signature = paymasterAndData[108:];
}

/// @notice Calculate the token cost based on the gas cost and exchange rate
Expand Down
Loading

0 comments on commit 14a0b21

Please sign in to comment.