Skip to content

Commit

Permalink
undo prover abstraction
Browse files Browse the repository at this point in the history
  • Loading branch information
jackchuma committed Nov 22, 2024
1 parent 36d7292 commit 7360855
Show file tree
Hide file tree
Showing 22 changed files with 162 additions and 172 deletions.
2 changes: 1 addition & 1 deletion contracts/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

.PHONY: test

ARBITRUM_REQUEST_HASH = 0x8c1fcd779345380579a09056caba99fac6401a2c842b0582a5e3bc76e43a517f
ARBITRUM_REQUEST_HASH = 0xc57854ca0b344a5016d560b45dc207f1b32c3afbdbddb004ff574e493d015d0b
OPTIMISM_REQUEST_HASH = 0xe38ad8c9e84178325f28799eb3aaae72551b2eea7920c43d88854edd350719f5
FULFILLER_ADDRESS = 0x23214A0864FC0014CAb6030267738F01AFfdd547
MOCK_VERIFIER_ADDRESS = 0x49E2cDC9e81825B6C718ae8244fe0D5b062F4874
Expand Down
16 changes: 0 additions & 16 deletions contracts/script/DeployArbitrumProver.s.sol

This file was deleted.

16 changes: 0 additions & 16 deletions contracts/script/DeployOPStackProver.s.sol

This file was deleted.

16 changes: 0 additions & 16 deletions contracts/script/DeployRIP7755Outbox.s.sol

This file was deleted.

16 changes: 16 additions & 0 deletions contracts/script/DeployRIP7755OutboxToArbitrum.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {Script} from "forge-std/Script.sol";

import {RIP7755OutboxToArbitrum} from "../src/outboxes/RIP7755OutboxToArbitrum.sol";

contract DeployRIP7755OutboxToArbitrum is Script {
function run() external returns (RIP7755OutboxToArbitrum) {
vm.startBroadcast();
RIP7755OutboxToArbitrum outbox = new RIP7755OutboxToArbitrum();
vm.stopBroadcast();

return outbox;
}
}
16 changes: 16 additions & 0 deletions contracts/script/DeployRIP7755OutboxToOPStack.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// SPDX-License-Identifier: MIT
pragma solidity 0.8.24;

import {Script} from "forge-std/Script.sol";

import {RIP7755OutboxToOPStack} from "../src/outboxes/RIP7755OutboxToOPStack.sol";

contract DeployRIP7755OutboxToOPStack is Script {
function run() external returns (RIP7755OutboxToOPStack) {
vm.startBroadcast();
RIP7755OutboxToOPStack outbox = new RIP7755OutboxToOPStack();
vm.stopBroadcast();

return outbox;
}
}
1 change: 0 additions & 1 deletion contracts/script/actions/SubmitRequest.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ contract SubmitRequest is Script {
requester: 0x8C1a617BdB47342F9C17Ac8750E0b070c372C721,
calls: calls,
destinationChainId: 84532, // base sepolia chain ID
proverContract: 0x062fBdCfd17A0346D2A9d89FE233bbAdBd1DC14C,
inboxContract: 0xB482b292878FDe64691d028A2237B34e91c7c7ea, // RIP7755Inbox on Base Sepolia
l2Oracle: 0x4C8BA32A5DAC2A720bb35CeDB51D6B067D104205, // Base Sepolia AnchorStateRegistry on Sepolia
l2OracleStorageKey: 0xa6eef7e35abe7026729641147f7915573c7e97b47efa546f5f6e3230263bcb49, // AnchorStateRegistry storage slot
Expand Down
6 changes: 2 additions & 4 deletions contracts/script/chains/DeployArbitrum.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,16 @@ pragma solidity 0.8.24;

import {Script} from "forge-std/Script.sol";

import {OPStackProver} from "../../src/provers/OPStackProver.sol";
import {RIP7755OutboxToOPStack} from "../../src/outboxes/RIP7755OutboxToOPStack.sol";
import {RIP7755Inbox} from "../../src/RIP7755Inbox.sol";
import {RIP7755Outbox} from "../../src/RIP7755Outbox.sol";

contract DeployArbitrum is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

vm.startBroadcast(deployerPrivateKey);
new OPStackProver();
new RIP7755Inbox();
new RIP7755Outbox();
new RIP7755OutboxToOPStack();
vm.stopBroadcast();
}
}
10 changes: 4 additions & 6 deletions contracts/script/chains/DeployBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,18 @@ pragma solidity 0.8.24;

