Skip to content

Commit

Permalink
feat: update from fn
Browse files Browse the repository at this point in the history
  • Loading branch information
Tranduy1dol committed Jun 25, 2024
1 parent ae205f2 commit 8f657c3
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 75 deletions.
2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -84,4 +84,4 @@ orchestrator = { path = "crates/orchestrator" }

[patch.crates-io]
merlin = { git = "https://github.com/aptos-labs/merlin" }
x25519-dalek = { git = "https://github.com/Tranduy1dol/x25519-dalek", branch = "zeroize_v1.7" }
x25519-dalek = { git = "https://github.com/Tranduy1dol/x25519-dalek", branch = "zeroize_v1.7" }
11 changes: 5 additions & 6 deletions crates/da-clients/aptos/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ version.workspace = true
edition.workspace = true

[dependencies]
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "68952c0" }
c-kzg = "1.0.2"
color-eyre = "0.6.3"
dotenv = "0.15.0"
c-kzg = "1.0.2"
url = "2.5.0"
alloy = { git = "https://github.com/alloy-rs/alloy", rev = "68952c0"}

serde = { workspace = true }
aptos-sdk = { workspace = true }
async-trait = { workspace = true }
da-client-interface = { workspace = true }
async-trait = { workspace = true}
serde = { workspace = true }
utils = { workspace = true }
aptos-sdk = { workspace = true }

10 changes: 5 additions & 5 deletions crates/da-clients/aptos/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::str::FromStr;
use aptos_sdk::crypto::_once_cell::sync::Lazy;
use url::Url;
use da_client_interface::DaConfig;
use std::str::FromStr;
use url::Url;
use utils::env_utils::get_env_var_or_panic;

#[derive(Clone, Debug)]
Expand All @@ -20,13 +20,13 @@ impl DaConfig for AptosDaConfig {
.map(|s| s.as_str())
.unwrap_or("https://fullnode.devnet.aptoslabs.com"),
)
.unwrap()
.unwrap()
});

Self {
node_url: NODE_URL.to_string(),
private_key: get_env_var_or_panic("PRIVATE_KEY"),
account_address: get_env_var_or_panic("ADDRESS")
account_address: get_env_var_or_panic("ADDRESS"),
}
}
}
}
2 changes: 1 addition & 1 deletion crates/da-clients/aptos/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub(crate) fn vec_fixed_bytes_48_to_hex_string(data: &[FixedBytes<48>]) -> Strin
pub(crate) fn vec_fixed_bytes_131072_to_hex_string(data: &[FixedBytes<131072>]) -> String {
let hex_chars: Vec<String> = data.iter().map(|byte| format!("{:02X}", byte)).collect();
hex_chars.join("")
}
}
108 changes: 50 additions & 58 deletions crates/da-clients/aptos/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
#![allow(missing_docs)]
#![allow(clippy::missing_docs_in_private_items)]

use std::path::Path;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};
use aptos_sdk::rest_client::{Client};
use aptos_sdk::transaction_builder::TransactionBuilder;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::LocalAccount;
use aptos_sdk::types::transaction::{SignedTransaction, TransactionPayload, EntryFunction};
use async_trait::async_trait;
use crate::config::AptosDaConfig;
use crate::conversion::{vec_fixed_bytes_131072_to_hex_string, vec_fixed_bytes_48_to_hex_string};
use alloy::primitives::FixedBytes;
use aptos_sdk::crypto::ed25519::Ed25519PrivateKey;
use aptos_sdk::crypto::HashValue;
use aptos_sdk::move_types::identifier::Identifier;
use aptos_sdk::move_types::language_storage::ModuleId;
use aptos_sdk::move_types::u256;
use aptos_sdk::move_types::value::{MoveValue, serialize_values};
use c_kzg::{Blob, BYTES_PER_BLOB, KzgCommitment, KzgProof, KzgSettings};
use aptos_sdk::move_types::value::{serialize_values, MoveValue};
use aptos_sdk::rest_client::Client;
use aptos_sdk::transaction_builder::TransactionBuilder;
use aptos_sdk::types::chain_id::ChainId;
use aptos_sdk::types::transaction::{EntryFunction, SignedTransaction, TransactionPayload};
use aptos_sdk::types::{AccountKey, LocalAccount};
use async_trait::async_trait;
use c_kzg::{Blob, KzgCommitment, KzgProof, KzgSettings, BYTES_PER_BLOB};
use da_client_interface::{DaClient, DaVerificationStatus};
use dotenv::dotenv;
use crate::config::AptosDaConfig;
use crate::conversion::{vec_fixed_bytes_131072_to_hex_string, vec_fixed_bytes_48_to_hex_string};
use std::path::Path;
use std::str::FromStr;
use std::time::{SystemTime, UNIX_EPOCH};

