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

feat: Check origination contract by using RIP7755 registry contract #4

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
26 changes: 26 additions & 0 deletions contracts/src/IRIP7755Registry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

/// @title RIP7755Registry Interface
///
/// @notice An interface for the RIP-7755 registry contract. This interface defines the methods
/// that allow contracts to check, add, or remove trusted origination contracts.
interface IRIP7755Registry {

/// @notice Checks if a given origination contract is trusted
///
/// @param originationContract The address of the origination contract
///
/// @return _ A status indicating whether the contract is trusted
function checkTrustedContract(address originationContract) external view returns (bool);

/// @notice Adds an origination contract to the trusted list
///
/// @param originationContract The address of the origination contract to be trusted
function addTrustedContract(address originationContract) external;

/// @notice Removes an origination contract from the trusted list
///
/// @param originationContract The address of the origination contract to be removed
function removeTrustedContract(address originationContract) external;
}
41 changes: 41 additions & 0 deletions contracts/src/RIP7755Registry.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {Ownable} from "@openzeppelin/contracts/access/Ownable.sol";
import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol";

/// @title RIP7755Registry
///
/// @author Coinbase (https://github.com/base-org/RIP-7755-poc)
///
/// @notice A registry contract within RIP-7755. This contract serves as a registry for managing
/// and verifying trusted origination contracts.
contract RIP7755Registry is Ownable {
using Address for address;

/// @notice A mapping that tracks whether an origination contract is trusted
mapping(address => bool) private _trustedContract;

/// @notice Checks if a given origination contract is trusted
///
/// @param originationContract The address of the origination contract
///
/// @return _ A status indicating whether the contract is trusted
function checkTrustedContract(address originationContract) external view returns (bool) {
return _trustedContract[originationContract];
}

/// @notice Adds an origination contract to the trusted list
///
/// @param originationContract The address of the origination contract to be trusted
function addTrustedContract(address originationContract) external onlyOwner {
_trustedContract[originationContract] = true;
}

/// @notice Removes an origination contract from the trusted list
///
/// @param originationContract The address of the origination contract to be removed
function removeTrustedContract(address originationContract) external onlyOwner {
_trustedContract[originationContract] = false;
}
}
16 changes: 15 additions & 1 deletion contracts/src/RIP7755Verifier.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma solidity 0.8.24;
import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol";

import {IPrecheckContract} from "./IPrecheckContract.sol";
import {IRIP7755Registry} from "./IRIP7755Registry.sol";
import {CrossChainRequest} from "./RIP7755Structs.sol";

/// @title RIP7755Verifier
Expand Down Expand Up @@ -31,6 +32,9 @@ contract RIP7755Verifier {
// Main storage location used as the base for the fulfillmentInfo mapping following EIP-7201. (keccak256("RIP-7755"))
bytes32 private constant _MAIN_STORAGE_LOCATION = 0x43f1016e17bdb0194ec37b77cf476d255de00011d02616ab831d2e2ce63d9ee2;

// Address of the RIP7755Registry contract
IRIP7755Registry private _registry;

/// @notice Event emitted when a cross chain call is fulfilled
/// @param requestHash The keccak256 hash of a `CrossChainRequest`
/// @param fulfilledBy The account that fulfilled the cross chain call
Expand All @@ -42,9 +46,16 @@ contract RIP7755Verifier {
/// @notice This error is thrown when an account submits a cross chain call with a `verifyingContract` different than this contract's address
error InvalidVerifyingContract();

/// @notice This error is thrown when an account submits a cross chain call with a `originationContract` untrusted contract's address
error UntrustedOriginationContract();

/// @notice This error is thrown when an account attempts to submit a cross chain call that has already been fulfilled
error CallAlreadyFulfilled();

constructor(IRIP7755Registry registry) {
_registry = registry;
}

/// @notice Returns the stored fulfillment info for a passed in call hash
///
/// @param requestHash A keccak256 hash of a CrossChainRequest
Expand Down Expand Up @@ -72,7 +83,10 @@ contract RIP7755Verifier {
IPrecheckContract(request.precheckContract).precheckCall(request, msg.sender);
}

// TODO: Check for trusted originationContract
// Check for trusted originationContract
if (!IRIP7755Registry(_registry).checkTrustedContract(request.originationContract)) {
revert UntrustedOriginationContract();
}

bytes32 requestHash = hashRequest(request);

Expand Down