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

Each message sender can request customizable optimistic latency #34

Merged
merged 15 commits into from
Jul 4, 2022
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
1 change: 1 addition & 0 deletions .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,7 @@ jobs:
# Path to your GolangCI-Lint config within the repo (optional)
config: ${{ env.GITHUB_WORKSPACE }}/.golangci.yml
# see: https://github.com/golangci/golangci-lint/issues/2654
args: --timeout=5m
env:
# GitHub token for annotations (optional)
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
56 changes: 46 additions & 10 deletions packages/contracts/contracts/Home.sol
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ pragma solidity 0.8.13;

// ============ Internal Imports ============
import { Version0 } from "./Version0.sol";
import { SynapseBase } from "./SynapseBase.sol";
import { UpdaterStorage } from "./UpdaterStorage.sol";
import { QueueLib } from "./libs/Queue.sol";
import { MerkleLib } from "./libs/Merkle.sol";
import { Message } from "./libs/Message.sol";
Expand All @@ -23,12 +23,26 @@ import { Address } from "@openzeppelin/contracts/utils/Address.sol";
* Accepts submissions of fraudulent signatures
* by the Updater and slashes the Updater in this case.
*/
contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
contract Home is Version0, QueueManager, MerkleTreeManager, UpdaterStorage {
// ============ Libraries ============

using QueueLib for QueueLib.Queue;
using MerkleLib for MerkleLib.Tree;

// ============ Enums ============

// States:
// 0 - UnInitialized - before initialize function is called
// note: the contract is initialized at deploy time, so it should never be in this state
// 1 - Active - as long as the contract has not become fraudulent
// 2 - Failed - after a valid fraud proof has been submitted;
// contract will no longer accept updates or new messages
enum States {
UnInitialized,
Active,
Failed
}

// ============ Constants ============

// Maximum bytes per message = 2 KiB
Expand All @@ -41,11 +55,15 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
mapping(uint32 => uint32) public nonces;
// contract responsible for Updater bonding, slashing and rotation
IUpdaterManager public updaterManager;
// Current state of contract
States public state;
// The latest root that has been signed by the Updater
bytes32 public committedRoot;

// ============ Upgrade Gap ============

// gap for upgrade safety
uint256[48] private __GAP;
uint256[46] private __GAP;

// ============ Events ============

Expand Down Expand Up @@ -103,7 +121,7 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {

// ============ Constructor ============

constructor(uint32 _localDomain) SynapseBase(_localDomain) {} // solhint-disable-line no-empty-blocks
constructor(uint32 _localDomain) UpdaterStorage(_localDomain) {} // solhint-disable-line no-empty-blocks

// ============ Initializer ============

Expand All @@ -112,6 +130,7 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
__QueueManager_initialize();
_setUpdaterManager(_updaterManager);
__SynapseBase_initialize(updaterManager.updater());
state = States.Active;
}

// ============ Modifiers ============
Expand Down Expand Up @@ -170,6 +189,7 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
function dispatch(
uint32 _destinationDomain,
bytes32 _recipientAddress,
uint32 _optimisticSeconds,
bytes memory _messageBody
) external notFailed {
require(_messageBody.length <= MAX_MESSAGE_BODY_BYTES, "msg too long");
Expand All @@ -183,6 +203,7 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
_nonce,
_destinationDomain,
_recipientAddress,
_optimisticSeconds,
_messageBody
);
// insert the hashed message into the Merkle tree
Expand Down Expand Up @@ -263,24 +284,24 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {
bytes calldata _signature2
) external notFailed {
if (
SynapseBase._isUpdaterSignature(_oldRoot, _newRoot[0], _signature) &&
SynapseBase._isUpdaterSignature(_oldRoot, _newRoot[1], _signature2) &&
_isUpdaterSignature(_oldRoot, _newRoot[0], _signature) &&
_isUpdaterSignature(_oldRoot, _newRoot[1], _signature2) &&
_newRoot[0] != _newRoot[1]
) {
_fail();
emit DoubleUpdate(_oldRoot, _newRoot, _signature, _signature2);
}
}

// ============ Public Functions ============

/**
* @notice Hash of Home domain concatenated with "SYN"
*/
function homeDomainHash() public view override returns (bytes32) {
return _homeDomainHash(localDomain);
function homeDomainHash() external view returns (bytes32) {
return _domainHash(localDomain);
}

// ============ Public Functions ============

/**
* @notice Check if an Update is an Improper Update;
* if so, slash the Updater and set the contract to FAILED state.
Expand Down Expand Up @@ -329,6 +350,21 @@ contract Home is Version0, QueueManager, MerkleTreeManager, SynapseBase {

// ============ Internal Functions ============

/**
* @notice Checks that signature was signed by Updater on the local chain
* @param _oldRoot Old merkle root
* @param _newRoot New merkle root
* @param _signature Signature on `_oldRoot` and `_newRoot`
* @return TRUE if signature is valid signed by updater
**/
function _isUpdaterSignature(
bytes32 _oldRoot,
bytes32 _newRoot,
bytes memory _signature
) internal view returns (bool) {
return _isUpdaterSignature(localDomain, _oldRoot, _newRoot, _signature);
}

/**
* @notice Set the UpdaterManager
* @param _updaterManager Address of the UpdaterManager
Expand Down
Loading