Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
Haypierre committed Dec 23, 2024
1 parent 8384e4d commit e7b240d
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 20 deletions.
2 changes: 1 addition & 1 deletion remappings.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
@openzeppelin/contracts-upgradeable/=lib/openzeppelin-contracts-upgradeable/contracts/
@openzeppelin/contracts/=lib/openzeppelin-contracts/contracts/
@vibc-core-smart-contracts/=lib/vibc-core-smart-contracts/
@solady/=lib/solady/src/
@solady/=lib/solady/src/
6 changes: 3 additions & 3 deletions src/interfaces/IInvoiceManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,15 @@ interface IInvoiceManager {
address account;
uint256 nonce;
address paymaster;
string sponsorChainId;
uint256 sponsorChainId;
}

/// @notice Struct to represent the invoice.
struct InvoiceWithRepayTokens {
address account;
uint256 nonce;
address paymaster;
string sponsorChainId;
uint256 sponsorChainId;
RepayTokenInfo[] repayTokenInfos;
}

Expand Down Expand Up @@ -141,7 +141,7 @@ interface IInvoiceManager {
address account,
address paymaster,
uint256 nonce,
string sponsorChainId,
uint256 sponsorChainId,
RepayTokenInfo[] calldata repayTokenInfos
) external view returns (bytes32);
}
1 change: 1 addition & 0 deletions src/interfaces/IPaymasterVerifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ interface IPaymasterVerifier {
/// @notice Emitted when an invoice is verified.
event InvoiceVerified(bytes32 indexed invoiceId);


/// @notice The struct of the sponsor token.
struct SponsorToken {
address token;
Expand Down
24 changes: 8 additions & 16 deletions src/paymasters/CABPaymaster.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import {IVault} from "../interfaces/IVault.sol";
import {IPaymasterVerifier} from "../interfaces/IPaymasterVerifier.sol";
import {ICrossL2Prover} from "@vibc-core-smart-contracts/contracts/interfaces/ICrossL2Prover.sol";

import {LibBytes} from "@solady/src/utils/LibBytes.sol";
import {LibBytes} from "@solady/utils/LibBytes.sol";


/**
* @title CABPaymaster
Expand Down Expand Up @@ -54,27 +55,18 @@ contract CABPaymaster is IPaymasterVerifier, BasePaymaster {
_invoice.account, _invoice.paymaster, _invoice.nonce, _invoice.sponsorChainId, _invoice.repayTokenInfos
);

// validateEvent(uint256 ,logIndex, bytes calldata proof) returns (bytes32 chainId, address emittingContract, bytes[] memory topics, bytes memory unindexedData)

if (invoiceId != _invoiceId) return false;

(uint256 logIndex, bytes memory proof) = abi.decode(_proof, (uint256, bytes));

(string memory proofChainId, address emittingContract, bytes[] memory topics, bytes memory unindexedData) =
prover.validateEvent(logIndex, proof);

if (!Bytes.equal(bytes(abi.encodePacked(_invoice.sponsorChainId)), bytes(proofChainId))) {
revert invalidChainId();
}
if (emittingContract != expectedEmitter) {
revert invalidEventSender();
}
crossL2Prover.validateEvent(logIndex, proof);

if (!Bytes.equal(abi.encode(topics), abi.encode(expectedTopics))) {
revert invalidCounterpartyEvent();
}
if (!Bytes.equal(unindexedData, expectedUnindexedData)) {
revert invalidCounterpartyEvent();
bytes[] memory expectedTopics = new bytes[](2);
expectedTopics[0] = abi.encode(keccak256("InvoiceCreated(bytes32)"));
expectedTopics[1] = abi.encode(invoiceId);
if (!LibBytes.eq(abi.encode(topics), abi.encode(expectedTopics))) {
return false;
}

emit InvoiceVerified(invoiceId);
Expand Down

0 comments on commit e7b240d

Please sign in to comment.