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

Make merkle proofs optional on multisig ISM #2173

Merged
merged 45 commits into from
May 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
f153063
Make merkle proofs optional on multisig ISM
yorhodes May 4, 2023
d338321
Fix tests
yorhodes May 4, 2023
1376094
Optimize calldata usage and memory expansion
yorhodes May 4, 2023
cecefc9
Update gas snapshot
yorhodes May 4, 2023
c04cd4e
Reorganize metadata suffix
yorhodes May 4, 2023
53019b6
Improve test coverage of multisig ism
yorhodes May 4, 2023
39b7389
Fix legacy ism tests
yorhodes May 4, 2023
a4182fa
Remove implicit return
yorhodes May 4, 2023
6878335
Make metadata property names more descriptive
yorhodes May 4, 2023
9497aca
Reorganize metadata suffix (again)
yorhodes May 5, 2023
1b270e1
Make index optional in merkle path
yorhodes May 5, 2023
c35949f
Fix optional metadata
yorhodes May 5, 2023
0ac040f
Separate merkle root and message ID multisig ISMs
yorhodes May 9, 2023
ac1f886
Fix message ID ism tests
yorhodes May 9, 2023
9220ffb
Update gas snapshot
yorhodes May 9, 2023
a8f5bc7
Update SDK
yorhodes May 10, 2023
94ce778
Update infra
yorhodes May 10, 2023
fba016b
Fix sdk tests
yorhodes May 10, 2023
c295000
Update natspec
yorhodes May 10, 2023
1f3780f
More PR comments
yorhodes May 15, 2023
31df88a
Deploy both multisig flavors in SDK
yorhodes May 15, 2023
e85deb7
Complete natspec
yorhodes May 15, 2023
7ab788c
Fix solhint
yorhodes May 15, 2023
ce103cf
Update test addresses with new ISMs
yorhodes May 15, 2023
dc88f11
Update validators with new signature scheme (#2187)
yorhodes May 23, 2023
c130224
Merge branch 'main' into optional-merkle
yorhodes May 23, 2023
5c23e5a
Fix rust lint
yorhodes May 23, 2023
eb26ab1
Validator only signs once tree is consistent
yorhodes May 24, 2023
2fa9df7
Address pr comments
yorhodes May 24, 2023
06eab5c
Cleanup diff
yorhodes May 24, 2023
5831604
Address more pr comments
yorhodes May 24, 2023
3c69ff6
Fix infra build
yorhodes May 24, 2023
1241afe
Remove message_id check from merkle root builder
yorhodes May 24, 2023
254991d
Adjust instrumented logs
yorhodes May 24, 2023
08dbc45
Fix fragile target logic
yorhodes May 24, 2023
f698c1d
Fix lint
yorhodes May 24, 2023
a5225b2
Address contract pr comments
yorhodes May 24, 2023
4dda113
Address rust pr comments
yorhodes May 24, 2023
e027a24
Address more rust pr comments
yorhodes May 24, 2023
da1d78a
Address more rust pr comments
yorhodes May 24, 2023
08022e7
Address sdk pr comments
yorhodes May 24, 2023
1b584f7
Sleep for max u64 when backfill is done
yorhodes May 24, 2023
3e1af6b
Merge branch 'main' into optional-merkle
yorhodes May 24, 2023
73b0cb0
Fix lint again
yorhodes May 24, 2023
ff85708
Merge branch 'main' into optional-merkle
yorhodes May 25, 2023
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
3 changes: 3 additions & 0 deletions .github/workflows/e2e.yml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,9 @@ jobs:
toolchain: stable
profile: minimal

- name: Install Foundry
uses: onbjerg/foundry-toolchain@v1

- name: rust cache
uses: Swatinem/rust-cache@v2
with:
Expand Down
3 changes: 3 additions & 0 deletions rust/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions rust/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ async-trait = { version = "0.1" }
color-eyre = { version = "0.6" }
config = "~0.13.3"
derive-new = "0.5"
derive_more = "0.99"
enum_dispatch = "0.3"
ethers = { git = "https://github.com/hyperlane-xyz/ethers-rs", tag = "2023-02-10-01" }
ethers-contract = { git = "https://github.com/hyperlane-xyz/ethers-rs", tag = "2023-02-10-01", features = ["legacy"] }
Expand Down
1 change: 1 addition & 0 deletions rust/agents/relayer/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ hyperlane-base = { path = "../../hyperlane-base" }
hyperlane-ethereum = { path = "../../chains/hyperlane-ethereum" }
num-derive.workspace = true
num-traits.workspace = true
derive_more.workspace = true

[dev-dependencies]
tokio-test = "0.4"
Expand Down
83 changes: 36 additions & 47 deletions rust/agents/relayer/src/msg/metadata/base.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,39 +5,33 @@ use std::{collections::HashMap, fmt::Debug};
use async_trait::async_trait;
use derive_new::new;
use eyre::{Context, Result};
use num_derive::FromPrimitive;
use num_traits::FromPrimitive;
use tokio::sync::RwLock;
use tracing::{debug, instrument, warn};
use tracing::{debug, info, instrument, warn};

use hyperlane_base::{
ChainConf, CheckpointSyncer, CheckpointSyncerConf, CoreMetrics, MultisigCheckpointSyncer,
};
use hyperlane_core::accumulator::merkle::Proof;
use hyperlane_core::{
HyperlaneDomain, HyperlaneMessage, MultisigIsm, MultisigSignedCheckpoint, RoutingIsm,
Checkpoint, HyperlaneDomain, HyperlaneMessage, ModuleType, MultisigIsm, RoutingIsm,
ValidatorAnnounce, H160, H256,
};

use crate::merkle_tree_builder::MerkleTreeBuilder;
use crate::msg::metadata::{MultisigIsmMetadataBuilder, RoutingIsmMetadataBuilder};
use crate::msg::metadata::multisig::{
LegacyMultisigMetadataBuilder, MerkleRootMultisigMetadataBuilder,
MessageIdMultisigMetadataBuilder,
};
use crate::msg::metadata::RoutingIsmMetadataBuilder;

#[derive(Debug, thiserror::Error)]
pub enum MetadataBuilderError {
#[error("Unknown or invalid module type ({0})")]
UnsupportedModuleType(u8),
UnsupportedModuleType(ModuleType),
#[error("Exceeded max depth when building metadata ({0})")]
MaxDepthExceeded(u32),
}

#[derive(FromPrimitive, Clone, Debug)]
pub enum SupportedIsmTypes {
Routing = 1,
// Aggregation = 2,
LegacyMultisig = 3,
Multisig = 4,
}

#[async_trait]
pub trait MetadataBuilder: Send + Sync {
#[allow(clippy::async_yields_async)]
Expand Down Expand Up @@ -71,7 +65,7 @@ impl Debug for BaseMetadataBuilder {

#[async_trait]
impl MetadataBuilder for BaseMetadataBuilder {
#[instrument(err, skip(self))]
#[instrument(err, skip(self), fields(domain=self.domain().name()))]
async fn build(
&self,
ism_address: H256,
Expand All @@ -84,17 +78,16 @@ impl MetadataBuilder for BaseMetadataBuilder {
.await
.context(CTX)?;
let module_type = ism.module_type().await.context(CTX)?;
let supported_type = SupportedIsmTypes::from_u8(module_type)
.ok_or(MetadataBuilderError::UnsupportedModuleType(module_type))
.context(CTX)?;
let base = self.clone_with_incremented_depth()?;

let metadata_builder: Box<dyn MetadataBuilder> = match supported_type {
SupportedIsmTypes::Multisig => Box::new(MultisigIsmMetadataBuilder::new(base, false)),
SupportedIsmTypes::LegacyMultisig => {
Box::new(MultisigIsmMetadataBuilder::new(base, true))
let metadata_builder: Box<dyn MetadataBuilder> = match module_type {
ModuleType::LegacyMultisig => Box::new(LegacyMultisigMetadataBuilder::new(base)),
ModuleType::MerkleRootMultisig => {
Box::new(MerkleRootMultisigMetadataBuilder::new(base))
}
SupportedIsmTypes::Routing => Box::new(RoutingIsmMetadataBuilder::new(base)),
ModuleType::MessageIdMultisig => Box::new(MessageIdMultisigMetadataBuilder::new(base)),
ModuleType::Routing => Box::new(RoutingIsmMetadataBuilder::new(base)),
_ => return Err(MetadataBuilderError::UnsupportedModuleType(module_type).into()),
};
metadata_builder
.build(ism_address, message)
Expand All @@ -118,35 +111,31 @@ impl BaseMetadataBuilder {
}
}

pub async fn get_proof(
&self,
message: &HyperlaneMessage,
checkpoint: MultisigSignedCheckpoint,
) -> Result<Proof> {
pub async fn get_proof(&self, nonce: u32, checkpoint: Checkpoint) -> Result<Option<Proof>> {
const CTX: &str = "When fetching message proof";
self.origin_prover_sync
let proof = self
.origin_prover_sync
.read()
.await
.get_proof(message.nonce, checkpoint.checkpoint.index)
.context(CTX)
.get_proof(nonce, checkpoint.index)
.context(CTX)?;

// checkpoint may be fraudulent if the root does not
// match the canonical root at the checkpoint's index
if proof.root() != checkpoint.root {
yorhodes marked this conversation as resolved.
Show resolved Hide resolved
info!(
?checkpoint,
canonical_root = ?proof.root(),
"Could not fetch metadata: checkpoint root does not match canonical root from merkle proof"
);
Ok(None)
} else {
Ok(Some(proof))
}
}

pub async fn fetch_checkpoint(
&self,
validators: &Vec<H256>,
threshold: usize,
message: &HyperlaneMessage,
) -> Result<Option<MultisigSignedCheckpoint>> {
const CTX: &str = "When fetching checkpoint signatures";
let highest_known_nonce = self.origin_prover_sync.read().await.count() - 1;
let checkpoint_syncer = self
.build_checkpoint_syncer(validators)
.await
.context(CTX)?;
checkpoint_syncer
.fetch_checkpoint_in_range(validators, threshold, message.nonce, highest_known_nonce)
.await
.context(CTX)
pub async fn highest_known_nonce(&self) -> u32 {
self.origin_prover_sync.read().await.count() - 1
}

pub async fn build_routing_ism(&self, address: H256) -> Result<Box<dyn RoutingIsm>> {
Expand Down
1 change: 0 additions & 1 deletion rust/agents/relayer/src/msg/metadata/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ mod routing;

pub(crate) use base::BaseMetadataBuilder;
pub(crate) use base::MetadataBuilder;
use multisig::MultisigIsmMetadataBuilder;
use routing::RoutingIsmMetadataBuilder;
185 changes: 0 additions & 185 deletions rust/agents/relayer/src/msg/metadata/multisig.rs

This file was deleted.

Loading