Skip to content

Commit

Permalink
Merge branch 'master' into fix/docs-and-interface
Browse files Browse the repository at this point in the history
  • Loading branch information
trajan0x committed May 12, 2024
2 parents deac934 + 9b4ae6f commit e325176
Show file tree
Hide file tree
Showing 166 changed files with 5,876 additions and 5,111 deletions.
52 changes: 52 additions & 0 deletions packages/contracts-communication/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,58 @@
All notable changes to this project will be documented in this file.
See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.

## [1.7.1](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.7.0...contracts-communication@1.7.1) (2024-05-12)

**Note:** Version bump only for package contracts-communication





# [1.7.0](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.6.2...contracts-communication@1.7.0) (2024-05-11)


### Features

* **contracts-communication:** default values for modules/required respones ([#2612](https://github.com/synapsecns/sanguine/issues/2612)) ([2fcf06d](https://github.com/synapsecns/sanguine/commit/2fcf06dc2f74d610263973c028e233402e339312))





## [1.6.2](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.6.1...contracts-communication@1.6.2) (2024-05-10)


### Bug Fixes

* **contracts-communication:** default settings for Guard service ([#2605](https://github.com/synapsecns/sanguine/issues/2605)) ([f4ee9d0](https://github.com/synapsecns/sanguine/commit/f4ee9d0260300289c5708586b5e75a53961a8ef2))





## [1.6.1](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.6.0...contracts-communication@1.6.1) (2024-05-09)


### Bug Fixes

* **contracts-communication:** interchain module ignore nonces ([#2604](https://github.com/synapsecns/sanguine/issues/2604)) ([be4351b](https://github.com/synapsecns/sanguine/commit/be4351be2a5954e6d2c11471b5e93de99b3e42b6))





# [1.6.0](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.5.4...contracts-communication@1.6.0) (2024-05-09)


### Features

* **contracts-communication:** remove batching ([#2599](https://github.com/synapsecns/sanguine/issues/2599)) ([e6588f7](https://github.com/synapsecns/sanguine/commit/e6588f7dab0d4314e1c18b834708264177abdc7a))





## [1.5.4](https://github.com/synapsecns/sanguine/compare/contracts-communication@1.5.3...contracts-communication@1.5.4) (2024-05-08)

**Note:** Version bump only for package contracts-communication
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"latestInterchainClient": "InterchainClientV1",
"trustedModules": ["SynapseModule"],
"appConfig": {
"0_requiredResponses": 1,
"1_optimisticPeriod": 30
"requiredResponses": 1,
"optimisticPeriod": 30
},
"messageLengthEstimate": 1024
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
"latestInterchainClient": "InterchainClientV1",
"trustedModules": ["SynapseModule"],
"appConfig": {
"0_requiredResponses": 1,
"1_optimisticPeriod": 30
"requiredResponses": 1,
"optimisticPeriod": 30
},
"gasLimit": 500000
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"claimFeeBPS": 10,
"feeCollector": "0xAe61329Ce0AfFA55A7174916214fC2560a1CdD9f",
"feeRecipient": "0xAe61329Ce0AfFA55A7174916214fC2560a1CdD9f",
"gasOracleName": "SynapseGasOracleV1",
"threshold": 6,
"verifiers": [
Expand Down
194 changes: 95 additions & 99 deletions packages/contracts-communication/contracts/InterchainClientV1.sol

Large diffs are not rendered by default.

356 changes: 118 additions & 238 deletions packages/contracts-communication/contracts/InterchainDB.sol

Large diffs are not rendered by default.

17 changes: 3 additions & 14 deletions packages/contracts-communication/contracts/apps/AbstractICApp.sol
Original file line number Diff line number Diff line change
Expand Up @@ -25,19 +25,9 @@ abstract contract AbstractICApp is AbstractICAppEvents, IInterchainApp {
/// @dev App is responsible for keeping track of interchain clients, and must verify the message sender.
/// @param srcChainId Chain ID of the source chain, where the message was sent from.
/// @param sender Sender address on the source chain, as a bytes32 value.
/// @param dbNonce The Interchain DB nonce of the batch containing the message entry.
/// @param entryIndex The index of the message entry within the batch.
/// @param dbNonce The Interchain DB nonce of the message entry.
/// @param message The message being sent.
function appReceive(
uint64 srcChainId,
bytes32 sender,
uint64 dbNonce,
uint64 entryIndex,
bytes calldata message
)
external
payable
{
function appReceive(uint64 srcChainId, bytes32 sender, uint64 dbNonce, bytes calldata message) external payable {
if (!_isInterchainClient(msg.sender)) {
revert InterchainApp__CallerNotInterchainClient(msg.sender);
}
Expand All @@ -47,7 +37,7 @@ abstract contract AbstractICApp is AbstractICAppEvents, IInterchainApp {
if (!_isAllowedSender(srcChainId, sender)) {
revert InterchainApp__SrcSenderNotAllowed(srcChainId, sender);
}
_receiveMessage(srcChainId, sender, dbNonce, entryIndex, message);
_receiveMessage(srcChainId, sender, dbNonce, message);
}

/// @notice Returns the verification configuration of the Interchain App.
Expand Down Expand Up @@ -173,7 +163,6 @@ abstract contract AbstractICApp is AbstractICAppEvents, IInterchainApp {
uint64 srcChainId,
bytes32 sender,
uint64 dbNonce,
uint64 entryIndex,
bytes calldata message
)
internal
Expand Down
8 changes: 4 additions & 4 deletions packages/contracts-communication/contracts/apps/ICAppV1.sol
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {AbstractICApp, InterchainTxDescriptor} from "./AbstractICApp.sol";

import {InterchainAppV1Events} from "../events/InterchainAppV1Events.sol";
import {IInterchainAppV1} from "../interfaces/IInterchainAppV1.sol";
import {AppConfigV1, APP_CONFIG_GUARD_DEFAULT} from "../libs/AppConfig.sol";
import {AppConfigV1, APP_CONFIG_GUARD_DISABLED} from "../libs/AppConfig.sol";
import {OptionsV1} from "../libs/Options.sol";
import {TypeCasts} from "../libs/TypeCasts.sol";

Expand Down Expand Up @@ -107,7 +107,7 @@ abstract contract ICAppV1 is AbstractICApp, AccessControlEnumerable, InterchainA
/// - requiredResponses: the number of module responses required for accepting the message
/// - optimisticPeriod: the minimum time after which the module responses are considered final
function setAppConfigV1(uint256 requiredResponses, uint256 optimisticPeriod) external onlyRole(IC_GOVERNOR_ROLE) {
if (requiredResponses == 0 || optimisticPeriod == 0) {
if (requiredResponses == 0) {
revert InterchainApp__AppConfigInvalid(requiredResponses, optimisticPeriod);
}
_requiredResponses = SafeCast.toUint16(requiredResponses);
Expand Down Expand Up @@ -253,9 +253,9 @@ abstract contract ICAppV1 is AbstractICApp, AccessControlEnumerable, InterchainA
}

/// @dev Returns the guard flag and address in the app config.
/// By default, the ICApp is using the Client-provided guard, but it can be overridden in the derived contract.
/// By default, the ICApp does not opt in for any guard, but it can be overridden in the derived contracts.
function _getGuardConfig() internal view virtual returns (uint8 guardFlag, address guard) {
return (APP_CONFIG_GUARD_DEFAULT, address(0));
return (APP_CONFIG_GUARD_DISABLED, address(0));
}

/// @dev Returns the address of the Execution Service to use for sending messages.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import {OptionsV1} from "../../libs/Options.sol";
import {Address} from "@openzeppelin/contracts/utils/Address.sol";

contract ExampleAppV1 is ICAppV1 {
event MessageReceived(uint64 srcChainId, bytes32 sender, uint64 dbNonce, uint64 entryIndex, bytes message);
event MessageSent(uint64 dstChainId, uint64 dbNonce, uint64 entryIndex, bytes32 transactionId);
event MessageReceived(uint64 srcChainId, bytes32 sender, uint64 dbNonce, bytes message);
event MessageSent(uint64 dstChainId, uint64 dbNonce, bytes32 transactionId);

constructor(address admin) ICAppV1(admin) {
_grantRole(IC_GOVERNOR_ROLE, admin);
Expand All @@ -37,7 +37,7 @@ contract ExampleAppV1 is ICAppV1 {
options: OptionsV1({gasLimit: gasLimit, gasAirdrop: gasAirdrop}),
message: message
});
emit MessageSent(dstChainId, desc.dbNonce, desc.entryIndex, desc.transactionId);
emit MessageSent(dstChainId, desc.dbNonce, desc.transactionId);
}

/// @notice Returns the fee required to send a message using `sendMessage`.
Expand All @@ -59,12 +59,11 @@ contract ExampleAppV1 is ICAppV1 {
uint64 srcChainId,
bytes32 sender,
uint64 dbNonce,
uint64 entryIndex,
bytes calldata message
)
internal
override
{
emit MessageReceived(srcChainId, sender, dbNonce, entryIndex, message);
emit MessageReceived(srcChainId, sender, dbNonce, message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ pragma solidity 0.8.20;

import {ICAppV1} from "../ICAppV1.sol";

import {APP_CONFIG_GUARD_DEFAULT} from "../../libs/AppConfig.sol";
import {InterchainTxDescriptor} from "../../libs/InterchainTransaction.sol";
import {OptionsV1} from "../../libs/Options.sol";

Expand All @@ -16,8 +17,8 @@ contract PingPongApp is ICAppV1 {

event GasLimitSet(uint256 gasLimit);
event PingDisrupted(uint256 counter);
event PingReceived(uint256 counter, uint64 dbNonce, uint64 entryIndex);
event PingSent(uint256 counter, uint64 dbNonce, uint64 entryIndex);
event PingReceived(uint256 counter, uint64 dbNonce);
event PingSent(uint256 counter, uint64 dbNonce);

constructor(address admin) ICAppV1(admin) {
_grantRole(IC_GOVERNOR_ROLE, admin);
Expand Down Expand Up @@ -55,14 +56,13 @@ contract PingPongApp is ICAppV1 {
uint64 srcChainId,
bytes32, // sender
uint64 dbNonce,
uint64 entryIndex,
bytes calldata message
)
internal
override
{
uint256 counter = abi.decode(message, (uint256));
emit PingReceived(counter, dbNonce, entryIndex);
emit PingReceived(counter, dbNonce);
if (counter > 0) {
// Don't revert if the balance is low, just stop sending messages.
_sendPingPongMessage({dstChainId: srcChainId, counter: counter - 1, lowBalanceRevert: false});
Expand All @@ -81,12 +81,19 @@ contract PingPongApp is ICAppV1 {
return;
}
InterchainTxDescriptor memory desc = _sendToLinkedApp(dstChainId, messageFee, options, message);
emit PingSent(counter, desc.dbNonce, desc.entryIndex);
emit PingSent(counter, desc.dbNonce);
}

/// @dev Sets the gas limit for the interchain messages.
function _setGasLimit(uint256 gasLimit_) internal {
gasLimit = gasLimit_;
emit GasLimitSet(gasLimit_);
}

/// @dev Returns the guard flag and address in the app config.
/// By default, the ICApp does not opt in for any guard, but it can be overridden in the derived contracts.
/// PingPong app opts in for the default guard.
function _getGuardConfig() internal pure override returns (uint8 guardFlag, address guard) {
return (APP_CONFIG_GUARD_DEFAULT, address(0));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@
pragma solidity ^0.8.0;

abstract contract InterchainClientV1Events {
/// @notice Emitted when the Guard module is set.
/// @param guard The address of the Guard module.
/// @notice Emitted when the default Guard module is set.
/// @param guard The address of the Guard module that will be used by default.
event DefaultGuardSet(address guard);

/// @notice Emitted when the default Module is set.
/// @param module The address of the Module that will be used by default.
event DefaultModuleSet(address module);

/// @notice Emitted when the InterchainClientV1 deployment on a remote chain is linked.
/// @param chainId The chain ID of the remote chain.
/// @param client The address of the InterchainClientV1 deployment on the remote chain.
Expand All @@ -14,19 +18,17 @@ abstract contract InterchainClientV1Events {
/// @notice Emitted when a new interchain transaction is sent through the InterchainClientV1.
/// The Receiver on the destination chain will receive the specified message once the transaction is executed.
/// @param transactionId The unique identifier of the interchain transaction.
/// @param dbNonce The nonce of batch containing the transaction's DB entry.
/// @param entryIndex The index of the transaction's DB entry in the batch.
/// @param dbNonce The nonce of entry containing the transaction.
/// @param dstChainId The chain ID of the destination chain.
/// @param srcSender The sender of the transaction on the source chain.
/// @param dstReceiver The receiver of the transaction on the destination chain.
/// @param verificationFee The fee paid to verify the batch on the destination chain.
/// @param verificationFee The fee paid to verify the entry on the destination chain.
/// @param executionFee The fee paid to execute the transaction on the destination chain.
/// @param options The execution options for the transaction.
/// @param message The payload of the message being sent.
event InterchainTransactionSent(
bytes32 indexed transactionId,
uint64 dbNonce,
uint64 entryIndex,
uint64 dstChainId,
bytes32 indexed srcSender,
bytes32 indexed dstReceiver,
Expand All @@ -39,15 +41,13 @@ abstract contract InterchainClientV1Events {
/// @notice Emitted when an interchain transaction is received by the InterchainClientV1.
/// The Receiver on the destination chain has just received the message sent from the source chain.
/// @param transactionId The unique identifier of the interchain transaction.
/// @param dbNonce The nonce of batch containing the transaction's DB entry.
/// @param entryIndex The index of the transaction's DB entry in the batch.
/// @param dbNonce The nonce of entry containing the transaction.
/// @param srcChainId The chain ID of the source chain.
/// @param srcSender The sender of the transaction on the source chain.
/// @param dstReceiver The receiver of the transaction on the destination chain.
event InterchainTransactionReceived(
bytes32 indexed transactionId,
uint64 dbNonce,
uint64 entryIndex,
uint64 srcChainId,
bytes32 indexed srcSender,
bytes32 indexed dstReceiver
Expand All @@ -56,10 +56,7 @@ abstract contract InterchainClientV1Events {
/// @notice Emitted when the proof of execution is written to InterchainDB. This allows the source chain
/// to verify that the transaction was executed by a specific executor, if necessary.
/// @param transactionId The unique identifier of the interchain transaction.
/// @param dbNonce The nonce of batch containing the written proof's DB entry.
/// @param entryIndex The index of the written proof's DB entry in the batch.
/// @param dbNonce The nonce of entry containing the transaction.
/// @param executor The address of the executor that completed the transaction.
event ExecutionProofWritten(
bytes32 indexed transactionId, uint64 dbNonce, uint64 entryIndex, address indexed executor
);
event ExecutionProofWritten(bytes32 indexed transactionId, uint64 dbNonce, address indexed executor);
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,35 +3,25 @@ pragma solidity ^0.8.0;

abstract contract InterchainDBEvents {
/// @notice Emitted when a local entry is written to the database.
/// @param dbNonce The nonce of the batch containing the entry.
/// @param entryIndex The index of the entry within the batch.
/// @param srcWriter The address of the writer.
/// @param dataHash The written data hash.
event InterchainEntryWritten(
uint64 indexed dbNonce, uint64 entryIndex, bytes32 indexed srcWriter, bytes32 dataHash
);

/// @notice Emitted when a local batch is finalized.
/// @param dbNonce The nonce of the finalized batch.
/// @param batchRoot The Merkle root hash of the finalized batch.
event InterchainBatchFinalized(uint64 indexed dbNonce, bytes32 batchRoot);
/// @param dbNonce The nonce of the written entry.
/// @param srcWriter The address of the entry writer.
/// @param digest The written data digest.
/// @param entryValue The value of the written entry: keccak256(abi.encode(srcWriter, digest)).
event InterchainEntryWritten(uint64 indexed dbNonce, bytes32 indexed srcWriter, bytes32 digest, bytes32 entryValue);

/// @notice Emitted when a remote batch is verified by the Interchain Module.
/// @param module The address of the Interchain Module that verified the batch.
/// @notice Emitted when a remote entry is verified by the Interchain Module.
/// @param module The address of the Interchain Module that verified the entry.
/// @param srcChainId The ID of the source chain.
/// @param dbNonce The nonce of the verified batch.
/// @param batchRoot The Merkle root hash of the verified batch.
event InterchainBatchVerified(
address indexed module, uint64 indexed srcChainId, uint64 indexed dbNonce, bytes32 batchRoot
/// @param dbNonce The nonce of the verified entry.
/// @param entryValue The value of the verified entry: keccak256(abi.encode(srcWriter, digest)).
event InterchainEntryVerified(
address indexed module, uint64 indexed srcChainId, uint64 indexed dbNonce, bytes32 entryValue
);

/// @notice Emitted when a local batch is requested to be verified on a remote chain
/// @notice Emitted when a local entry is requested to be verified on a remote chain
/// using the set of Interchain Modules.
/// @param dstChainId The ID of the destination chain.
/// @param dbNonce The nonce of the batch to be verified.
/// @param batchRoot The Merkle root hash of the batch to be verified.
/// @param srcModules The addresses of the Interchain Modules that will verify the batch.
event InterchainBatchVerificationRequested(
uint64 indexed dstChainId, uint64 indexed dbNonce, bytes32 batchRoot, address[] srcModules
);
/// @param dbNonce The nonce of the entry to be verified.
/// @param srcModules The addresses of the Interchain Modules that will verify the entry.
event InterchainEntryVerificationRequested(uint64 indexed dstChainId, uint64 indexed dbNonce, address[] srcModules);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,15 @@
pragma solidity ^0.8.0;

abstract contract InterchainModuleEvents {
/// @notice Emitted when a batch verification on a remote chain is requested.
/// @notice Emitted when an entry verification on a remote chain is requested.
/// @param dstChainId The chain ID of the destination chain.
/// @param batch The encoded batch to be verified.
/// @param ethSignedBatchHash The digest of the batch (EIP-191 personal signed).
event BatchVerificationRequested(uint64 indexed dstChainId, bytes batch, bytes32 ethSignedBatchHash);
/// @param entry The encoded entry to be verified.
/// @param ethSignedEntryHash The digest of the entry (EIP-191 personal signed).
event EntryVerificationRequested(uint64 indexed dstChainId, bytes entry, bytes32 ethSignedEntryHash);

/// @notice Emitted when a batch from the remote chain is verified.
/// @notice Emitted when an entry from the remote chain is verified.
/// @param srcChainId The chain ID of the source chain.
/// @param batch The encoded batch that was verified.
/// @param ethSignedBatchHash The digest of the batch (EIP-191 personal signed).
event BatchVerified(uint64 indexed srcChainId, bytes batch, bytes32 ethSignedBatchHash);
/// @param entry The encoded entry that was verified.
/// @param ethSignedEntryHash The digest of the entry (EIP-191 personal signed).
event EntryVerified(uint64 indexed srcChainId, bytes entry, bytes32 ethSignedEntryHash);
}
Loading

0 comments on commit e325176

Please sign in to comment.