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
928 changes: 188 additions & 740 deletions Cargo.lock

Large diffs are not rendered by default.

7 changes: 2 additions & 5 deletions ant-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,8 @@ zip = "2"
tower-http = { version = "0.6.8", features = ["cors"] }

# Data operations
ant-evm = "0.1.19"
evmlib = "0.4.7"
evmlib = "0.5.0"
xor_name = "5"
libp2p = "0.56"
multihash = "0.19"
self_encryption = "0.35.0"
futures = "0.3"
postcard = { version = "1.1.3", features = ["use-std"] }
Expand All @@ -38,7 +35,7 @@ tracing = "0.1"
bytes = "1"
lru = "0.16"
rand = "0.8"
ant-node = "0.7"
ant-node = "0.8.0"
saorsa-pqc = "0.5"
tracing-subscriber = { version = "0.3", features = ["env-filter"] }

Expand Down
6 changes: 3 additions & 3 deletions ant-core/src/data/client/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@
use crate::data::client::payment::peer_id_to_encoded;
use crate::data::client::Client;
use crate::data::error::{Error, Result};
use ant_evm::{Amount, EncodedPeerId, PaymentQuote, ProofOfPayment, QuoteHash, RewardsAddress};
use ant_node::ant_protocol::DATA_TYPE_CHUNK;
use ant_node::client::{compute_address, XorName};
use ant_node::core::{MultiAddr, PeerId};
use ant_node::payment::{serialize_single_node_proof, PaymentProof, SingleNodePayment};
use bytes::Bytes;
use evmlib::common::TxHash;
use evmlib::common::{Amount, QuoteHash, TxHash};
use evmlib::contract::payment_vault::get_market_price;
use evmlib::wallet::PayForQuotesError;
use evmlib::{EncodedPeerId, PaymentQuote, ProofOfPayment, RewardsAddress};
use futures::stream::{self, StreamExt};
use std::collections::{HashMap, HashSet};
use tracing::{debug, info};
Expand Down Expand Up @@ -435,9 +435,9 @@ mod send_assertions {
#[allow(clippy::unwrap_used)]
mod tests {
use super::*;
use ant_evm::QuotingMetrics;
use ant_node::payment::single_node::QuotePaymentInfo;
use ant_node::CLOSE_GROUP_SIZE;
use evmlib::quoting_metrics::QuotingMetrics;

fn test_metrics() -> QuotingMetrics {
QuotingMetrics {
Expand Down
2 changes: 1 addition & 1 deletion ant-core/src/data/client/file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ use crate::data::client::batch::{finalize_batch_payment, PaymentIntent, Prepared
use crate::data::client::merkle::{MerkleBatchPaymentResult, PaymentMode};
use crate::data::client::Client;
use crate::data::error::{Error, Result};
use ant_evm::QuoteHash;
use ant_node::ant_protocol::DATA_TYPE_CHUNK;
use ant_node::client::compute_address;
use bytes::Bytes;
use evmlib::common::QuoteHash;
use evmlib::common::TxHash;
use futures::stream::{self, StreamExt};
use self_encryption::{stream_encrypt, streaming_decrypt, DataMap};
Expand Down
24 changes: 12 additions & 12 deletions ant-core/src/data/client/merkle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,6 @@

use crate::data::client::Client;
use crate::data::error::{Error, Result};
use ant_evm::merkle_payments::{
MerklePaymentCandidateNode, MerklePaymentCandidatePool, MerklePaymentProof, MerkleTree,
MidpointProof, CANDIDATES_PER_POOL, MAX_LEAVES,
};
use ant_node::ant_protocol::{
ChunkMessage, ChunkMessageBody, MerkleCandidateQuoteRequest, MerkleCandidateQuoteResponse,
};
Expand All @@ -18,6 +14,10 @@ use ant_node::payment::quote::verify_merkle_candidate_signature;
use ant_node::payment::serialize_merkle_proof;
use bytes::Bytes;
use evmlib::merkle_batch_payment::PoolCommitment;
use evmlib::merkle_payments::{
MerklePaymentCandidateNode, MerklePaymentCandidatePool, MerklePaymentProof, MerkleTree,
MidpointProof, CANDIDATES_PER_POOL, MAX_LEAVES,
};
use futures::stream::{self, FuturesUnordered, StreamExt};
use std::collections::HashMap;
use std::time::Duration;
Expand Down Expand Up @@ -515,7 +515,7 @@ mod send_assertions {
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
mod tests {
use super::*;
use ant_evm::merkle_payments::{MerkleTree, CANDIDATES_PER_POOL};
use evmlib::merkle_payments::{MerkleTree, CANDIDATES_PER_POOL};

// =========================================================================
// should_use_merkle (free function, no Client needed)
Expand Down Expand Up @@ -632,10 +632,10 @@ mod tests {

#[test]
fn test_merkle_proof_serialize_deserialize_roundtrip() {
use ant_evm::merkle_payments::MerklePaymentCandidateNode;
use ant_evm::QuotingMetrics;
use ant_evm::RewardsAddress;
use ant_node::payment::{deserialize_merkle_proof, serialize_merkle_proof};
use evmlib::merkle_payments::MerklePaymentCandidateNode;
use evmlib::quoting_metrics::QuotingMetrics;
use evmlib::RewardsAddress;

let addrs = make_test_addresses(4);
let xornames: Vec<XorName> = addrs.iter().map(|a| XorName(*a)).collect();
Expand Down Expand Up @@ -702,7 +702,7 @@ mod tests {
// Simulates what collect_validated_candidates checks
let candidate = MerklePaymentCandidateNode {
pub_key: vec![0u8; 32],
quoting_metrics: ant_evm::QuotingMetrics {
quoting_metrics: evmlib::quoting_metrics::QuotingMetrics {
data_size: 0,
data_type: 0,
close_records_stored: 0,
Expand All @@ -713,7 +713,7 @@ mod tests {
network_density: None,
network_size: None,
},
reward_address: ant_evm::RewardsAddress::new([0u8; 20]),
reward_address: evmlib::RewardsAddress::new([0u8; 20]),
merkle_payment_timestamp: 1000,
signature: vec![0u8; 64],
};
Expand All @@ -726,7 +726,7 @@ mod tests {
fn test_candidate_wrong_data_type_rejected() {
let candidate = MerklePaymentCandidateNode {
pub_key: vec![0u8; 32],
quoting_metrics: ant_evm::QuotingMetrics {
quoting_metrics: evmlib::quoting_metrics::QuotingMetrics {
data_size: 0,
data_type: 1, // scratchpad
close_records_stored: 0,
Expand All @@ -737,7 +737,7 @@ mod tests {
network_density: None,
network_size: None,
},
reward_address: ant_evm::RewardsAddress::new([0u8; 20]),
reward_address: evmlib::RewardsAddress::new([0u8; 20]),
merkle_payment_timestamp: 1000,
signature: vec![0u8; 64],
};
Expand Down
6 changes: 2 additions & 4 deletions ant-core/src/data/client/payment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,10 @@

use crate::data::client::Client;
use crate::data::error::{Error, Result};
use ant_evm::{EncodedPeerId, ProofOfPayment};
use ant_node::client::hex_node_id_to_encoded_peer_id;
use ant_node::core::{MultiAddr, PeerId};
use ant_node::payment::{serialize_single_node_proof, PaymentProof, SingleNodePayment};
use evmlib::wallet::Wallet;
use evmlib::{EncodedPeerId, ProofOfPayment};
use std::sync::Arc;
use tracing::{debug, info};

Expand Down Expand Up @@ -158,6 +157,5 @@ impl Client {

/// Convert an ant-node `PeerId` to an `EncodedPeerId` for payment proofs.
pub(crate) fn peer_id_to_encoded(peer_id: &PeerId) -> Result<EncodedPeerId> {
hex_node_id_to_encoded_peer_id(&peer_id.to_hex())
.map_err(|e| Error::Payment(format!("Failed to encode peer ID: {e}")))
Ok(EncodedPeerId::new(*peer_id.as_bytes()))
}
3 changes: 2 additions & 1 deletion ant-core/src/data/client/quote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,15 @@

use crate::data::client::Client;
use crate::data::error::{Error, Result};
use ant_evm::{Amount, PaymentQuote};
use ant_node::ant_protocol::{
ChunkMessage, ChunkMessageBody, ChunkQuoteRequest, ChunkQuoteResponse,
};
use ant_node::client::send_and_await_chunk_response;
use ant_node::core::{MultiAddr, PeerId};
use ant_node::payment::calculate_price;
use ant_node::{CLOSE_GROUP_MAJORITY, CLOSE_GROUP_SIZE};
use evmlib::common::Amount;
use evmlib::PaymentQuote;
use futures::stream::{FuturesUnordered, StreamExt};
use std::time::Duration;
use tracing::{debug, info, warn};
Expand Down
8 changes: 6 additions & 2 deletions ant-core/src/node/devnet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,13 @@ impl LocalDevnet {
/// Returns an error if the devnet fails to start or stabilize.
pub async fn start(mut config: DevnetConfig) -> Result<Self> {
info!("Starting local Anvil blockchain...");
let testnet = Testnet::new().await;
let testnet = Testnet::new()
.await
.map_err(|e| Error::Config(format!("failed to start Anvil testnet: {e}")))?;
let network = testnet.to_network();
let wallet_key = testnet.default_wallet_private_key();
let wallet_key = testnet
.default_wallet_private_key()
.map_err(|e| Error::Config(format!("failed to get wallet key: {e}")))?;

let (rpc_url, token_addr, payments_addr, merkle_addr) =
extract_custom_network_info(&network)?;
Expand Down
12 changes: 4 additions & 8 deletions ant-core/tests/e2e_security.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,11 @@
mod support;

use ant_core::data::{compute_address, Client, ClientConfig};
use ant_evm::ProofOfPayment;
use ant_node::client::hex_node_id_to_encoded_peer_id;
use ant_node::core::PeerId;
use ant_node::payment::{serialize_single_node_proof, PaymentProof, SingleNodePayment};
use bytes::Bytes;
use evmlib::common::TxHash;
use evmlib::{EncodedPeerId, ProofOfPayment};
use serial_test::serial;
use std::sync::Arc;
use support::MiniTestnet;
Expand Down Expand Up @@ -45,8 +44,7 @@ async fn collect_and_pay(client: &Client, content: &Bytes) -> (PaymentProof, Vec
let mut peer_quotes = Vec::with_capacity(quotes.len());
let mut quotes_for_payment = Vec::with_capacity(quotes.len());
for (peer_id, _addrs, quote, price) in quotes {
let encoded =
hex_node_id_to_encoded_peer_id(&peer_id.to_hex()).expect("peer ID conversion");
let encoded = EncodedPeerId::new(*peer_id.as_bytes());
peer_quotes.push((encoded, quote.clone()));
quotes_for_payment.push((quote, price));
}
Expand Down Expand Up @@ -196,8 +194,7 @@ async fn test_attack_zero_amount_payment() {
let target_peer = quotes.first().expect("should have quotes").0;
let mut peer_quotes = Vec::with_capacity(quotes.len());
for (peer_id, _addrs, quote, _price) in quotes {
let encoded =
hex_node_id_to_encoded_peer_id(&peer_id.to_hex()).expect("peer ID conversion");
let encoded = EncodedPeerId::new(*peer_id.as_bytes());
peer_quotes.push((encoded, quote));
}

Expand Down Expand Up @@ -241,8 +238,7 @@ async fn test_attack_fabricated_tx_hash() {
let target_peer = quotes.first().expect("should have quotes").0;
let mut peer_quotes = Vec::with_capacity(quotes.len());
for (peer_id, _addrs, quote, _price) in quotes {
let encoded =
hex_node_id_to_encoded_peer_id(&peer_id.to_hex()).expect("peer ID conversion");
let encoded = EncodedPeerId::new(*peer_id.as_bytes());
peer_quotes.push((encoded, quote));
}

Expand Down
8 changes: 5 additions & 3 deletions ant-core/tests/support/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
clippy::used_underscore_binding
)]

use ant_evm::RewardsAddress;
use ant_node::ant_protocol::MAX_WIRE_MESSAGE_SIZE;
use ant_node::core::{
CoreNodeConfig, IPDiversityConfig, MlDsa65, MultiAddr, NodeIdentity, P2PEvent, P2PNode,
Expand All @@ -28,6 +27,7 @@ use ant_node::storage::{AntProtocol, LmdbStorage, LmdbStorageConfig};
use evmlib::testnet::Testnet;
use evmlib::wallet::Wallet;
use evmlib::Network as EvmNetwork;
use evmlib::RewardsAddress;
use rand::Rng;
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
use std::sync::Arc;
Expand Down Expand Up @@ -68,11 +68,13 @@ impl MiniTestnet {
/// Use 6 for standard tests, 35+ for merkle tests (need 16 peers per pool).
pub async fn start(node_count: usize) -> Self {
// Start Anvil EVM testnet FIRST
let testnet = Testnet::new().await;
let testnet = Testnet::new().await.expect("start Anvil testnet");
let evm_network = testnet.to_network();

// Create funded wallet from the same Anvil instance
let private_key = testnet.default_wallet_private_key();
let private_key = testnet
.default_wallet_private_key()
.expect("get wallet key");
let wallet = Wallet::new_from_private_key(evm_network.clone(), &private_key)
.expect("create funded wallet");

Expand Down
Loading