Skip to content

Commit

Permalink
Add test paymaster contract
Browse files Browse the repository at this point in the history
  • Loading branch information
b1m0n committed Apr 9, 2024
1 parent cfb2f70 commit a1d212c
Show file tree
Hide file tree
Showing 11 changed files with 1,331 additions and 7 deletions.
4 changes: 2 additions & 2 deletions contracts/eip712/IAccount.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;
pragma solidity ^0.8.20;

Check failure on line 3 in contracts/eip712/IAccount.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.8.20 does not satisfy the ^0.5.8 semver requirement

import "../libraries/TransactionHelper.sol";
import "./TransactionHelper.sol";

bytes4 constant ACCOUNT_VALIDATION_SUCCESS_MAGIC = IAccount.validateTransaction.selector;

Expand Down
6 changes: 4 additions & 2 deletions contracts/eip712/IPaymaster.sol
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;
pragma solidity ^0.8.20;

Check failure on line 3 in contracts/eip712/IPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.8.20 does not satisfy the ^0.5.8 semver requirement

import "../libraries/TransactionHelper.sol";
import "./TransactionHelper.sol";

enum ExecutionResult {
Revert,
Expand All @@ -17,6 +17,7 @@ interface IPaymaster {
/// address.
/// @param _txHash The hash of the transaction
/// @param _suggestedSignedHash The hash of the transaction that is signed by an EOA
/// @param _authenticationSignature The authorization proof signed by an EOA, can be used as a verifiable shortcut
/// @param _transaction The transaction itself.
/// @return magic The value that should be equal to the signature of the validateAndPayForPaymasterTransaction
/// if the paymaster agrees to pay for the transaction.
Expand All @@ -28,6 +29,7 @@ interface IPaymaster {
function validateAndPayForPaymasterTransaction(
bytes32 _txHash,
bytes32 _suggestedSignedHash,
bytes memory _authenticationSignature,
Transaction calldata _transaction
) external payable returns (bytes4 magic, bytes memory context);

Expand Down
2 changes: 1 addition & 1 deletion contracts/eip712/IPaymasterFlow.sol
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// SPDX-License-Identifier: MIT

pragma solidity 0.8.20;
pragma solidity ^0.8.20;

Check failure on line 3 in contracts/eip712/IPaymasterFlow.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.8.20 does not satisfy the ^0.5.8 semver requirement

/**
* @author Matter Labs
Expand Down
51 changes: 51 additions & 0 deletions contracts/eip712/TestPaymaster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.20;

Check failure on line 2 in contracts/eip712/TestPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Compiler version ^0.8.20 does not satisfy the ^0.5.8 semver requirement

import "./IPaymaster.sol";
import "../libraries/EIP712.sol";
import "../libraries/ECDSA.sol";

contract TestPaymaster is IPaymaster, EIP712 {
struct SignData {
bytes32 suggestedSignedHash;
}

address public owner;

constructor(string memory name, string memory version) EIP712(name, version) {

Check warning on line 15 in contracts/eip712/TestPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Explicitly mark visibility in function (Set ignoreConstructors to true if using solidity >=0.7.0)
owner = msg.sender;
}

function signDataTypeHash() internal pure returns (bytes32) {
return keccak256("SignData(bytes32 suggestedSignedHash)");
}

function signDataMessage(bytes32 suggestedSignedHash) internal view returns (bytes32) {
return ECDSA.toTypedDataHash(_domainSeparatorV4(), keccak256(abi.encode(
signDataTypeHash(),
suggestedSignedHash
)));
}

function validateAndPayForPaymasterTransaction(
bytes32 _txHash,

Check warning on line 31 in contracts/eip712/TestPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Variable "_txHash" is unused
bytes32 _suggestedSignedHash,
bytes memory _authenticationSignature,
Transaction calldata _transaction

Check warning on line 34 in contracts/eip712/TestPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Variable "_transaction" is unused
) external payable returns (bytes4 magic, bytes memory context) {
address recoverAddress = ECDSA.recover(signDataMessage(_suggestedSignedHash), _authenticationSignature);
require(recoverAddress == owner, "Paymaster: Unauthorized signature");

Check warning on line 37 in contracts/eip712/TestPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Error message for require is too long
return (PAYMASTER_VALIDATION_SUCCESS_MAGIC, context);
}

function postTransaction(
bytes calldata _context,
Transaction calldata _transaction,
bytes32 _txHash,
bytes32 _suggestedSignedHash,
ExecutionResult _txResult,
uint256 _maxRefundedGas
) external payable {

Check warning on line 48 in contracts/eip712/TestPaymaster.sol

View workflow job for this annotation

GitHub Actions / Lint sources (18.16.1)

Code contains empty blocks

}
}
Loading

0 comments on commit a1d212c

Please sign in to comment.