Skip to content

Commit e62624b

Browse files
authored
docs: update examples and SDK specs (#1839)
1 parent 76d3e34 commit e62624b

File tree

6 files changed

+135
-54
lines changed

6 files changed

+135
-54
lines changed

batcher/aligned-sdk/src/sdk.rs

Lines changed: 58 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,18 @@ use std::io::Write;
4949
use std::path::PathBuf;
5050

5151
/// Submits multiple proofs to the batcher to be verified in Aligned and waits for the verification on-chain.
52+
///
5253
/// # Arguments
5354
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
54-
/// * `chain` - The chain on which the verification will be done.
55+
/// * `network` - The network on which the verification will be done.
5556
/// * `verification_data` - An array of verification data of each proof.
56-
/// * `max_fees` - An array of the maximum fee that the submitter is willing to pay for each proof verification.
57+
/// * `max_fee` - The maximum fee that the submitter is willing to pay for the verification for each proof.
5758
/// * `wallet` - The wallet used to sign the proof.
5859
/// * `nonce` - The nonce of the submitter address. See [`get_nonce_from_ethereum`] or [`get_nonce_from_batcher`].
59-
/// * `payment_service_addr` - The address of the payment service contract.
60+
///
6061
/// # Returns
6162
/// * An array of aligned verification data obtained when submitting the proof.
63+
///
6264
/// # Errors
6365
/// * `MissingRequiredParameter` if the verification data vector is empty.
6466
/// * `ProtocolVersionMismatch` if the version of the SDK is lower than the expected one.
@@ -109,19 +111,21 @@ pub async fn submit_multiple_and_wait_verification(
109111
}
110112

111113
/// Returns the estimated `max_fee` depending on the batch inclusion preference of the user, computed based on the current gas price, and the number of proofs in a batch.
112-
/// NOTE: The `max_fee` is computed from an rpc nodes max priority gas price.
114+
/// NOTE: The `max_fee` is computed from a rpc node's max priority gas price.
113115
/// To estimate the `max_fee` of a batch we compute it based on a batch size of 1 (Instant), 10 (Default), or a user supplied `number_proofs_in_batch` (Custom).
114116
/// The `max_fee` estimates therefore are:
115-
/// * `Default`: Specifies a `max_fee` equivalent to the cost of paying for one proof within a batch of 10 proofs ie. 1 / 10 proofs.
117+
/// * `Default`: Specifies a `max_fee` equivalent to the cost of paying for one proof within a batch of 10 proofs i.e. 1 / 10 proofs.
116118
/// This estimates a default `max_fee` the user should specify for including there proof within the batch.
117119
/// * `Instant`: Specifies a `max_fee` equivalent to the cost of paying for an entire batch ensuring the user's proof is included instantly assuming the proof is not competing with others for inclusion.
118120
/// * `Custom (number_proofs_in_batch)`: Specifies a `max_fee` equivalent to the cost of paying 1 proof / `number_proofs_in_batch` allowing the user a user to estimate the `max_fee` precisely based on the `number_proofs_in_batch`.
119121
///
120122
/// # Arguments
121123
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
122-
/// * `estimate_type` - Enum specifying the type of price estimate: Default, Instant. Custom(usize)
124+
/// * `fee_estimation_type` - Enum specifying the type of price estimate: Default, Instant. Custom(usize)
125+
///
123126
/// # Returns
124127
/// The estimated `max_fee` in gas for a proof based on the users `FeeEstimateType` as a `U256`.
128+
///
125129
/// # Errors
126130
/// * `EthereumProviderError` if there is an error in the connection with the RPC provider.
127131
/// * `EthereumGasPriceError` if there is an error retrieving the Ethereum gas price.
@@ -144,12 +148,16 @@ pub async fn estimate_fee(
144148

145149
/// Returns the `fee_per_proof` based on the current gas price for a batch compromised of `num_proofs_per_batch`
146150
/// i.e. (1 / `num_proofs_per_batch`).
147-
// NOTE: The `fee_per_proof` is computed from an rpc nodes max priority gas price.
151+
///
152+
/// NOTE: The `fee_per_proof` is computed from a rpc node's max priority gas price.
153+
///
148154
/// # Arguments
149155
/// * `eth_rpc_url` - The URL of the users Ethereum RPC node.
150-
/// * `num_proofs_per_batch` - number of proofs within a batch.
156+
/// * `num_proofs_in_batch` - number of proofs within a batch.
157+
///
151158
/// # Returns
152159
/// * The fee per proof of a batch as a `U256`.
160+
///
153161
/// # Errors
154162
/// * `EthereumProviderError` if there is an error in the connection with the RPC provider.
155163
/// * `EthereumGasPriceError` if there is an error retrieving the Ethereum gas price.
@@ -195,14 +203,17 @@ async fn fetch_gas_price(
195203
}
196204

197205
/// Submits multiple proofs to the batcher to be verified in Aligned.
206+
///
198207
/// # Arguments
199208
/// * `network` - The network on which the verification will be done.
200209
/// * `verification_data` - An array of verification data of each proof.
201-
/// * `max_fees` - An array of the maximum fee that the submitter is willing to pay for each proof verification.
210+
/// * `max_fee` - The maximum fee that the submitter is willing to pay for the verification for each proof.
202211
/// * `wallet` - The wallet used to sign the proof.
203212
/// * `nonce` - The nonce of the submitter address. See [`get_nonce_from_ethereum`] or [`get_nonce_from_batcher`].
213+
///
204214
/// # Returns
205215
/// * An array of aligned verification data obtained when submitting the proof.
216+
///
206217
/// # Errors
207218
/// * `MissingRequiredParameter` if the verification data vector is empty.
208219
/// * `ProtocolVersionMismatch` if the version of the SDK is lower than the expected one.
@@ -307,16 +318,18 @@ async fn _submit_multiple(
307318
}
308319

309320
/// Submits a proof to the batcher to be verified in Aligned and waits for the verification on-chain.
321+
///
310322
/// # Arguments
311323
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
312-
/// * `chain` - The chain on which the verification will be done.
324+
/// * `network` - The network on which the verification will be done.
313325
/// * `verification_data` - The verification data of the proof.
314326
/// * `max_fee` - The maximum fee that the submitter is willing to pay for the verification.
315327
/// * `wallet` - The wallet used to sign the proof.
316328
/// * `nonce` - The nonce of the submitter address. See [`get_nonce_from_ethereum`] or [`get_nonce_from_batcher`].
317-
/// * `payment_service_addr` - The address of the payment service contract.
329+
///
318330
/// # Returns
319331
/// * The aligned verification data obtained when submitting the proof.
332+
///
320333
/// # Errors
321334
/// * `MissingRequiredParameter` if the verification data vector is empty.
322335
/// * `ProtocolVersionMismatch` if the version of the SDK is lower than the expected one.
@@ -366,14 +379,17 @@ pub async fn submit_and_wait_verification(
366379
}
367380

368381
/// Submits a proof to the batcher to be verified in Aligned.
382+
///
369383
/// # Arguments
370384
/// * `network` - The network on which the verification will be done.
371385
/// * `verification_data` - The verification data of the proof.
372386
/// * `max_fee` - The maximum fee that the submitter is willing to pay for the verification.
373387
/// * `wallet` - The wallet used to sign the proof.
374388
/// * `nonce` - The nonce of the submitter address. See [`get_nonce_from_ethereum`] or [`get_nonce_from_batcher`].
389+
///
375390
/// # Returns
376391
/// * The aligned verification data obtained when submitting the proof.
392+
///
377393
/// # Errors
378394
/// * `MissingRequiredParameter` if the verification data vector is empty.
379395
/// * `ProtocolVersionMismatch` if the version of the SDK is lower than the expected one.
@@ -411,13 +427,15 @@ pub async fn submit(
411427
}
412428

413429
/// Checks if the proof has been verified with Aligned and is included in the batch.
430+
///
414431
/// # Arguments
415432
/// * `aligned_verification_data` - The aligned verification data obtained when submitting the proofs.
416-
/// * `chain` - The chain on which the verification will be done.
433+
/// * `network` - The network on which the verification will be done.
417434
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
418-
/// * `payment_service_addr` - The address of the payment service.
435+
///
419436
/// # Returns
420437
/// * A boolean indicating whether the proof was verified on-chain and is included in the batch.
438+
///
421439
/// # Errors
422440
/// * `EthereumProviderError` if there is an error in the connection with the RPC provider.
423441
/// * `EthereumCallError` if there is an error in the Ethereum call.
@@ -477,11 +495,14 @@ async fn _is_proof_verified(
477495
}
478496

479497
/// Returns the commitment for the verification key, taking into account the corresponding proving system.
498+
///
480499
/// # Arguments
481500
/// * `verification_key_bytes` - The serialized contents of the verification key.
482501
/// * `proving_system` - The corresponding proving system ID.
502+
///
483503
/// # Returns
484504
/// * The commitment.
505+
///
485506
/// # Errors
486507
/// * None.
487508
pub fn get_vk_commitment(
@@ -496,14 +517,18 @@ pub fn get_vk_commitment(
496517
}
497518

498519
/// Returns the next nonce for a given address from the batcher.
520+
///
499521
/// You should prefer this method instead of [`get_nonce_from_ethereum`] if you have recently sent proofs,
500522
/// as the batcher proofs might not yet be on ethereum,
501-
/// producing an out-of-sync nonce with the payment service contract on ethereum
523+
/// producing an out-of-sync nonce with the payment service contract on ethereum.
524+
///
502525
/// # Arguments
503-
/// * `address` - The user address for which the nonce will be retrieved.
504526
/// * `network` - The network from which the nonce will be retrieved.
527+
/// * `address` - The user address for which the nonce will be retrieved.
528+
///
505529
/// # Returns
506530
/// * The next nonce of the proof submitter account.
531+
///
507532
/// # Errors
508533
/// * `EthRpcError` if the batcher has an error in the Ethereum call when retrieving the nonce if not already cached.
509534
pub async fn get_nonce_from_batcher(
@@ -569,11 +594,15 @@ pub async fn get_nonce_from_batcher(
569594

570595
/// Returns the next nonce for a given address in Ethereum from aligned payment service contract.
571596
/// Note that it might be out of sync if you recently sent proofs. For that see [`get_nonce_from_batcher`]
597+
///
572598
/// # Arguments
573599
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
574-
/// * `address` - The user address for which the nonce will be retrieved.
600+
/// * `submitter_addr` - The user address for which the nonce will be retrieved.
601+
/// * `network` - The network from which the nonce will be retrieved.
602+
///
575603
/// # Returns
576604
/// * The next nonce of the proof submitter account from ethereum.
605+
///
577606
/// # Errors
578607
/// * `EthRpcError` if the batcher has an error in the Ethereum call when retrieving the nonce if not already cached.
579608
pub async fn get_nonce_from_ethereum(
@@ -600,10 +629,13 @@ pub async fn get_nonce_from_ethereum(
600629
}
601630

602631
/// Returns the chain ID of the Ethereum network.
632+
///
603633
/// # Arguments
604634
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
635+
///
605636
/// # Returns
606637
/// * The chain ID of the Ethereum network.
638+
///
607639
/// # Errors
608640
/// * `EthereumProviderError` if there is an error in the connection with the RPC provider.
609641
/// * `EthereumCallError` if there is an error in the Ethereum call.
@@ -619,13 +651,16 @@ pub async fn get_chain_id(eth_rpc_url: &str) -> Result<u64, errors::ChainIdError
619651
Ok(chain_id.as_u64())
620652
}
621653

622-
/// Funds the batcher payment service in name of the signer
654+
/// Funds the batcher payment service in name of the signer.
655+
///
623656
/// # Arguments
624657
/// * `amount` - The amount to be paid.
625658
/// * `signer` - The signer middleware of the payer.
626659
/// * `network` - The network on which the payment will be done.
660+
///
627661
/// # Returns
628662
/// * The receipt of the payment transaction.
663+
///
629664
/// # Errors
630665
/// * `SendError` if there is an error sending the transaction.
631666
/// * `SubmitError` if there is an error submitting the transaction.
@@ -656,12 +691,15 @@ pub async fn deposit_to_aligned(
656691
}
657692

658693
/// Returns the balance of a user in the payment service.
694+
///
659695
/// # Arguments
660696
/// * `user` - The address of the user.
661697
/// * `eth_rpc_url` - The URL of the Ethereum RPC node.
662698
/// * `network` - The network on which the balance will be checked.
699+
///
663700
/// # Returns
664701
/// * The balance of the user in the payment service.
702+
///
665703
/// # Errors
666704
/// * `EthereumProviderError` if there is an error in the connection with the RPC provider.
667705
/// * `EthereumCallError` if there is an error in the Ethereum call.
@@ -691,11 +729,14 @@ pub async fn get_balance_in_aligned(
691729
}
692730

693731
/// Saves AlignedVerificationData in a file.
732+
///
694733
/// # Arguments
695734
/// * `batch_inclusion_data_directory_path` - The path of the directory where the data will be saved.
696735
/// * `aligned_verification_data` - The aligned verification data to be saved.
736+
///
697737
/// # Returns
698738
/// * Ok if the data is saved successfully.
739+
///
699740
/// # Errors
700741
/// * `FileError` if there is an error writing the data to the file.
701742
pub fn save_response(

docs/1_introduction/1_try_aligned.md

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,6 @@ aligned submit \
3434
--proof ~/.aligned/test_files/sp1_fibonacci_4_1_3.proof \
3535
--vm_program ~/.aligned/test_files/sp1_fibonacci_4_1_3.elf \
3636
--aligned_verification_data_path ~/.aligned/aligned_verification_data \
37-
--batcher_url wss://batcher.alignedlayer.com \
3837
--network holesky \
3938
--rpc_url https://ethereum-holesky-rpc.publicnode.com
4039
```

docs/3_guides/0_submitting_proofs.md

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,6 @@ aligned submit \
148148
--proving_system SP1 \
149149
--proof ./scripts/test_files/sp1/sp1_fibonacci_4_1_3.proof \
150150
--vm_program ./scripts/test_files/sp1/sp1_fibonacci_4_1_3.elf \
151-
--batcher_url wss://batcher.alignedlayer.com \
152151
--keystore_path ~/.aligned_keystore/keystore0 \
153152
--network holesky \
154153
--rpc_url https://ethereum-holesky-rpc.publicnode.com
@@ -194,7 +193,6 @@ aligned submit \
194193
--proof ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.proof \
195194
--vm_program ./scripts/test_files/risc_zero/fibonacci_proof_generator/fibonacci_id_2_0.bin \
196195
--public_input ./scripts/test_files/risc_zero/fibonacci_proof_generator/risc_zero_fibonacci_2_0.pub \
197-
--batcher_url wss://batcher.alignedlayer.com \
198196
--aligned_verification_data_path ~/.aligned/aligned_verification_data \
199197
--keystore_path ~/.aligned_keystore/keystore0 \
200198
--network holesky \
@@ -212,7 +210,6 @@ aligned submit \
212210
--proof <proof_file> \
213211
--public_input <public_input_file> \
214212
--vk <verification_key_file> \
215-
--batcher_url wss://batcher.alignedlayer.com \
216213
--proof_generator_addr [proof_generator_addr] \
217214
--batch_inclusion_data_directory_path [batch_inclusion_data_directory_path] \
218215
--keystore_path <path_to_ecdsa_keystore> \
@@ -229,7 +226,6 @@ aligned submit \
229226
--proof ./scripts/test_files/gnark_plonk_bn254_script/plonk.proof \
230227
--public_input ./scripts/test_files/gnark_plonk_bn254_script/plonk_pub_input.pub \
231228
--vk ./scripts/test_files/gnark_plonk_bn254_script/plonk.vk \
232-
--batcher_url wss://batcher.alignedlayer.com \
233229
--keystore_path ~/.aligned_keystore/keystore0 \
234230
--network holesky \
235231
--rpc_url https://ethereum-holesky-rpc.publicnode.com
@@ -242,7 +238,6 @@ aligned submit \
242238
--proof ./scripts/test_files/gnark_plonk_bls12_381_script/plonk.proof \
243239
--public_input ./scripts/test_files/gnark_plonk_bls12_381_script/plonk_pub_input.pub \
244240
--vk ./scripts/test_files/gnark_plonk_bls12_381_script/plonk.vk \
245-
--batcher_url wss://batcher.alignedlayer.com \
246241
--keystore_path ~/.aligned_keystore/keystore0 \
247242
--network holesky \
248243
--rpc_url https://ethereum-holesky-rpc.publicnode.com
@@ -255,7 +250,6 @@ aligned submit \
255250
--proof ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_1_groth16.proof \
256251
--public_input ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_1_groth16.pub \
257252
--vk ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_1_groth16.vk \
258-
--batcher_url wss://batcher.alignedlayer.com \
259253
--keystore_path ~/.aligned_keystore/keystore0 \
260254
--network holesky \
261255
--rpc_url https://ethereum-holesky-rpc.publicnode.com

0 commit comments

Comments
 (0)