Skip to content

Commit

Permalink
Merge branch '898-fix-sdk-add-sender-address-to-wait-for-verification…
Browse files Browse the repository at this point in the history
…-function' into 881-feat-add-limit-on-aggregator-spending
  • Loading branch information
uri-99 committed Sep 3, 2024
2 parents cbbbb67 + 29cfbd0 commit ec7a63b
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
2 changes: 1 addition & 1 deletion batcher/aligned-sdk/abi/BatcherPaymentService.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
38 changes: 35 additions & 3 deletions batcher/aligned-sdk/src/sdk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ use futures_util::{
/// * `max_fees` - An array of the maximum fee that the submitter is willing to pay for each proof verification.
/// * `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 Down Expand Up @@ -69,13 +70,19 @@ pub async fn submit_multiple_and_wait_verification(
max_fees: &[U256],
wallet: Wallet<SigningKey>,
nonce: U256,
payment_service_addr: &str,
) -> Result<Vec<AlignedVerificationData>, errors::SubmitError> {
let aligned_verification_data =
submit_multiple(batcher_url, verification_data, max_fees, 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 @@ -199,6 +206,7 @@ async fn _submit_multiple(
/// * `max_fee` - The maximum fee that the submitter is willing to pay for the verification.
/// * `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 Down Expand Up @@ -227,6 +235,7 @@ pub async fn submit_and_wait_verification(
max_fee: U256,
wallet: Wallet<SigningKey>,
nonce: U256,
payment_service_addr: &str,
) -> Result<AlignedVerificationData, errors::SubmitError> {
let verification_data = vec![verification_data.clone()];

Expand All @@ -240,6 +249,7 @@ pub async fn submit_and_wait_verification(
&max_fees,
wallet,
nonce,
payment_service_addr,
)
.await?;

Expand Down Expand Up @@ -291,6 +301,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 @@ -301,25 +312,38 @@ 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",
Chain::Holesky => "0x58F280BeBE9B34c9939C3C39e0890C81f163B623",
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 @@ -343,6 +367,7 @@ 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
Expand Down Expand Up @@ -432,6 +457,7 @@ mod test {
use ethers::signers::LocalWallet;

const MAX_FEE: U256 = U256::max_value();
const BATCHER_PAYMENT_SERVICE_ADDR: &str = "0x7969c5eD335650692Bc04293B07F5BF2e7A673C0";

#[tokio::test]
async fn test_submit_success() {
Expand Down Expand Up @@ -469,6 +495,7 @@ mod test {
&max_fees,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand Down Expand Up @@ -505,6 +532,7 @@ mod test {
&max_fees,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await;

Expand Down Expand Up @@ -549,6 +577,7 @@ mod test {
&max_fees,
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand All @@ -559,6 +588,7 @@ mod test {
&aligned_verification_data[0],
Chain::Devnet,
"http://localhost:8545",
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand Down Expand Up @@ -600,6 +630,7 @@ mod test {
&[MAX_FEE],
wallet,
U256::zero(),
BATCHER_PAYMENT_SERVICE_ADDR,
)
.await
.unwrap();
Expand All @@ -615,6 +646,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 @@ -170,6 +170,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 @@ -382,6 +388,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

Large diffs are not rendered by default.

6 changes: 6 additions & 0 deletions docs/3_guides/1.2_SDK_api_reference.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ pub async fn submit_and_wait_verification(
max_fee: U256,
wallet: Wallet<SigningKey>,
nonce: U256,
payment_service_addr: &str,
) -> Result<AlignedVerificationData, errors::SubmitError>
```

Expand All @@ -114,6 +115,7 @@ pub async fn submit_and_wait_verification(
- `max_fee` - The maximum fee that the submitter is willing to pay for the proof verification.
- `wallet` - The wallet used to sign the proof. Should be using correct chain id. See `get_chain_id`.
- `nonce` - The nonce of the submitter address. See `get_next_nonce`.
- `payment_service_addr` - The address of the batcher payment service contract.

#### Returns

Expand Down Expand Up @@ -152,6 +154,7 @@ 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>
```

Expand All @@ -164,6 +167,7 @@ pub async fn submit_multiple_and_wait_verification(
- `max_fees` - A max fee array.
- `wallet` - The wallet used to sign the proof. Should be using correct chain id. See `get_chain_id`.
- `nonce` - The nonce of the submitter address. See `get_next_nonce`.
- `payment_service_addr` - The address of the batcher payment service contract.

#### Returns

Expand Down Expand Up @@ -198,6 +202,7 @@ pub async fn is_proof_verified(
aligned_verification_data: AlignedVerificationData,
chain: Chain,
eth_rpc_url: &str,
payment_service_addr: &str,
) -> Result<bool, errors::VerificationError>
```

Expand All @@ -206,6 +211,7 @@ pub async fn is_proof_verified(
- `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 batcher payment service contract.

#### Returns

Expand Down

0 comments on commit ec7a63b

Please sign in to comment.