Skip to content

Commit

Permalink
Check in RIP-7560 related contracts
Browse files Browse the repository at this point in the history
  • Loading branch information
forshtat committed Aug 15, 2024
1 parent 1ed9be6 commit 066904d
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 0 deletions.
22 changes: 22 additions & 0 deletions contracts/interfaces/IRip7560Account.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

/**
* @title IRip7560Account
* @dev Interface for the account contract.
*/
interface IRip7560Account {
/**
* account validation function.
* This method must call RIP7560Utils.accountAcceptTransaction to accept the transaction.
* Any other return value (or revert) will be considered as a rejection of the transaction.
* @param version - transaction encoding version RIP7560Utils.VERSION
* @param txHash - transaction hash to check the signature against
* @param transaction - encoded transaction
*/
function validateTransaction(
uint256 version,
bytes32 txHash,
bytes calldata transaction
) external;
}
9 changes: 9 additions & 0 deletions contracts/interfaces/IRip7560EntryPoint.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

interface IRip7560EntryPoint {
function acceptAccount(uint256 validAfter, uint256 validUntil) external;
function sigFailAccount(uint256 validAfter, uint256 validUntil) external;
function acceptPaymaster(uint256 validAfter, uint256 validUntil, bytes calldata context) external;
function sigFailPaymaster(uint256 validAfter, uint256 validUntil, bytes calldata context) external;
}
40 changes: 40 additions & 0 deletions contracts/interfaces/IRip7560Paymaster.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

/**
* @title IRip7560Paymaster
* @dev Interface for the paymaster contract.
*/
interface IRip7560Paymaster {

/**
* paymaster validation function.
* This method must call RIP7560Utils.paymasterAcceptTransaction to accept paying for the transaction.
* Any other return value (or revert) will be considered as a rejection of the transaction.
* @param version - transaction encoding version RIP7560Utils.VERSION
* @param txHash - transaction hash to check the signature against
* @param transaction - encoded transaction
*/
function validatePaymasterTransaction(
uint256 version,
bytes32 txHash,
bytes calldata transaction)
external;


/**
* paymaster post transaction function.
* This method is called after the transaction has been executed - if the validation function returned a context
* @dev revert in this method will cause the account execution function to revert too
* (but the reverted transaction will still get on-chain and be paid for)
* @param success - true if the transaction was successful, false otherwise
* @param actualGasCost - the actual gas cost of the transaction
* @param context - context data returned by validatePaymasterTransaction
*/
function postPaymasterTransaction(
bool success,
uint256 actualGasCost,
bytes calldata context
) external;

}
20 changes: 20 additions & 0 deletions contracts/interfaces/IRip7560Transaction.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

struct RIP7560TransactionStruct {
address sender;
uint256 nonce;
uint256 validationGasLimit;
uint256 paymasterValidationGasLimit;
uint256 postOpGasLimit;
uint256 callGasLimit;
uint256 maxFeePerGas;
uint256 maxPriorityFeePerGas;
uint256 builderFee;
address paymaster;
bytes paymasterData;
address deployer;
bytes deployerData;
bytes callData;
bytes signature;
}
39 changes: 39 additions & 0 deletions contracts/utils/RIP7560Utils.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
// SPDX-License-Identifier: GPL-3.0
pragma solidity ^0.8.19;

import "../interfaces/IRip7560EntryPoint.sol";
import "../interfaces/IRip7560Transaction.sol";

address constant ENTRY_POINT = 0x0000000000000000000000000000000000007560;

library RIP7560Utils {

//struct version, as defined in RIP-7560
uint constant VERSION = 0;

function decodeTransaction(uint256 version, bytes calldata transaction) internal pure returns (RIP7560TransactionStruct memory) {
require(version == VERSION, "RIP7560Utils: unsupported version");
return abi.decode(transaction, (RIP7560TransactionStruct));
}

function accountAcceptTransaction(
uint48 validAfter,
uint48 validUntil
) internal {
(bool success,) = ENTRY_POINT.call(
abi.encodeCall(IRip7560EntryPoint.acceptAccount, (validAfter, validUntil))
);
require(success);
}

function paymasterAcceptTransaction(
bytes memory context,
uint256 validAfter,
uint256 validUntil
) internal {
(bool success,) = ENTRY_POINT.call(
abi.encodeCall(IRip7560EntryPoint.acceptPaymaster, (validAfter, validUntil, context))
);
require(success);
}
}

0 comments on commit 066904d

Please sign in to comment.