import {Script} from "forge-std/Script.sol";

import {ArbitrumProver} from "../../src/provers/ArbitrumProver.sol";
import {OPStackProver} from "../../src/provers/OPStackProver.sol";
import {RIP7755OutboxToArbitrum} from "../../src/outboxes/RIP7755OutboxToArbitrum.sol";
import {RIP7755OutboxToOPStack} from "../../src/outboxes/RIP7755OutboxToOPStack.sol";
import {RIP7755Inbox} from "../../src/RIP7755Inbox.sol";
import {RIP7755Outbox} from "../../src/RIP7755Outbox.sol";

contract DeployBase is Script {
function run() external {
uint256 deployerPrivateKey = vm.envUint("PRIVATE_KEY");

vm.startBroadcast(deployerPrivateKey);
new ArbitrumProver();
new OPStackProver();
new RIP7755Inbox();
new RIP7755Outbox();
new RIP7755OutboxToArbitrum();
new RIP7755OutboxToOPStack();
vm.stopBroadcast();
}
}
30 changes: 26 additions & 4 deletions contracts/src/RIP7755Outbox.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,16 @@ import {IERC20} from "openzeppelin-contracts/contracts/token/ERC20/IERC20.sol";
import {SafeERC20} from "openzeppelin-contracts/contracts/token/ERC20/utils/SafeERC20.sol";
import {Address} from "openzeppelin-contracts/contracts/utils/Address.sol";

import {IProver} from "./interfaces/IProver.sol";
import {RIP7755Inbox} from "./RIP7755Inbox.sol";
import {Call, CrossChainRequest} from "./RIP7755Structs.sol";
import {CrossChainRequest} from "./RIP7755Structs.sol";

