Skip to content

Commit

Permalink
Verifier V1 [NUF-176] (#302)
Browse files Browse the repository at this point in the history
This patch adds Verifier V1 component as a part of DVN. In case, if received Packet was not verified, Verifier executes V1 verification algorithm:

- fetches state root from aggregator;
- fetches block state root by chain RPC API;
- compares them and says is message is gud.

As a part of this change, compilation error was fixed in indexer tests.
  • Loading branch information
Fly-Style authored Oct 28, 2024
1 parent 768a994 commit 2c9fc41
Show file tree
Hide file tree
Showing 12 changed files with 1,363 additions and 4,951 deletions.
5,968 changes: 1,039 additions & 4,929 deletions Cargo.lock

Large diffs are not rendered by default.

27 changes: 12 additions & 15 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@ resolver = "2"
members = [
"indexer",
"contracts/evm/test/ffi/bls-utils",
"relayer-rs",
"operator-rs",
"core-rs",
"workers",
]

Expand All @@ -19,26 +16,26 @@ repository = "https://github.com/NethermindEth/near-sffl"
[workspace.dependencies]
alloy = { version = "0.4.2", features = ["full", "node-bindings", "rpc-types-debug", "rpc-types-trace", "json-rpc", "rpc-client", "serde", "json-abi"] }
alloy-primitives = "0.8.3"
alloy-rlp = "0.3.8"
alloy-rpc-client = "0.4.2"
alloy-rpc-types = "0.4.2"
alloy-transport-ws = "0.4.2"
alloy-rlp = "0.3.8"
tokio = { version = "1.0", features = ["full"] }
anyhow = "1.0.79"
async-trait = "0.1"
bincode = "1.3"
clap = "4.5.18"
eyre = "0.6"
futures-util = "0.3.30"
log = "0.4"
prometheus = "0.13"
reqwest = "0.12.8"
serde = { version = "1.0", features = ["derive"] }
serde_json = "1.0"
anyhow = "1.0"
tracing = "0.1"
tracing-subscriber = "0.3"
futures-util = "0.3.30"
eyre = "0.6"
bincode = "1.3"
serde_yaml = "0.9"
clap = "4.5.18"
tempfile = "3.10.0"
async-trait = "0.1"
log = "0.4"
core-rs = { path = "core-rs" }
tokio = { version = "1", features = ["full"] }
tracing = "0.1"
tracing-subscriber = "0.3"

[patch.crates-io]
parity-secp256k1 = { git = 'https://github.com/paritytech/rust-secp256k1.git' }
3 changes: 3 additions & 0 deletions indexer/src/block_listener.rs
Original file line number Diff line number Diff line change
Expand Up @@ -338,6 +338,7 @@ mod tests {
gas: 100,
deposit: 100,
}],
priority_fee: 0,
signature: Signature::default(),
hash: CryptoHash::default(),
},
Expand All @@ -355,6 +356,7 @@ mod tests {
nonce: 0,
receiver_id: da_contract_id,
actions: vec![ActionView::CreateAccount],
priority_fee: 0,
signature: Signature::default(),
hash: CryptoHash::default(),
},
Expand Down Expand Up @@ -415,6 +417,7 @@ mod tests {
nonce: 0,
receiver_id: da_contract_id.clone(),
actions,
priority_fee: 0,
signature: Signature::default(),
hash: CryptoHash::hash_bytes(b"test_tx_id"),
},
Expand Down

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

4 changes: 4 additions & 0 deletions workers/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ bytes = "1.7.2"
config = { version = "0.14.0", features = ["toml"] }
eyre.workspace = true
futures = "0.3.31"
reqwest.workspace = true
serde.workspace = true
serde_json.workspace = true
tokio.workspace = true
tracing.workspace = true
tracing-subscriber = {workspace = true, features = ["env-filter"] }

[dev-dependencies]
wiremock = "0.6.2"
16 changes: 13 additions & 3 deletions workers/src/bin/dvn.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,18 @@
//! Main offchain workflow for Nuff DVN.
//! Main off-chain workflow for Nuff DVN.
use alloy::primitives::U256;
use eyre::{OptionExt, Result};
use futures::stream::StreamExt;
use tracing::{debug, error, info, warn};
use tracing_subscriber::EnvFilter;
use workers::data::dvn::Dvn;
use workers::verifier::NFFLVerifier;
use workers::{
abi::{L0V2EndpointAbi::PacketSent, SendLibraryAbi::DVNFeePaid},
chain::{
connections::{build_subscriptions, get_abi_from_path, get_http_provider},
contracts::{create_contract_instance, query_already_verified, query_confirmations, verify},
},
data::dvn::Dvn,
};

#[tokio::main]
Expand All @@ -23,6 +24,7 @@ async fn main() -> Result<()> {
.init();

let mut dvn_data = Dvn::new_from_env()?;
let verifier = NFFLVerifier::new_from_config(&dvn_data.config).await?;

// Create the WS subscriptions for listening to the events.
let (_provider, mut endpoint_stream, mut sendlib_stream) = build_subscriptions(&dvn_data.config).await?;
Expand Down Expand Up @@ -92,7 +94,15 @@ async fn main() -> Result<()> {
dvn_data.verifying();
debug!("Packet NOT verified. Calling verification.");

// FIXME: logic for NFFL verification
if log.block_number.is_none() {
error!("Block number is None, can't verify Packet.");
continue;
}

if !verifier.verify(log.block_number.unwrap()).await? {
error!("Failed to verify the state root.");
continue;
}

verify(
&receivelib_contract,
Expand Down
2 changes: 2 additions & 0 deletions workers/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ pub struct DVNConfig {
pub network_eid: u64,
/// Own DVN address. Used to check when the DVN is assigned to a task.
pub dvn_addr: Address,
/// NFFL Aggregator URL
pub aggregator_url: String,
}

impl DVNConfig {
Expand Down
1 change: 1 addition & 0 deletions workers/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@ pub mod abi;
pub mod chain;
pub mod config;
pub mod data;
pub mod verifier;
Loading

0 comments on commit 2c9fc41

Please sign in to comment.