pub mod config;
pub mod conversion;
Expand All @@ -41,37 +42,35 @@ impl DaClient for AptosDaClient {

let (blobs, commitments, proofs) = prepare_blob(&state_diff, &self.trusted_setup).await?;

let payload = TransactionPayload::EntryFunction(
EntryFunction::new(
ModuleId::new(
account.address(),
Identifier::new("starknet").unwrap()
),
Identifier::new("update_state").unwrap(),
vec![],
serialize_values(vec![
&MoveValue::Vector(vec![
MoveValue::U256(u256::U256::from_str(vec_fixed_bytes_131072_to_hex_string(&blobs).as_str()).unwrap()),
MoveValue::U256(u256::U256::from_str(vec_fixed_bytes_48_to_hex_string(&commitments).as_str()).unwrap()),
MoveValue::U256(u256::U256::from_str(vec_fixed_bytes_48_to_hex_string(&proofs).as_str()).unwrap()),
])
].into_iter())
)
);
let payload = TransactionPayload::EntryFunction(EntryFunction::new(
ModuleId::new(account.address(), Identifier::new("starknet").unwrap()),
Identifier::new("update_state").unwrap(),
vec![],
serialize_values(
vec![&MoveValue::Vector(vec![
MoveValue::U256(
u256::U256::from_str(vec_fixed_bytes_131072_to_hex_string(&blobs).as_str()).unwrap(),
),
MoveValue::U256(
u256::U256::from_str(vec_fixed_bytes_48_to_hex_string(&commitments).as_str()).unwrap(),
),
MoveValue::U256(u256::U256::from_str(vec_fixed_bytes_48_to_hex_string(&proofs).as_str()).unwrap()),
])]
.into_iter(),
),
));

// Build transaction.
let txn = TransactionBuilder::new(
payload,
SystemTime::now()
.duration_since(UNIX_EPOCH)
.unwrap()
.as_secs(),
ChainId::test())
.sender(account.address())
.sequence_number(1)
.max_gas_amount(10000000)
.gas_unit_price(1)
.build();
SystemTime::now().duration_since(UNIX_EPOCH).unwrap().as_secs(),
ChainId::test(),
)
.sender(account.address())
.sequence_number(1)
.max_gas_amount(10000000)
.gas_unit_price(1)
.build();

// Sign transaction.
let signed_txn: SignedTransaction = account.sign_transaction(txn);
Expand All @@ -87,19 +86,11 @@ impl DaClient for AptosDaClient {
let txn = client.get_transaction_by_hash(HashValue::from_str(external_id).unwrap()).await?;
let response = txn.into_inner();
match response.success() {
true => {
Ok(DaVerificationStatus::Verified)
}
false => {
match response.is_pending() {
true => {
Ok(DaVerificationStatus::Pending)
}
false => {
Ok(DaVerificationStatus::Rejected)
}
}
}
true => Ok(DaVerificationStatus::Verified),
false => match response.is_pending() {
true => Ok(DaVerificationStatus::Pending),
false => Ok(DaVerificationStatus::Rejected),
},
}
}

Expand All @@ -117,12 +108,13 @@ impl DaClient for AptosDaClient {
impl From<AptosDaConfig> for AptosDaClient {
fn from(config: AptosDaConfig) -> Self {
let client = Client::new(config.node_url.parse().unwrap());
let private_key = config.private_key.parse()?;
let account_address = config.account_address.parse()?;
let account = LocalAccount::new(account_address, private_key, 0);
let private_key = Ed25519PrivateKey::try_from(config.private_key.as_bytes());
let account_key = AccountKey::from_private_key(private_key.unwrap());
let account_address = config.account_address.parse().expect("Issue while loading account address");
let account = LocalAccount::new(account_address, account_key, 0);
let trusted_setup = KzgSettings::load_trusted_setup_file(Path::new("./trusted_setup.txt"))
.expect("Issue while loading the trusted setup");
AptosDaClient { client, account, trusted_setup}
AptosDaClient { client, account, trusted_setup }
}
}

Expand All @@ -149,4 +141,4 @@ async fn prepare_blob(
}

Ok((sidecar_blobs, sidecar_commitments, sidecar_proofs))
}
}
2 changes: 1 addition & 1 deletion crates/orchestrator/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ name = "orchestrator"
path = "src/main.rs"

[dependencies]
aptos-da-client = { workspace = true }
arc-swap = { workspace = true }
async-std = "1.12.0"
async-trait = { workspace = true }
Expand All @@ -22,7 +23,6 @@ color-eyre = { workspace = true }
da-client-interface = { workspace = true }
dotenvy = { workspace = true }
ethereum-da-client = { workspace = true, optional = true }
aptos-da-client = { workspace = true }
futures = { workspace = true }
lazy_static = { workspace = true }
majin-blob-core = { git = "https://github.com/AbdelStark/majin-blob", branch = "main" }
Expand Down
6 changes: 3 additions & 3 deletions crates/orchestrator/src/config.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
use std::sync::Arc;

use aptos_da_client::config::AptosDaConfig;
use aptos_da_client::AptosDaClient;
use arc_swap::{ArcSwap, Guard};
use da_client_interface::{DaClient, DaConfig};
use dotenvy::dotenv;
Expand All @@ -10,8 +12,6 @@ use sharp_service::SharpProverService;
use starknet::providers::jsonrpc::HttpTransport;
use starknet::providers::{JsonRpcClient, Url};
use tokio::sync::OnceCell;
use aptos_da_client::AptosDaClient;
use aptos_da_client::config::AptosDaConfig;
use utils::env_utils::get_env_var_or_panic;
use utils::settings::default::DefaultSettingsProvider;
use utils::settings::SettingsProvider;
Expand Down Expand Up @@ -129,7 +129,7 @@ fn build_da_client() -> Box<dyn DaClient + Send + Sync> {
"ethereum" => {
let config = EthereumDaConfig::new_from_env();
Box::new(EthereumDaClient::from(config))
},
}
"aptos" => {
let config = AptosDaConfig::new_from_env();
Box::new(AptosDaClient::from(config))
Expand Down

0 comments on commit 8f657c3

Please sign in to comment.