diff --git a/Cargo.lock b/Cargo.lock index c03c02b..59b6d12 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -380,10 +380,10 @@ dependencies = [ "blst", "bulletproofs", "bytes", - "curve25519-dalek", + "curve25519-dalek 3.2.0", "curve25519-dalek-ng", "digest 0.9.0", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "ff", "hex", "hkdf 0.10.0", @@ -985,18 +985,22 @@ dependencies = [ [[package]] name = "aptos-testcontainer" -version = "0.1.0" -source = "git+https://github.com/sota-zk-labs/aptos-testcontainer.git?tag=v0.1.0#3dfb2795a78be837a2c46aba5d84794f4356ee27" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6aebc3c0e8d108bb2629c707b2821fd879ce043e18857f171db768982bf29600" dependencies = [ "anyhow", "base64 0.22.1", "config", + "ed25519-dalek 2.1.1", + "hex", "log", "rand 0.8.5", "regex", "serde", "testcontainers", "thiserror", + "tiny-keccak", "tokio", "walkdir", ] @@ -2557,6 +2561,33 @@ dependencies = [ "zeroize", ] +[[package]] +name = "curve25519-dalek" +version = "4.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "97fb8b7c4503de7d6ae7b42ab72a5a59857b4c937ec27a3d4539dba95b5ab2be" +dependencies = [ + "cfg-if", + "cpufeatures", + "curve25519-dalek-derive", + "digest 0.10.7", + "fiat-crypto", + "rustc_version", + "subtle", + "zeroize", +] + +[[package]] +name = "curve25519-dalek-derive" +version = "0.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f46882e17999c6cc590af592290432be3bce0428cb0d5f8b6715e4dc7b383eb3" +dependencies = [ + "proc-macro2", + "quote", + "syn 2.0.76", +] + [[package]] name = "curve25519-dalek-ng" version = "4.1.1" @@ -2807,14 +2838,24 @@ dependencies = [ "signature 1.6.4", ] +[[package]] +name = "ed25519" +version = "2.2.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "115531babc129696a58c64a4fef0a8bf9e9698629fb97e9e40767d235cfbcd53" +dependencies = [ + "pkcs8", + "signature 2.2.0", +] + [[package]] name = "ed25519-dalek" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "c762bae6dcaf24c4c84667b8579785430908723d5c889f469d76a41d59cc7a9d" dependencies = [ - "curve25519-dalek", - "ed25519", + "curve25519-dalek 3.2.0", + "ed25519 1.5.3", "rand 0.7.3", "serde", "serde_bytes", @@ -2822,6 +2863,20 @@ dependencies = [ "zeroize", ] +[[package]] +name = "ed25519-dalek" +version = "2.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4a3daa8e81a3963a60642bcc1f90a670680bd4a77535faa384e9d1c79d620871" +dependencies = [ + "curve25519-dalek 4.1.3", + "ed25519 2.2.3", + "serde", + "sha2 0.10.8", + "subtle", + "zeroize", +] + [[package]] name = "ed25519-dalek-bip32" version = "0.2.0" @@ -2829,7 +2884,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "9d2be62a4061b872c8c0873ee4fc6f101ce7b889d039f019c5fa2af471a59908" dependencies = [ "derivation-path", - "ed25519-dalek", + "ed25519-dalek 1.0.1", "hmac 0.12.1", "sha2 0.10.8", ] @@ -2979,6 +3034,12 @@ dependencies = [ "syn 1.0.109", ] +[[package]] +name = "fiat-crypto" +version = "0.2.9" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "28dea519a9695b9977216879a3ebfddf92f1c08c05d984f8996aecd6ecdc811d" + [[package]] name = "fixed" version = "1.28.0" @@ -7348,9 +7409,9 @@ dependencies = [ [[package]] name = "testcontainers" -version = "0.21.1" +version = "0.22.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5f7d80fe0008971413157e67062150cbf508b92f0eb525b9f49de1aec4267f24" +checksum = "2ef8374cea2c164699681ecc39316c3e1d953831a7a5721e36c7736d974e15fa" dependencies = [ "async-trait", "bollard", @@ -7529,9 +7590,9 @@ checksum = "1f3ccbac311fea05f86f61904b462b55fb3df8837a366dfc601a0161d0532f20" [[package]] name = "tokio" -version = "1.39.3" +version = "1.40.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9babc99b9923bfa4804bd74722ff02c0381021eafa4db9949217e3be8e84fff5" +checksum = "e2b070231665d27ad9ec9b8df639893f46727666c6767db40317fbe920a5d998" dependencies = [ "backtrace", "bytes", @@ -8568,7 +8629,7 @@ name = "x25519-dalek" version = "1.2.0" source = "git+https://github.com/Tranduy1dol/x25519-dalek?branch=zeroize_v1.7#d98aca90959611359089b2194874faa200d55977" dependencies = [ - "curve25519-dalek", + "curve25519-dalek 3.2.0", "rand_core 0.5.1", "zeroize", ] diff --git a/Cargo.toml b/Cargo.toml index cfb69f0..774451b 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -22,9 +22,7 @@ tokio = { version = "1.39.3", features = ["macros", "rt-multi-thread"] } url = { version = "2.4.0", features = ["serde"] } [dev-dependencies] -aptos-testcontainer = { git = "https://github.com/sota-zk-labs/aptos-testcontainer.git", tag = "v0.1.0", features = [ - "testing", -] } +aptos-testcontainer = { version = "0.1.2", features = ["testing"] } [patch.crates-io] merlin = { git = "https://github.com/aptos-labs/merlin" } diff --git a/contracts/navori b/contracts/navori index dc5f70a..c071c5f 160000 --- a/contracts/navori +++ b/contracts/navori @@ -1 +1 @@ -Subproject commit dc5f70a6b6546620cd7eab1423370bcb83d55c3f +Subproject commit c071c5f87cf7408c549d2ac7b4aba60fab7a5525 diff --git a/src/contracts_caller/gps/verify_proof_and_register.rs b/src/contracts_caller/gps/verify_proof_and_register.rs index 9195c38..a4afbba 100644 --- a/src/contracts_caller/gps/verify_proof_and_register.rs +++ b/src/contracts_caller/gps/verify_proof_and_register.rs @@ -7,12 +7,12 @@ use aptos_sdk::move_types::value::{serialize_values, MoveValue}; use aptos_sdk::rest_client::aptos_api_types::MoveType; use aptos_sdk::rest_client::error::RestError; use aptos_sdk::types::transaction::{EntryFunction, TransactionPayload}; -use log::{debug, error, info}; +use log::{debug, info}; use crate::config::AppConfig; use crate::contracts_caller::gps::types::verify_proof_and_register::VerifyProofAndRegisterData; use crate::contracts_caller::transaction_helper::{build_transaction, get_event_from_transaction}; -use crate::error::CoreError::TransactionNotSucceed; +use crate::error::CoreError::{FlowNotFinished, TransactionNotSucceed}; pub async fn verify_proof_and_register( config: &AppConfig, @@ -115,42 +115,43 @@ pub async fn verify_proof_and_register( .wait_for_transaction(&pending_transaction) .await? .into_inner(); - let transaction_info = transaction.transaction_info()?; - ensure!( - transaction_info.success, - TransactionNotSucceed(format!("{}; hash: {}", name, transaction_info.hash)) - ); - info!( - "{} finished: id={}; hash={}; gas={}", - name, - transaction_info.version, - transaction_info.hash.to_string(), - transaction_info.gas_used, - ); - Ok::<_, anyhow::Error>(transaction) + Ok::<_, anyhow::Error>((name, transaction)) }) }) .collect::>(); let mut transactions = Vec::with_capacity(results.len()); for handle in results { - transactions.push(handle.await??); + let (name, transaction) = handle.await??; + let transaction_info = transaction.transaction_info()?; + ensure!( + transaction_info.success, + TransactionNotSucceed(format!("{}; hash: {}", name, transaction_info.hash)) + ); + info!( + "{} finished: id={}; hash={}; gas={}", + name, + transaction_info.version, + transaction_info.hash.to_string(), + transaction_info.gas_used, + ); + transactions.push(transaction); } + let last_transaction = transactions.last().unwrap(); + // Get the event from the last transaction - if let Some(last_transaction) = transactions.last() { - let event = get_event_from_transaction( - last_transaction, - MoveType::from_str(&format!( - "{}::{}::VparFinished", - config.module_address, module_name - ))?, - ); + let event = get_event_from_transaction( + last_transaction, + MoveType::from_str(&format!( + "{}::{}::VparFinished", + config.module_address, module_name + ))?, + ); + ensure!( + event.is_ok(), + FlowNotFinished("verify_proof_and_register".to_string()) + ); - info!("Verify_proof_and_register {}", event.is_ok()); - if event.is_err() { - error!("Some things went wrong!"); - } - } Ok(()) } diff --git a/src/contracts_caller/memory_page_fact_registry/register_continuous_memory_page.rs b/src/contracts_caller/memory_page_fact_registry/register_continuous_memory_page.rs index d51728b..6f33d2d 100644 --- a/src/contracts_caller/memory_page_fact_registry/register_continuous_memory_page.rs +++ b/src/contracts_caller/memory_page_fact_registry/register_continuous_memory_page.rs @@ -32,7 +32,6 @@ pub async fn register_continuous_memory_page( MoveValue::Vector(values), MoveValue::U256(U256::from_str(&data.z)?), MoveValue::U256(U256::from_str(&data.alpha)?), - MoveValue::U256(U256::from_str(&data.prime)?), ]), )); let tx = build_transaction(payload, &config.account, config.chain_id); diff --git a/src/contracts_caller/memory_page_fact_registry/register_continuous_page_batch.rs b/src/contracts_caller/memory_page_fact_registry/register_continuous_page_batch.rs index f1c4298..f6bba9f 100644 --- a/src/contracts_caller/memory_page_fact_registry/register_continuous_page_batch.rs +++ b/src/contracts_caller/memory_page_fact_registry/register_continuous_page_batch.rs @@ -23,15 +23,11 @@ pub async fn register_continuous_page_batch( ) -> anyhow::Result<()> { let ContinuousMemoryPage { z, - alpha, - prime, - values: _, - start_addr: _, + alpha, .. } = data.memory_page_entries.first().unwrap(); let z = MoveValue::U256(U256::from_str(z)?); let alpha = MoveValue::U256(U256::from_str(alpha)?); - let prime = MoveValue::U256(U256::from_str(prime)?); let mut converted_data = data .memory_page_entries @@ -80,7 +76,6 @@ pub async fn register_continuous_page_batch( let txs = chunks.into_iter().enumerate().map(|(i, chunk)| { let (chunk_start_addr, chunk_values): (Vec<_>, Vec<_>) = chunk.into_iter().unzip(); - let payload = TransactionPayload::EntryFunction(EntryFunction::new( ModuleId::new( config.module_address, @@ -93,7 +88,6 @@ pub async fn register_continuous_page_batch( MoveValue::Vector(chunk_values), z.clone(), alpha.clone(), - prime.clone(), ]), )); let tx = build_transaction(payload, &config.account, config.chain_id); diff --git a/src/error.rs b/src/error.rs index 31e4cdf..fc5277e 100644 --- a/src/error.rs +++ b/src/error.rs @@ -19,6 +19,9 @@ pub enum CoreError { #[error("transaction not succeed {0}")] TransactionNotSucceed(String), + #[error("flow not finished {0}")] + FlowNotFinished(String), + #[error("not found")] NotFound, diff --git a/tests/memory_page_test.rs b/tests/memory_page_test.rs index 1bb933e..290de41 100644 --- a/tests/memory_page_test.rs +++ b/tests/memory_page_test.rs @@ -4,6 +4,7 @@ mod tests { use aptos_sdk::types::LocalAccount; use aptos_testcontainer::test_utils::aptos_container_test_utils::{lazy_aptos_container, run}; + use log::info; use test_log::test; use verifier_onchain_services::config::{AppConfig, EnvConfig}; @@ -31,18 +32,11 @@ mod tests { chain_id: aptos_container.get_chain_id().to_string(), }); - let sequence_number = config - .client - .get_account(config.account.address()) - .await? - .into_inner() - .sequence_number; - config.account.set_sequence_number(sequence_number); - let mut named_addresses = HashMap::new(); - named_addresses.insert("verifier_addr".to_string(), module_address.clone()); named_addresses.insert("lib_addr".to_string(), module_address.clone()); - named_addresses.insert("cpu_addr".to_string(), module_address); + named_addresses.insert("cpu_addr".to_string(), module_address.clone()); + named_addresses.insert("verifier_addr".to_string(), module_address.clone()); + aptos_container .upload_contract( "./contracts/navori", @@ -54,14 +48,36 @@ mod tests { .await .unwrap(); + aptos_container + .run_script( + "./contracts/navori", + sender_account_private_key, + &named_addresses, + &vec!["verifier"], + ) + .await + .unwrap(); + let sequence_number = config + .client + .get_account(config.account.address()) + .await? + .into_inner() + .sequence_number; + config.account.set_sequence_number(sequence_number); + + info!("Registering continuous page batch"); let register_continuous_page_batch_input = sample_register_continuous_page_batch()?; register_continuous_page_batch(&config, register_continuous_page_batch_input) .await .unwrap(); + info!("Registering continuous memory page"); let register_continuous_page_input = sample_register_continuous_page()?; - register_continuous_memory_page(&config, register_continuous_page_input).await?; + register_continuous_memory_page(&config, register_continuous_page_input) + .await + .unwrap(); + info!("Registering large data continuous page batch"); let large_data_register_continuous_page_batch_input = sample_large_data_register_continuous_page_batch()?; register_continuous_page_batch( @@ -70,6 +86,7 @@ mod tests { ) .await .unwrap(); + Ok(()) }) })