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

feat: memory page #3

Merged
merged 16 commits into from
Aug 29, 2024
Merged
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,4 @@ jobs:
- name: Set PKG_CONFIG_PATH
run: echo "PKG_CONFIG_PATH=/usr/lib/pkgconfig" >> $GITHUB_ENV
- name: Run tests
run: cargo tarpaulin --all-features --verbose --tests
run: cargo tarpaulin --all-features --verbose --tests --skip-clean
56 changes: 23 additions & 33 deletions Cargo.lock

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

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ anyhow = { version = "1.0.71" }
aptos-sdk = { git = "https://github.com/aptos-labs/aptos-core", branch = "mainnet" }
async-trait = { version = "0.1.81" }
dotenv = { version = "0.15.0" }
itertools = "0.10.5"
lazy_static = "1.4.0"
log = { version = "0.4.22" }
once_cell = { version = "1.19.0" }
Expand All @@ -21,7 +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.0.1", features = [
aptos-testcontainer = { git = "https://github.com/sota-zk-labs/aptos-testcontainer.git", tag = "v0.0.3", features = [
"testing",
] }

Expand Down
3 changes: 3 additions & 0 deletions rustfmt.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
group_imports = "StdExternalCrate"
imports_granularity = "Preserve"
reorder_imports = true
5 changes: 5 additions & 0 deletions src/bin/main.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
use log::info;

use verifier_onchain_services::config::{AppConfig, EnvConfig};
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::register_continuous_page_batch::register_continuous_page_batch;
use verifier_onchain_services::contracts_caller::memory_page_fact_registry::sample_register_memory::sample_register_continuous_page_batch;
use verifier_onchain_services::contracts_caller::verify_fri::sample_verify_fri_input::sample_verify_fri_input;
use verifier_onchain_services::contracts_caller::verify_fri::verify_fri::verify_fri;
use verifier_onchain_services::contracts_caller::verify_merkle::sample_verify_merkle_input::sample_verify_merkle_input;
Expand Down Expand Up @@ -47,5 +49,8 @@ async fn main() -> anyhow::Result<()> {
info!("Verify FRI {} success", i);
}

let register_continuous_page_batch_input = sample_register_continuous_page_batch()?;
register_continuous_page_batch(&config, register_continuous_page_batch_input).await?;
info!("Register continuous page batch success");
Ok(())
}
3 changes: 1 addition & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,11 @@
use std::str::FromStr;

use anyhow::Result;
use dotenv::dotenv;

use aptos_sdk::move_types::account_address::AccountAddress;
use aptos_sdk::rest_client::Client;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::LocalAccount;
use dotenv::dotenv;

pub struct EnvConfig {
pub node_url: String,
Expand Down
4 changes: 4 additions & 0 deletions src/contracts_caller/memory_page_fact_registry/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
pub mod register_continuous_memory_page;
pub mod register_continuous_page_batch;
pub mod sample_register_memory;
pub mod types;
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use std::str::FromStr;

use aptos_sdk::move_types::identifier::Identifier;
use aptos_sdk::move_types::language_storage::ModuleId;
use aptos_sdk::move_types::u256::U256;
use aptos_sdk::move_types::value::{serialize_values, MoveValue};
use aptos_sdk::types::transaction::{EntryFunction, TransactionPayload};
use log::info;

use crate::config::AppConfig;
use crate::contracts_caller::memory_page_fact_registry::types::register_continuous_memory_page::ContinuousMemoryPage;
use crate::contracts_caller::transaction_helper::build_transaction;

pub async fn register_continuous_memory_page(
config: &AppConfig,
data: ContinuousMemoryPage,
) -> anyhow::Result<bool> {
let mut values = vec![];
for e in &data.values {
values.push(MoveValue::U256(U256::from_str(e)?));
}

let payload = TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(
config.module_address,
Identifier::new("memory_page_fact_registry")?,
),
Identifier::new("register_continuous_memorypage")?,
vec![],
serialize_values(&vec![
MoveValue::U256(U256::from_str(&data.start_addr)?),
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);
let transaction = config.client.submit_and_wait(&tx).await?.into_inner();
let transaction_info = transaction.transaction_info()?;
info!(
"register_continuous_memory_page: {}; gas used: {}",
transaction_info.hash.to_string(),
transaction_info.gas_used
);
Ok(transaction.success())
}
Loading
Loading