Skip to content

Commit

Permalink
Merge pull request #30 from lambdaclass/update_to_0_6
Browse files Browse the repository at this point in the history
Update to 0.6.0
  • Loading branch information
gabrielbosio authored Sep 16, 2024
2 parents 590dd19 + a157f80 commit d5b0885
Show file tree
Hide file tree
Showing 30 changed files with 438 additions and 275 deletions.
2 changes: 1 addition & 1 deletion batcher/aligned-sdk/abi/AlignedLayerServiceManager.json

Large diffs are not rendered by default.

12 changes: 9 additions & 3 deletions batcher/aligned-sdk/src/communication/batch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,17 @@ pub async fn await_batch_verification(
aligned_verification_data: &AlignedVerificationData,
rpc_url: &str,
chain: Chain,
payment_service_addr: &str,
) -> Result<(), errors::SubmitError> {
for _ in 0..RETRIES {
if is_proof_verified(aligned_verification_data, chain.clone(), rpc_url)
.await
.is_ok_and(|r| r)
if is_proof_verified(
aligned_verification_data,
chain.clone(),
rpc_url,
payment_service_addr,
)
.await
.is_ok_and(|r| r)
{
return Ok(());
}
Expand Down
48 changes: 41 additions & 7 deletions batcher/aligned-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use std::sync::Arc;
use tokio::{net::TcpStream, sync::Mutex};
use tokio_tungstenite::{connect_async, tungstenite::Message, MaybeTlsStream, WebSocketStream};

use log::debug;
use log::{debug, info};

use futures_util::{
stream::{SplitSink, SplitStream},
Expand All @@ -40,6 +40,7 @@ use futures_util::{
/// * `verification_data` - An array of verification data of each proof.
/// * `wallet` - The wallet used to sign the proof.
/// * `nonce` - The nonce of the submitter address. See `get_next_nonce`.
/// * `payment_service_addr` - The address of the payment service contract.
/// # Returns
/// * An array of aligned verification data obtained when submitting the proof.
/// # Errors
Expand All @@ -66,13 +67,19 @@ pub async fn submit_multiple_and_wait_verification(
verification_data: &[VerificationData],
wallet: Wallet<SigningKey>,
nonce: U256,
payment_service_addr: &str,
) -> Result<Vec<AlignedVerificationData>, errors::SubmitError> {
let aligned_verification_data =
submit_multiple(batcher_url, verification_data, wallet, nonce).await?;

for aligned_verification_data_item in aligned_verification_data.iter() {
await_batch_verification(aligned_verification_data_item, eth_rpc_url, chain.clone())
.await?;
await_batch_verification(
aligned_verification_data_item,
eth_rpc_url,
chain.clone(),
payment_service_addr,
)
.await?;
}

Ok(aligned_verification_data)
Expand Down Expand Up @@ -182,6 +189,7 @@ async fn _submit_multiple(
/// * `verification_data` - The verification data of the proof.
/// * `wallet` - The wallet used to sign the proof.
/// * `nonce` - The nonce of the submitter address. See `get_next_nonce`.
/// * `payment_service_addr` - The address of the payment service contract.
/// # Returns
/// * The aligned verification data obtained when submitting the proof.
/// # Errors
Expand All @@ -208,6 +216,7 @@ pub async fn submit_and_wait_verification(
verification_data: &VerificationData,
wallet: Wallet<SigningKey>,
nonce: U256,
payment_service_addr: &str,
) -> Result<AlignedVerificationData, errors::SubmitError> {
let verification_data = vec![verification_data.clone()];

Expand All @@ -218,6 +227,7 @@ pub async fn submit_and_wait_verification(
&verification_data,
wallet,
nonce,
payment_service_addr,
)
.await?;

Expand Down Expand Up @@ -265,6 +275,7 @@ pub async fn submit(
/// * `aligned_verification_data` - The aligned verification data obtained when submitting the proofs.
/// * `chain` - The chain on which the verification will be done.
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
/// * `payment_service_addr` - The address of the payment service.
/// # Returns
/// * A boolean indicating whether the proof was verified on-chain and is included in the batch.
/// # Errors
Expand All @@ -275,18 +286,27 @@ pub async fn is_proof_verified(
aligned_verification_data: &AlignedVerificationData,
chain: Chain,
eth_rpc_url: &str,
payment_service_addr: &str,
) -> Result<bool, errors::VerificationError> {
let eth_rpc_provider =
Provider::<Http>::try_from(eth_rpc_url).map_err(|e: url::ParseError| {
errors::VerificationError::EthereumProviderError(e.to_string())
})?;
_is_proof_verified(aligned_verification_data, chain, eth_rpc_provider).await

_is_proof_verified(
aligned_verification_data,
chain,
eth_rpc_provider,
payment_service_addr,
)
.await
}

async fn _is_proof_verified(
aligned_verification_data: &AlignedVerificationData,
chain: Chain,
eth_rpc_provider: Provider<Http>,
payment_service_addr: &str,
) -> Result<bool, errors::VerificationError> {
let contract_address = match chain {
Chain::Devnet => "0x1613beB3B2C4f22Ee086B2b38C1476A3cE7f78E8",
Expand All @@ -295,6 +315,10 @@ async fn _is_proof_verified(
Chain::HoleskyStage => "0x9C5231FC88059C086Ea95712d105A2026048c39B",
};

let payment_service_addr = payment_service_addr
.parse::<Address>()
.map_err(|e| errors::VerificationError::HexDecodingError(e.to_string()))?;

// All the elements from the merkle proof have to be concatenated
let merkle_proof: Vec<u8> = aligned_verification_data
.batch_inclusion_proof
Expand All @@ -318,11 +342,13 @@ async fn _is_proof_verified(
aligned_verification_data.batch_merkle_root,
merkle_proof.into(),
aligned_verification_data.index_in_batch.into(),
payment_service_addr,
);

let result = call
.await
.map_err(|e| errors::VerificationError::EthereumCallError(e.to_string()))?;
let result = call.await.map_err(|e| {
info!("err: {}", e.to_string());
errors::VerificationError::EthereumCallError(e.to_string())
})?;

Ok(result)
}
Expand Down Expand Up @@ -406,6 +432,8 @@ mod test {

use ethers::signers::LocalWallet;

const BATCHER_PAYMENT_SERVICE_ADDR: &str = "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0";

#[tokio::test]
async fn test_submit_success() {
let base_dir = PathBuf::from(env!("CARGO_MANIFEST_DIR"));
Expand Down Expand Up @@ -439,6 +467,7 @@ mod test {
&verification_data,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand Down Expand Up @@ -472,6 +501,7 @@ mod test {
&verification_data,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await;

Expand Down Expand Up @@ -513,6 +543,7 @@ mod test {
&verification_data,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand All @@ -523,6 +554,7 @@ mod test {
&aligned_verification_data[0],
Chain::Devnet,
"http://localhost:8545",
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand Down Expand Up @@ -563,6 +595,7 @@ mod test {
&verification_data,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand All @@ -578,6 +611,7 @@ mod test {
&aligned_verification_data_modified,
Chain::Devnet,
"http://localhost:8545",
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand Down
7 changes: 7 additions & 0 deletions batcher/aligned/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,12 @@ pub struct VerifyProofOnchainArgs {
default_value = "devnet"
)]
chain: ChainArg,
#[arg(
name = "Batcher Payment Service Eth Address",
long = "payment_service_addr",
default_value = "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0"
)]
payment_service_addr: String,
}

#[derive(Parser, Debug)]
Expand Down Expand Up @@ -366,6 +372,7 @@ async fn main() -> Result<(), AlignedError> {
&aligned_verification_data,
chain,
&verify_inclusion_args.eth_rpc_url,
&verify_inclusion_args.payment_service_addr,
)
.await?;

Expand Down
2 changes: 1 addition & 1 deletion contracts/bindings/AlignedLayerServiceManager/binding.go

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Loading

0 comments on commit d5b0885

Please sign in to comment.