/// @title RIP7755Outbox
///
/// @author Coinbase (https://github.com/base-org/RIP-7755-poc)
///
/// @notice A source contract for initiating RIP-7755 Cross Chain Requests as well as reward fulfillment to Fillers that
/// submit the cross chain calls to destination chains.
contract RIP7755Outbox {
abstract contract RIP7755Outbox {
using Address for address payable;
using SafeERC20 for IERC20;

Expand Down Expand Up @@ -126,7 +125,8 @@ contract RIP7755Outbox {

_checkValidStatus({requestHash: requestHash, expectedStatus: CrossChainCallStatus.Requested});

IProver(request.proverContract).validateProof(storageKey, fulfillmentInfo, request, proof);
_validateProof(storageKey, fulfillmentInfo, request, proof);

_requestStatus[requestHash] = CrossChainCallStatus.Completed;

_sendReward(request, payTo);
Expand Down Expand Up @@ -219,4 +219,26 @@ contract RIP7755Outbox {
_sendERC20(to, request.rewardAsset, request.rewardAmount);
}
}

/// @notice Validates storage proofs and verifies fill
///
/// @custom:reverts If storage proof invalid.
/// @custom:reverts If fillInfo not found at inboxContractStorageKey on crossChainCall.verifyingContract
/// @custom:reverts If fillInfo.timestamp is less than
/// crossChainCall.finalityDelaySeconds from current destination chain block timestamp.
///
/// @dev Implementation will vary by L2
///
/// @param inboxContractStorageKey The storage location of the data to verify on the destination chain
/// `RIP7755Inbox` contract
/// @param fulfillmentInfo The fulfillment info that should be located at `inboxContractStorageKey` in storage
/// on the destination chain `RIP7755Inbox` contract
/// @param request The original cross chain request submitted to this contract
/// @param proofData The proof to validate
function _validateProof(
bytes memory inboxContractStorageKey,
RIP7755Inbox.FulfillmentInfo calldata fulfillmentInfo,
CrossChainRequest calldata request,
bytes calldata proofData
) internal virtual;
}
2 changes: 0 additions & 2 deletions contracts/src/RIP7755Structs.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ struct CrossChainRequest {
address requester;
/// @dev Array of calls to make on the destination chain
Call[] calls;
/// @dev The source chain contract address that will verify state on the destination chain
address proverContract;
/// @dev The chainId of the destination chain
uint256 destinationChainId;
/// @dev The L2 contract on destination chain that's storage will be used to verify whether or not this call was made
Expand Down
32 changes: 0 additions & 32 deletions contracts/src/interfaces/IProver.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ pragma solidity 0.8.24;

import {RLPReader} from "optimism/packages/contracts-bedrock/src/libraries/rlp/RLPReader.sol";

import {IProver} from "../interfaces/IProver.sol";
import {StateValidator} from "../libraries/StateValidator.sol";
import {RIP7755Inbox} from "../RIP7755Inbox.sol";
import {RIP7755Outbox} from "../RIP7755Outbox.sol";
import {CrossChainRequest} from "../RIP7755Structs.sol";

/// @title ArbitrumProver
/// @title RIP7755OutboxToArbitrum
///
/// @author Coinbase (https://github.com/base-org/RIP-7755-poc)
///
/// @notice This contract implements storage proof validation to ensure that requested calls actually happened on Arbitrum
contract ArbitrumProver is IProver {
contract RIP7755OutboxToArbitrum is RIP7755Outbox {
using StateValidator for address;
using RLPReader for RLPReader.RLPItem;
using RLPReader for bytes;
Expand Down Expand Up @@ -71,12 +71,12 @@ contract ArbitrumProver is IProver {
/// on the destination chain `RIP7755Inbox` contract
/// @param request The original cross chain request submitted to this contract
/// @param proof The proof to validate
function validateProof(
function _validateProof(
bytes memory inboxContractStorageKey,
RIP7755Inbox.FulfillmentInfo calldata fulfillmentInfo,
CrossChainRequest calldata request,
bytes calldata proof
) external view {
) internal view override {
RIP7755Proof memory proofData = abi.decode(proof, (RIP7755Proof));

// Set the expected storage key and value for the `RIP7755Inbox` on Arbitrum
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@ pragma solidity 0.8.24;

import {RLPReader} from "optimism/packages/contracts-bedrock/src/libraries/rlp/RLPReader.sol";

import {IProver} from "../interfaces/IProver.sol";
import {StateValidator} from "../libraries/StateValidator.sol";
import {RIP7755Inbox} from "../RIP7755Inbox.sol";
import {RIP7755Outbox} from "../RIP7755Outbox.sol";
import {CrossChainRequest} from "../RIP7755Structs.sol";

/// @title RIP7755OutboxOPStackValidator
/// @title RIP7755OutboxToOPStack
///
/// @author Coinbase (https://github.com/base-org/RIP-7755-poc)
///
/// @notice This contract implements storage proof validation to ensure that requested calls actually happened on an OP Stack chain
contract OPStackProver is IProver {
contract RIP7755OutboxToOPStack is RIP7755Outbox {
using StateValidator for address;
using RLPReader for RLPReader.RLPItem;
using RLPReader for bytes;
Expand Down Expand Up @@ -68,12 +68,12 @@ contract OPStackProver is IProver {
/// on the destination chain `RIP7755Inbox` contract
/// @param request The original cross chain request submitted to this contract
/// @param proof The proof to validate
function validateProof(
function _validateProof(
bytes memory inboxContractStorageKey,
RIP7755Inbox.FulfillmentInfo calldata fulfillmentInfo,
CrossChainRequest calldata request,
bytes calldata proof
) external view {
) internal view override {
RIP7755Proof memory proofData = abi.decode(proof, (RIP7755Proof));

// Set the expected storage key and value for the `RIP7755Inbox` on the destination OP Stack chain
Expand Down
Loading

0 comments on commit 7360855

Please sign in to comment.