Skip to content
Merged
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
4 changes: 2 additions & 2 deletions contracts/apps/counter-inbox/CounterInboxAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@ contract CounterInboxAppGateway is AppGatewayBase {
uint32 chainSlug_,
Fees memory fees_
) AppGatewayBase(addressResolver_, auctionManager_) {
watcherPrecompile__().setIsValidInboxCaller(chainSlug_, address(counterInbox_), true);
watcherPrecompile__().setIsValidPlug(chainSlug_, address(counterInbox_), true);
_setOverrides(fees_);
}

function callFromInbox(
function callFromChain(
uint32,
address,
bytes calldata payload_,
Expand Down
2 changes: 1 addition & 1 deletion contracts/base/AppGatewayBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ abstract contract AppGatewayBase is AddressResolverUtil, IAppGateway, FeesPlugin
PayloadBatch memory payloadBatch_
) external virtual onlyDeliveryHelper {}

function callFromInbox(
function callFromChain(
uint32 chainSlug_,
address plug_,
bytes calldata payload_,
Expand Down
2 changes: 1 addition & 1 deletion contracts/interfaces/IAppGateway.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ interface IAppGateway {

function onBatchComplete(bytes32 asyncId_, PayloadBatch memory payloadBatch_) external;

function callFromInbox(
function callFromChain(
uint32 chainSlug_,
address plug_,
bytes calldata payload_,
Expand Down
4 changes: 2 additions & 2 deletions contracts/interfaces/ISocket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,8 @@ interface ISocket {
}

/**
* @notice To call the appGateway on offChainVM. Should only be called by a plug.
* @param payload_ bytes to be delivered to the Plug on offChainVM
* @notice To call the appGateway on EVMx. Should only be called by a plug.
* @param payload_ bytes to be delivered to the Plug on EVMx
* @param params_ a 32 bytes param to add details for execution.
*/
function callAppGateway(
Expand Down
6 changes: 3 additions & 3 deletions contracts/interfaces/ISwitchboard.sol
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ pragma solidity ^0.8.21;
interface ISwitchboard {
/**
* @notice Checks if a packet can be allowed to go through the switchboard.
* @param root_ the packet root.
* @param digest_ the packet digest.
* @param packetId_ The unique identifier for the packet.
* @return A boolean indicating whether the packet is allowed to go through the switchboard or not.
*/
function allowPacket(bytes32 root_, bytes32 packetId_) external view returns (bool);
function allowPacket(bytes32 digest_, bytes32 packetId_) external view returns (bool);

function attest(bytes32 payloadId_, bytes32 root_, bytes calldata signature_) external;
function attest(bytes32 payloadId_, bytes32 digest_, bytes calldata proof_) external;
}
24 changes: 12 additions & 12 deletions contracts/interfaces/IWatcherPrecompile.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// SPDX-License-Identifier: Unlicense
pragma solidity ^0.8.21;

import {PayloadDetails, AsyncRequest, FinalizeParams, PayloadRootParams, AppGatewayConfig, PlugConfig, ResolvedPromises} from "../protocol/utils/common/Structs.sol";
import {PayloadDetails, AsyncRequest, FinalizeParams, PayloadDigestParams, AppGatewayConfig, PlugConfig, ResolvedPromises} from "../protocol/utils/common/Structs.sol";

/// @title IWatcherPrecompile
/// @notice Interface for the Watcher Precompile system that handles payload verification and execution
Expand Down Expand Up @@ -36,11 +36,11 @@ interface IWatcherPrecompile {
/// @notice Finalizes a payload execution request
/// @param params_ Parameters needed for finalization
/// @return payloadId The unique identifier for the request
/// @return root The merkle root of the payload parameters
/// @return digest The digest of the payload parameters
function finalize(
address originAppGateway_,
FinalizeParams memory params_
) external returns (bytes32 payloadId, bytes32 root);
) external returns (bytes32 payloadId, bytes32 digest);

/// @notice Creates a new query request
/// @param chainSlug_ The identifier of the destination network
Expand All @@ -56,10 +56,10 @@ interface IWatcherPrecompile {
bytes memory payload_
) external returns (bytes32 payloadId);

/// @notice Marks a request as finalized with a signature
/// @notice Marks a request as finalized with a proof
/// @param payloadId_ The unique identifier of the request
/// @param signature_ The watcher's signature
function finalized(bytes32 payloadId_, bytes calldata signature_) external;
/// @param proof_ The watcher's proof
function finalized(bytes32 payloadId_, bytes calldata proof_) external;

/// @notice Finalizes multiple payload execution requests with a new transmitter
/// @param payloadId_ The unique identifier of the request
Expand All @@ -83,10 +83,10 @@ interface IWatcherPrecompile {
/// @param timeoutId_ The unique identifier for the timeout
function resolveTimeout(bytes32 timeoutId_) external;

/// @notice Calculates the root hash for payload parameters
/// @param params_ The payload parameters used to calculate the root
/// @return root The calculated merkle root hash
function getRoot(PayloadRootParams memory params_) external pure returns (bytes32 root);
/// @notice Calculates the Digest hash for payload parameters
/// @param params_ The payload parameters used to calculate the digest
/// @return digest The calculated digest hash
function getDigest(PayloadDigestParams memory params_) external pure returns (bytes32 digest);

function setMaxTimeoutDelayInSeconds(uint256 maxTimeoutDelayInSeconds_) external;

Expand All @@ -98,9 +98,9 @@ interface IWatcherPrecompile {

function feesPlug(uint32 chainSlug_) external view returns (address);

function setIsValidInboxCaller(uint32 chainSlug_, address plug_, bool isValid_) external;
function setIsValidPlug(uint32 chainSlug_, address plug_, bool isValid_) external;

function checkAndUpdateLimit(
function checkAndConsumeLimit(
address appGateway_,
bytes32 limitType_,
uint256 consumeLimit_
Expand Down
8 changes: 6 additions & 2 deletions contracts/mock/MockSocket.sol
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,13 @@ contract MockSocket is ISocket {
////////////////// INTERNAL FUNCS //////////////////////
////////////////////////////////////////////////////////

function _verify(bytes32 root_, bytes32 payloadId_, ISwitchboard switchboard__) internal view {
function _verify(
bytes32 digest_,
bytes32 payloadId_,
ISwitchboard switchboard__
) internal view {
// NOTE: is the the first un-trusted call in the system, another one is Plug.call
if (!switchboard__.allowPacket(root_, payloadId_)) revert VerificationFailed();
if (!switchboard__.allowPacket(digest_, payloadId_)) revert VerificationFailed();
}

/**
Expand Down
24 changes: 12 additions & 12 deletions contracts/mock/MockWatcherPrecompile.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import "../interfaces/IAppGateway.sol";
import "../interfaces/IWatcherPrecompile.sol";
import "../interfaces/IPromise.sol";

import {PayloadRootParams, AsyncRequest, FinalizeParams, TimeoutRequest, CallFromInboxParams, PlugConfig, ResolvedPromises, AppGatewayConfig} from "../protocol/utils/common/Structs.sol";
import {PayloadDigestParams, AsyncRequest, FinalizeParams, TimeoutRequest, CallFromChainParams, PlugConfig, ResolvedPromises, AppGatewayConfig} from "../protocol/utils/common/Structs.sol";
import {QUERY, FINALIZE, SCHEDULE} from "../protocol/utils/common/Constants.sol";
import {TimeoutDelayTooLarge, TimeoutAlreadyResolved, InvalidInboxCaller, ResolvingTimeoutTooEarly, CallFailed, AppGatewayAlreadyCalled} from "../protocol/utils/common/Errors.sol";
import "solady/utils/ERC1967Factory.sol";
Expand Down Expand Up @@ -57,8 +57,8 @@ contract MockWatcherPrecompile {
/// @notice Emitted when a request is finalized
/// @param payloadId The unique identifier for the request
/// @param asyncRequest The async request details
/// @param watcherSignature The signature from the watcher
event Finalized(bytes32 indexed payloadId, AsyncRequest asyncRequest, bytes watcherSignature);
/// @param proof The proof from the watcher
event Finalized(bytes32 indexed payloadId, AsyncRequest asyncRequest, bytes proof);

/// @notice Emitted when a promise is resolved
/// @param payloadId The unique identifier for the resolved promise
Expand Down Expand Up @@ -120,14 +120,14 @@ contract MockWatcherPrecompile {

// ================== Finalize functions ==================

/// @notice Finalizes a payload request, requests the watcher to release the signatures to execute on chain
/// @notice Finalizes a payload request, requests the watcher to release the proofs to execute on chain
/// @param params_ The finalization parameters
/// @return payloadId The unique identifier for the finalized request
/// @return root The merkle root of the payload parameters
/// @return digest The digest of the payload parameters
function finalize(
FinalizeParams memory params_
) external returns (bytes32 payloadId, bytes32 root) {
root = keccak256(abi.encode(block.timestamp));
) external returns (bytes32 payloadId, bytes32 digest) {
digest = keccak256(abi.encode(block.timestamp));
// Generate a unique payload ID by combining chain, target, and counter
payloadId = encodePayloadId(
params_.payloadDetails.chainSlug,
Expand Down Expand Up @@ -169,12 +169,12 @@ contract MockWatcherPrecompile {
emit QueryRequested(chainSlug, targetAddress, payloadId, payload);
}

/// @notice Marks a request as finalized with a signature
/// @notice Marks a request as finalized with a proof
/// @param payloadId_ The unique identifier of the request
/// @param signature_ The watcher's signature
/// @param proof_ The watcher's proof
/// @dev Only callable by the contract owner
function finalized(bytes32 payloadId_, bytes calldata signature_) external {
emit Finalized(payloadId_, asyncRequests[payloadId_], signature_);
function finalized(bytes32 payloadId_, bytes calldata proof_) external {
emit Finalized(payloadId_, asyncRequests[payloadId_], proof_);
}

/// @notice Resolves multiple promises with their return data
Expand All @@ -188,7 +188,7 @@ contract MockWatcherPrecompile {

// ================== On-Chain Inbox ==================

function callAppGateways(CallFromInboxParams[] calldata params_) external {
function callAppGateways(CallFromChainParams[] calldata params_) external {
for (uint256 i = 0; i < params_.length; i++) {
emit CalledAppGateway(
params_[i].callId,
Expand Down
4 changes: 2 additions & 2 deletions contracts/protocol/AddressResolver.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ contract AddressResolver is Ownable, IAddressResolver, Initializable {
mapping(address => address) public override gatewaysToContracts;

/// @notice Error thrown if AppGateway contract was already set by a different address
error AppGatewayContractAlreadySetByDifferentSender(address contractAddress_);
error InvalidAppGateway(address contractAddress_);

event PlugAdded(address appGateway, uint32 chainSlug, address plug);
event ForwarderDeployed(address newForwarder, bytes32 salt);
Expand Down Expand Up @@ -166,7 +166,7 @@ contract AddressResolver is Ownable, IAddressResolver, Initializable {
contractsToGateways[contractAddress_] != address(0) &&
contractsToGateways[contractAddress_] != msg.sender
) {
revert AppGatewayContractAlreadySetByDifferentSender(contractAddress_);
revert InvalidAppGateway(contractAddress_);
}
contractsToGateways[contractAddress_] = msg.sender;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import "solady/utils/Initializable.sol";
/// @title AuctionManager
/// @notice Contract for managing auctions and placing bids
contract AuctionManager is AddressResolverUtil, Ownable, IAuctionManager, Initializable {
uint32 public vmChainSlug;
uint32 public evmxSlug;
mapping(bytes32 => Bid) public winningBids;
// asyncId => auction status
mapping(bytes32 => bool) public override auctionClosed;
Expand All @@ -39,19 +39,19 @@ contract AuctionManager is AddressResolverUtil, Ownable, IAuctionManager, Initia
}

/// @notice Initializer function to replace constructor
/// @param vmChainSlug_ The chain slug for the VM
/// @param evmxSlug_ The chain slug for the VM
/// @param auctionEndDelaySeconds_ The delay in seconds before an auction can end
/// @param addressResolver_ The address of the address resolver
/// @param owner_ The address of the contract owner
function initialize(
uint32 vmChainSlug_,
uint32 evmxSlug_,
uint256 auctionEndDelaySeconds_,
address addressResolver_,
address owner_
) public reinitializer(1) {
_setAddressResolver(addressResolver_);
_initializeOwner(owner_);
vmChainSlug = vmChainSlug_;
evmxSlug = evmxSlug_;
auctionEndDelaySeconds = auctionEndDelaySeconds_;
}

Expand Down Expand Up @@ -84,7 +84,7 @@ contract AuctionManager is AddressResolverUtil, Ownable, IAuctionManager, Initia
if (auctionClosed[asyncId_]) revert AuctionClosed();

address transmitter = _recoverSigner(
keccak256(abi.encode(address(this), vmChainSlug, asyncId_, fee, extraData)),
keccak256(abi.encode(address(this), evmxSlug, asyncId_, fee, extraData)),
transmitterSignature
);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ abstract contract BatchAsync is QueueAsync {
event PayloadAsyncRequested(
bytes32 indexed asyncId,
bytes32 indexed payloadId,
bytes32 indexed root,
bytes32 indexed digest,
PayloadDetails payloadDetails
);

Expand Down Expand Up @@ -97,7 +97,7 @@ abstract contract BatchAsync is QueueAsync {
// Handle initial read operations first
uint256 readEndIndex = _processReadOperations(payloadDetails_, asyncId);

watcherPrecompile__().checkAndUpdateLimit(
watcherPrecompile__().checkAndConsumeLimit(
payloadDetails_[0].appGateway,
QUERY,
readEndIndex
Expand Down Expand Up @@ -182,6 +182,7 @@ abstract contract BatchAsync is QueueAsync {
uint256 readEndIndex,
bytes32 asyncId
) internal returns (address) {
// later changed to main app gateway if its a write call
address appGateway = msg.sender;

uint256 writes = 0;
Expand All @@ -203,13 +204,13 @@ abstract contract BatchAsync is QueueAsync {
payloadBatchDetails[asyncId].push(payloadDetails_[i]);
}

watcherPrecompile__().checkAndUpdateLimit(
watcherPrecompile__().checkAndConsumeLimit(
appGateway,
QUERY,
// remaining reads
payloadDetails_.length - writes - readEndIndex
);
watcherPrecompile__().checkAndUpdateLimit(appGateway, FINALIZE, writes);
watcherPrecompile__().checkAndConsumeLimit(appGateway, FINALIZE, writes);

return appGateway;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ contract DeliveryHelper is BatchAsync, Initializable {
PayloadBatch storage payloadBatch_,
address batchPromise_,
bool isRead_
) internal returns (bytes32 payloadId, bytes32 root) {
) internal returns (bytes32 payloadId, bytes32 digest) {
payloadDetails_.next[1] = batchPromise_;
if (isRead_) {
payloadId = watcherPrecompile__().query(
Expand All @@ -153,14 +153,14 @@ contract DeliveryHelper is BatchAsync, Initializable {
payloadDetails_.next,
payloadDetails_.payload
);
root = bytes32(0);
digest = bytes32(0);
} else {
FinalizeParams memory finalizeParams = FinalizeParams({
payloadDetails: payloadDetails_,
asyncId: asyncId_,
transmitter: payloadBatch_.winningBid.transmitter
});
(payloadId, root) = watcherPrecompile__().finalize(
(payloadId, digest) = watcherPrecompile__().finalize(
payloadBatch_.appGateway,
finalizeParams
);
Expand All @@ -170,7 +170,7 @@ contract DeliveryHelper is BatchAsync, Initializable {
payloadIdToBatchHash[payloadId] = asyncId_;
payloadIdToPayloadDetails[payloadId] = payloadDetails_;

emit PayloadAsyncRequested(asyncId_, payloadId, root, payloadDetails_);
emit PayloadAsyncRequested(asyncId_, payloadId, digest, payloadDetails_);
}

function _processParallelCalls(
Expand Down
Loading
Loading