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

PRO-344: update contract ABI to match audit changes #632

Merged
merged 4 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions crates/micro-oz/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use ethers::prelude::SignerMiddleware;
use ethers::providers::{Http, Middleware, Provider};
use ethers::signers::{LocalWallet, Signer};
use ethers::types::transaction::eip2718::TypedTransaction;
use ethers::types::Eip1559TransactionRequest;
use ethers::types::{Eip1559TransactionRequest, U64};
use oz_api::data::transactions::{RelayerTransactionBase, SendBaseTransactionRequestOwned, Status};
use tokio::sync::{mpsc, Mutex};

Expand Down Expand Up @@ -101,9 +101,15 @@ async fn runner_inner(inner: &Arc<PinheadInner>, tx_id: String) -> Result<(), an

let mut tx_guard = tx.lock().await;

if let Some(_receipt) = receipt {
if let Some(receipt) = receipt {
if let Some(U64([0])) = receipt.status {
tracing::error!("Receipt: {:?}", receipt);
} else {
tracing::info!("Receipt: {:?}", receipt);
}
tx_guard.status = Status::Mined;
} else {
tracing::error!("Receipt not found");
tx_guard.status = Status::Failed;
}

Expand Down
12,646 changes: 0 additions & 12,646 deletions sol/SemaphoreVerifier.json

This file was deleted.

21,272 changes: 21,272 additions & 0 deletions sol/SemaphoreVerifier20.json

Large diffs are not rendered by default.

1,522 changes: 659 additions & 863 deletions sol/SequencerVerifier.json

Large diffs are not rendered by default.

18,585 changes: 4,661 additions & 13,924 deletions sol/WorldIDIdentityManagerImplV1.json

Large diffs are not rendered by default.

3,434 changes: 1,682 additions & 1,752 deletions sol/WorldIDIdentityManagerImplV2.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/contracts/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
0 => Self::Insertion,
1 => Self::Deletion,
2 => Self::Update,
_ => panic!("Invalid value for TreeChangeKind: {}", value),

Check warning on line 28 in src/contracts/abi.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/contracts/abi.rs:28:18 | 28 | _ => panic!("Invalid value for TreeChangeKind: {}", value), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args note: the lint level is defined here --> src/lib.rs:2:22 | 2 | #![warn(clippy::all, clippy::pedantic, clippy::cargo)] | ^^^^^^^^^^^^^^^^ = note: `#[warn(clippy::uninlined_format_args)]` implied by `#[warn(clippy::pedantic)]` help: change this to | 28 - _ => panic!("Invalid value for TreeChangeKind: {}", value), 28 + _ => panic!("Invalid value for TreeChangeKind: {value}"), |

Check warning on line 28 in src/contracts/abi.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/contracts/abi.rs:28:18 | 28 | _ => panic!("Invalid value for TreeChangeKind: {}", value), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args note: the lint level is defined here --> src/lib.rs:2:22 | 2 | #![warn(clippy::all, clippy::pedantic, clippy::cargo)] | ^^^^^^^^^^^^^^^^ = note: `#[warn(clippy::uninlined_format_args)]` implied by `#[warn(clippy::pedantic)]` help: change this to | 28 - _ => panic!("Invalid value for TreeChangeKind: {}", value), 28 + _ => panic!("Invalid value for TreeChangeKind: {value}"), |

Check warning on line 28 in src/contracts/abi.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/contracts/abi.rs:28:18 | 28 | _ => panic!("Invalid value for TreeChangeKind: {}", value), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args note: the lint level is defined here --> src/lib.rs:2:22 | 2 | #![warn(clippy::all, clippy::pedantic, clippy::cargo)] | ^^^^^^^^^^^^^^^^ = note: `#[warn(clippy::uninlined_format_args)]` implied by `#[warn(clippy::pedantic)]` help: change this to | 28 - _ => panic!("Invalid value for TreeChangeKind: {}", value), 28 + _ => panic!("Invalid value for TreeChangeKind: {value}"), |
}
}
}
Expand All @@ -36,7 +36,7 @@
struct RootInfo { uint256 root; uint128 supersededTimestamp; bool isValid }
event TreeChanged(uint256 indexed preRoot, uint8 indexed kind, uint256 indexed postRoot)
function registerIdentities(uint256[8] calldata insertionProof, uint256 preRoot, uint32 startIndex, uint256[] calldata identityCommitments, uint256 postRoot) public virtual
function deleteIdentities(uint256[8] calldata deletionProof, uint32 batchSize, bytes calldata packedDeletionIndices, uint256 preRoot, uint256 postRoot) public virtual
function deleteIdentities(uint256[8] calldata deletionProof, bytes calldata packedDeletionIndices, uint256 preRoot, uint256 postRoot) public virtual
function latestRoot() public view virtual returns (uint256 root)
function owner() public view virtual returns (address)
function queryRoot(uint256 root) public view virtual returns (RootInfo memory)
Expand Down
2 changes: 0 additions & 2 deletions src/contracts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,6 @@
pub async fn delete_identities(
&self,
deletion_proof: Proof,
batch_size: u32,
packed_deletion_indices: Vec<u8>,
pre_root: U256,
post_root: U256,
Expand All @@ -311,7 +310,6 @@
.abi
.delete_identities(
proof_points_array,
batch_size,
packed_deletion_indices.into(),
pre_root,
post_root,
Expand Down Expand Up @@ -374,7 +372,7 @@
.await?
.context("Missing tx")?;

use ethers::abi::AbiDecode;

Check warning on line 375 in src/contracts/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

adding items after statements is confusing, since items exist from the start of the scope

warning: adding items after statements is confusing, since items exist from the start of the scope --> src/contracts/mod.rs:375:9 | 375 | use ethers::abi::AbiDecode; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements = note: `#[warn(clippy::items_after_statements)]` implied by `#[warn(clippy::pedantic)]`

Check warning on line 375 in src/contracts/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

adding items after statements is confusing, since items exist from the start of the scope

warning: adding items after statements is confusing, since items exist from the start of the scope --> src/contracts/mod.rs:375:9 | 375 | use ethers::abi::AbiDecode; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements = note: `#[warn(clippy::items_after_statements)]` implied by `#[warn(clippy::pedantic)]`

Check warning on line 375 in src/contracts/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

adding items after statements is confusing, since items exist from the start of the scope

warning: adding items after statements is confusing, since items exist from the start of the scope --> src/contracts/mod.rs:375:9 | 375 | use ethers::abi::AbiDecode; | ^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#items_after_statements = note: `#[warn(clippy::items_after_statements)]` implied by `#[warn(clippy::pedantic)]`
let delete_identities = DeleteIdentitiesCall::decode(&tx.input)?;

let packed_deletion_indices: &[u8] = delete_identities.packed_deletion_indices.as_ref();
Expand All @@ -382,7 +380,7 @@

tracing::error!("unpacked = {indices:?}");

let padding_index = 2u32.pow(self.tree_depth as u32);

Check warning on line 383 in src/contracts/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/contracts/mod.rs:383:38 | 383 | let padding_index = 2u32.pow(self.tree_depth as u32); | ^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation = note: `#[warn(clippy::cast_possible_truncation)]` implied by `#[warn(clippy::pedantic)]` help: ... or use `try_from` and handle the error accordingly | 383 | let padding_index = 2u32.pow(u32::try_from(self.tree_depth)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 383 in src/contracts/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/contracts/mod.rs:383:38 | 383 | let padding_index = 2u32.pow(self.tree_depth as u32); | ^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation = note: `#[warn(clippy::cast_possible_truncation)]` implied by `#[warn(clippy::pedantic)]` help: ... or use `try_from` and handle the error accordingly | 383 | let padding_index = 2u32.pow(u32::try_from(self.tree_depth)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 383 in src/contracts/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/contracts/mod.rs:383:38 | 383 | let padding_index = 2u32.pow(self.tree_depth as u32); | ^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation = note: `#[warn(clippy::cast_possible_truncation)]` implied by `#[warn(clippy::pedantic)]` help: ... or use `try_from` and handle the error accordingly | 383 | let padding_index = 2u32.pow(u32::try_from(self.tree_depth)); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Ok(indices
.into_iter()
Expand Down
8 changes: 1 addition & 7 deletions src/task_monitor/tasks/process_identities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -204,37 +204,37 @@
updates: &[AppliedTreeUpdate],
) -> AnyhowResult<()> {
// If the update is an insertion
if updates
.first()
.context("Updates should be > 1")?
.update
.element
!= Hash::ZERO
{
let prover = identity_manager
.get_suitable_insertion_prover(updates.len())
.await?;

info!(
"Sending timed-out insertion batch with {}/{} updates.",
updates.len(),
prover.batch_size()
);

insert_identities(database, identity_manager, batching_tree, updates, prover).await?;
} else {
let prover = identity_manager
.get_suitable_deletion_prover(updates.len())
.await?;

info!(
"Sending timed-out deletion batch with {}/{} updates.",
updates.len(),
prover.batch_size()
);

delete_identities(database, identity_manager, batching_tree, updates, prover).await?;
}

Check warning on line 237 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary `!=` operation

warning: unnecessary `!=` operation --> src/task_monitor/tasks/process_identities.rs:207:5 | 207 | / if updates 208 | | .first() 209 | | .context("Updates should be > 1")? 210 | | .update ... | 236 | | delete_identities(database, identity_manager, batching_tree, updates, prover).await?; 237 | | } | |_____^ | = help: change to `==` and swap the blocks of the `if`/`else` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else = note: `#[warn(clippy::if_not_else)]` implied by `#[warn(clippy::pedantic)]`

Check warning on line 237 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary `!=` operation

warning: unnecessary `!=` operation --> src/task_monitor/tasks/process_identities.rs:207:5 | 207 | / if updates 208 | | .first() 209 | | .context("Updates should be > 1")? 210 | | .update ... | 236 | | delete_identities(database, identity_manager, batching_tree, updates, prover).await?; 237 | | } | |_____^ | = help: change to `==` and swap the blocks of the `if`/`else` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else = note: `#[warn(clippy::if_not_else)]` implied by `#[warn(clippy::pedantic)]`

Check warning on line 237 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

unnecessary `!=` operation

warning: unnecessary `!=` operation --> src/task_monitor/tasks/process_identities.rs:207:5 | 207 | / if updates 208 | | .first() 209 | | .context("Updates should be > 1")? 210 | | .update ... | 236 | | delete_identities(database, identity_manager, batching_tree, updates, prover).await?; 237 | | } | |_____^ | = help: change to `==` and swap the blocks of the `if`/`else` = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_not_else = note: `#[warn(clippy::if_not_else)]` implied by `#[warn(clippy::pedantic)]`

Ok(())
}
Expand Down Expand Up @@ -273,11 +273,11 @@
.map(|update| update.update.element)
.collect::<Vec<_>>();

panic!(
"Identities are not consecutive leaves in the tree (leaf_indexes = {:?}, \
commitments = {:?})",
leaf_indexes, commitments
);

Check warning on line 280 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/task_monitor/tasks/process_identities.rs:276:13 | 276 | / panic!( 277 | | "Identities are not consecutive leaves in the tree (leaf_indexes = {:?}, \ 278 | | commitments = {:?})", 279 | | leaf_indexes, commitments 280 | | ); | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args

Check warning on line 280 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/task_monitor/tasks/process_identities.rs:276:13 | 276 | / panic!( 277 | | "Identities are not consecutive leaves in the tree (leaf_indexes = {:?}, \ 278 | | commitments = {:?})", 279 | | leaf_indexes, commitments 280 | | ); | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args

Check warning on line 280 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

variables can be used directly in the `format!` string

warning: variables can be used directly in the `format!` string --> src/task_monitor/tasks/process_identities.rs:276:13 | 276 | / panic!( 277 | | "Identities are not consecutive leaves in the tree (leaf_indexes = {:?}, \ 278 | | commitments = {:?})", 279 | | leaf_indexes, commitments 280 | | ); | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#uninlined_format_args
}

last_index = update.update.leaf_index;
Expand Down Expand Up @@ -446,7 +446,7 @@

let mut deletion_indices = updates
.iter()
.map(|f| f.update.leaf_index as u32)

Check warning on line 449 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/task_monitor/tasks/process_identities.rs:449:18 | 449 | .map(|f| f.update.leaf_index as u32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation help: ... or use `try_from` and handle the error accordingly | 449 | .map(|f| u32::try_from(f.update.leaf_index)) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 449 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/task_monitor/tasks/process_identities.rs:449:18 | 449 | .map(|f| f.update.leaf_index as u32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation help: ... or use `try_from` and handle the error accordingly | 449 | .map(|f| u32::try_from(f.update.leaf_index)) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 449 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/task_monitor/tasks/process_identities.rs:449:18 | 449 | .map(|f| f.update.leaf_index as u32) | ^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation help: ... or use `try_from` and handle the error accordingly | 449 | .map(|f| u32::try_from(f.update.leaf_index)) | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
.collect::<Vec<u32>>();

let commitments =
Expand Down Expand Up @@ -487,7 +487,7 @@
// ensure that our batches match that size. We do this by padding deletion
// indices with tree.depth() ^ 2. The deletion prover will skip the proof for
// any deletion with an index greater than the max tree depth
let pad_index = 2_u32.pow(latest_tree_from_updates.depth() as u32);

Check warning on line 490 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/task_monitor/tasks/process_identities.rs:490:31 | 490 | let pad_index = 2_u32.pow(latest_tree_from_updates.depth() as u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation help: ... or use `try_from` and handle the error accordingly | 490 | let pad_index = 2_u32.pow(u32::try_from(latest_tree_from_updates.depth())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 490 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/task_monitor/tasks/process_identities.rs:490:31 | 490 | let pad_index = 2_u32.pow(latest_tree_from_updates.depth() as u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation help: ... or use `try_from` and handle the error accordingly | 490 | let pad_index = 2_u32.pow(u32::try_from(latest_tree_from_updates.depth())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Check warning on line 490 in src/task_monitor/tasks/process_identities.rs

View workflow job for this annotation

GitHub Actions / clippy

casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers

warning: casting `usize` to `u32` may truncate the value on targets with 64-bit wide pointers --> src/task_monitor/tasks/process_identities.rs:490:31 | 490 | let pad_index = 2_u32.pow(latest_tree_from_updates.depth() as u32); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ | = help: if this is intentional allow the lint with `#[allow(clippy::cast_possible_truncation)]` ... = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#cast_possible_truncation help: ... or use `try_from` and handle the error accordingly | 490 | let pad_index = 2_u32.pow(u32::try_from(latest_tree_from_updates.depth())); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

if commitment_count != batch_size {
let padding = batch_size - commitment_count;
Expand Down Expand Up @@ -548,13 +548,7 @@
// With all the data prepared we can submit the identities to the on-chain
// identity manager and wait for that transaction to be mined.
let transaction_id = identity_manager
.delete_identities(
proof,
batch_size as u32,
packed_deletion_indices,
pre_root,
post_root,
)
.delete_identities(proof, packed_deletion_indices, pre_root, post_root)
.await
.map_err(|e| {
error!(?e, "Failed to insert identity to contract.");
Expand Down
37 changes: 1 addition & 36 deletions tests/common/abi.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,45 +5,10 @@ use ethers::prelude::abigen;
abigen!(
BatchingContract,
r#"[
struct RootInfo { uint256 root; uint128 supersededTimestamp; bool isValid }
function NO_SUCH_ROOT() public pure returns (RootInfo memory rootInfo)
error UnreducedElement(uint8 elementType, uint256 element)
error Unauthorized(address user)
error InvalidCommitment(uint256 commitment)
error ProofValidationFailure()
error NotLatestRoot(uint256 providedRoot, uint256 latestRoot)
error ExpiredRoot()
error NonExistentRoot()
error ImplementationNotInitalized()
error NoSuchVerifier()
error MismatchedInputLengths()
constructor(address _logic, bytes memory data) payable
function initialize(uint8 treeDepth, uint256 initialRoot, address _batchInsertionVerifiers, address _batchUpdateVerifiers, address _semaphoreVerifier) public virtual
function initializeV2(address _batchDeletionVerifiers) public virtual
function deleteIdentities(uint256[8] calldata deletionProof, uint256 preRoot, bytes calldata deletionIndices, uint256 postRoot) public virtual
function registerIdentities(uint256[8] calldata insertionProof, uint256 preRoot, uint32 startIndex, uint256[] calldata identityCommitments, uint256 postRoot) public virtual
function updateIdentities(uint256[8] calldata updateProof, uint256 preRoot, uint32[] calldata leafIndices, uint256[] calldata oldIdentities, uint256[] calldata newIdentities, uint256 postRoot) public virtual
function calculateIdentityRegistrationInputHash(uint32 startIndex, uint256 preRoot, uint256 postRoot, uint256[] identityCommitments) public view virtual returns (bytes32 hash)
function calculateIdentityUpdateInputHash(uint256 preRoot, uint256 postRoot, uint32[] calldata leafIndices, uint256[] calldata oldIdentities, uint256[] calldata newIdentities) public view virtual returns (bytes32 hash)
function latestRoot() public view virtual returns (uint256 root)
function queryRoot(uint256 root) public view virtual returns (RootInfo memory rootInfo)
function isInputInReducedForm(uint256 input) public view virtual returns (bool isInReducedForm)
function checkValidRoot(uint256 root) public view virtual returns (bool)
function getRegisterIdentitiesVerifierLookupTableAddress() public view virtual returns (address addr)
function setRegisterIdentitiesVerifierLookupTable(address newVerifier) public virtual
function getIdentityUpdateVerifierLookupTableAddress() public view virtual returns (address addr)
function setIdentityUpdateVerifierLookupTable(address newVerifier) public virtual
function getSemaphoreVerifierAddress() public view virtual returns (address addr)
function setSemaphoreVerifier(address newVerifier) public virtual
function getRootHistoryExpiry() public view virtual returns (uint256 expiryTime)
function setRootHistoryExpiry(uint256 newExpiryTime) public virtual
function verifyProof(uint256 root, uint256 signalHash, uint256 nullifierHash, uint256 externalNullifierHash, uint256[8] calldata proof) public view virtual
function owner() public view virtual returns (address)
function renounceOwnership() public virtual
function transferOwnership(address newOwner) public virtual
function proxiableUUID() external view virtual override returns (bytes32)
function upgradeTo(address newImplementation) external virtual
function upgradeToAndCall(address newImplementation, bytes memory data) external payable virtual
function setRootHistoryExpiry(uint256 newExpiryTime) public virtual
]"#,
event_derives(serde::Deserialize, serde::Serialize)
);
2 changes: 1 addition & 1 deletion tests/common/chain_mock.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ pub async fn spawn_mock_chain(
.send()
.await?;

let verifier_path = "./sol/SemaphoreVerifier.json";
let verifier_path = "./sol/SemaphoreVerifier20.json";
let verifier_file =
File::open(verifier_path).unwrap_or_else(|_| panic!("Failed to open `{verifier_path}`"));

Expand Down
76 changes: 44 additions & 32 deletions tests/common/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@
use self::prelude::*;
use self::prover_mock::ProverType;

const NUM_ATTEMPTS_FOR_INCLUSION_PROOF: usize = 20;

#[allow(clippy::too_many_arguments)]
#[instrument(skip_all)]
pub async fn test_verify_proof(
Expand Down Expand Up @@ -223,7 +225,7 @@
leaf: &Hash,
expect_failure: bool,
) {
for i in 1..21 {
for i in 0..NUM_ATTEMPTS_FOR_INCLUSION_PROOF {
let body = construct_inclusion_proof_body(leaf);
info!(?uri, "Contacting");
let req = Request::builder()
Expand Down Expand Up @@ -262,16 +264,23 @@
generate_reference_proof_json(ref_tree, leaf_index, "pending")
);
assert_eq!(response.status(), StatusCode::ACCEPTED);
info!("Got pending, waiting 1 second, iteration {}", i);
tokio::time::sleep(Duration::from_secs(1)).await;
info!("Got pending, waiting 5 seconds, iteration {}", i);
tokio::time::sleep(Duration::from_secs(5)).await;
} else if status == "mined" {
// We don't differentiate between these 2 states in tests
let proof_json = generate_reference_proof_json(ref_tree, leaf_index, status);
assert_eq!(result_json, proof_json);

return;
} else {
panic!("Unexpected status: {}", status);
}
}

panic!(
"Failed to get an inclusion proof after {} attempts!",
NUM_ATTEMPTS_FOR_INCLUSION_PROOF
);
}

#[instrument(skip_all)]
Expand All @@ -281,37 +290,40 @@
leaf: &Hash,
expected_status: Status,
) {
for _i in 1..21 {
let body = construct_inclusion_proof_body(leaf);
info!(?uri, "Contacting");
let req = Request::builder()
.method("POST")
.uri(uri.to_owned() + "/inclusionProof")
.header("Content-Type", "application/json")
.body(body)
.expect("Failed to create inclusion proof hyper::Body");

let mut response = client
.request(req)
.await
.expect("Failed to execute request.");
let body = construct_inclusion_proof_body(leaf);
info!(?uri, "Contacting");
let req = Request::builder()
.method("POST")
.uri(uri.to_owned() + "/inclusionProof")
.header("Content-Type", "application/json")
.body(body)
.expect("Failed to create inclusion proof hyper::Body");

let bytes = hyper::body::to_bytes(response.body_mut())
.await
.expect("Failed to convert response body to bytes");
let result = String::from_utf8(bytes.into_iter().collect())
.expect("Could not parse response bytes to utf-8");
let result_json = serde_json::from_str::<serde_json::Value>(&result)
.expect("Failed to parse response as json");
let status = result_json["status"]
.as_str()
.expect("Failed to get status");
let mut response = client
.request(req)
.await
.expect("Failed to execute request.");

assert_eq!(
expected_status,
Status::from_str(status).expect("Could not convert str to Status")
);
}
let bytes = hyper::body::to_bytes(response.body_mut())
.await
.expect("Failed to convert response body to bytes");
let result = String::from_utf8(bytes.into_iter().collect())
.expect("Could not parse response bytes to utf-8");
println!(
"########################################################## \n
result: {:?}",
result
);
let result_json = serde_json::from_str::<serde_json::Value>(&result)
.expect("Failed to parse response as json");
let status = result_json["status"]
.as_str()
.expect("Failed to get status");

assert_eq!(
expected_status,
Status::from_str(status).expect("Could not convert str to Status")
);
}

#[instrument(skip_all)]
Expand Down Expand Up @@ -351,17 +363,17 @@
(ref_tree.proof(leaf_index).unwrap(), ref_tree.root())
}

#[instrument(skip_all)]
pub async fn test_recover_identity(
uri: &str,
client: &Client<HttpConnector>,
ref_tree: &mut PoseidonTree,
test_leaves: &[Field],
previous_leaf_index: usize,
new_leaf: Field,
new_leaf_index: usize,
expect_failure: bool,
) -> (merkle_tree::Proof<PoseidonHash>, Field) {

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)

Check warning on line 376 in tests/common/mod.rs

View workflow job for this annotation

GitHub Actions / clippy

this function has too many arguments (8/7)

warning: this function has too many arguments (8/7) --> tests/common/mod.rs:366:1 | 366 | #[instrument(skip_all)] | ^---------------------- | | | _in this procedural macro expansion | | 367 | | pub async fn test_recover_identity( 368 | | uri: &str, 369 | | client: &Client<HttpConnector>, ... | 375 | | expect_failure: bool, 376 | | ) -> (merkle_tree::Proof<PoseidonHash>, Field) { | |______________________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default = note: this warning originates in the attribute macro `instrument` (in Nightly builds, run with -Z macro-backtrace for more info)
let previous_leaf = test_leaves[previous_leaf_index];

let body = construct_recover_identity_body(&previous_leaf, &new_leaf);
Expand Down
35 changes: 20 additions & 15 deletions tests/dynamic_batch_sizes.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,26 +8,33 @@ use hyper::Uri;
use crate::common::{test_add_batch_size, test_remove_batch_size};

const SUPPORTED_DEPTH: usize = 20;
const IDLE_TIME: u64 = 7;
const IDLE_TIME: u64 = 10;

#[tokio::test]
async fn dynamic_batch_sizes() -> anyhow::Result<()> {
// Initialize logging for the test.
init_tracing_subscriber();
info!("Starting integration test");

let batch_size: usize = 3;
let first_batch_size: usize = 3;
let second_batch_size: usize = 2;

#[allow(clippy::cast_possible_truncation)]
let tree_depth: u8 = SUPPORTED_DEPTH as u8;

let mut ref_tree = PoseidonTree::new(SUPPORTED_DEPTH + 1, ruint::Uint::ZERO);
let initial_root: U256 = ref_tree.root().into();

let (mock_chain, db_container, insertion_prover_map, _, micro_oz) =
spawn_deps(initial_root, &[batch_size], &[], tree_depth).await?;
let (mock_chain, db_container, insertion_prover_map, _, micro_oz) = spawn_deps(
initial_root,
&[first_batch_size, second_batch_size],
&[],
tree_depth,
)
.await?;

let prover_mock = &insertion_prover_map[&batch_size];
let first_prover = &insertion_prover_map[&first_batch_size];
let second_prover = &insertion_prover_map[&second_batch_size];

let port = db_container.port();
let db_url = format!("postgres://postgres:postgres@localhost:{port}/database");
Expand All @@ -45,7 +52,7 @@ async fn dynamic_batch_sizes() -> anyhow::Result<()> {
"--tree-depth",
&format!("{tree_depth}"),
"--prover-urls",
&prover_mock.arg_string(),
&first_prover.arg_string(),
"--batch-timeout-seconds",
"3",
"--dense-tree-prefix-depth",
Expand Down Expand Up @@ -75,7 +82,7 @@ async fn dynamic_batch_sizes() -> anyhow::Result<()> {
.await
.expect("Failed to spawn app.");

let test_identities = generate_test_identities(batch_size * 5);
let test_identities = generate_test_identities(first_batch_size * 5);
let identities_ref: Vec<Field> = test_identities
.iter()
.map(|i| Hash::from_str_radix(i, 16).unwrap())
Expand Down Expand Up @@ -125,9 +132,6 @@ async fn dynamic_batch_sizes() -> anyhow::Result<()> {
)
.await;

// Add a new prover for batch sizes of two.
let second_prover = spawn_mock_insertion_prover(second_batch_size, tree_depth).await?;

test_add_batch_size(
&uri,
second_prover.url(),
Expand Down Expand Up @@ -162,17 +166,17 @@ async fn dynamic_batch_sizes() -> anyhow::Result<()> {
"prover_type": "insertion",
},
{
"url": prover_mock.url() + "/",
"url": first_prover.url() + "/",
"timeout_s": 30,
"batch_size": batch_size,
"batch_size": first_batch_size,
"prover_type": "insertion",

}
])
);

// Insert enough identities to trigger the lower batch size.
prover_mock.set_availability(false).await;
first_prover.set_availability(false).await;
test_insert_identity(&uri, &client, &mut ref_tree, &identities_ref, 3).await;
test_insert_identity(&uri, &client, &mut ref_tree, &identities_ref, 4).await;

Expand All @@ -181,6 +185,7 @@ async fn dynamic_batch_sizes() -> anyhow::Result<()> {
tokio::time::resume();

tokio::time::sleep(Duration::from_secs(IDLE_TIME)).await;

// Check that we can also get these inclusion proofs back.
test_inclusion_proof(
&uri,
Expand All @@ -206,9 +211,9 @@ async fn dynamic_batch_sizes() -> anyhow::Result<()> {
// Now if we remove the original prover, things should still work.
test_remove_batch_size(
&uri,
batch_size as u64,
first_batch_size as u64,
&client,
prover_mock.prover_type(),
first_prover.prover_type(),
false,
)
.await?;
Expand Down
23 changes: 15 additions & 8 deletions tests/validate_proofs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,17 +92,24 @@ async fn validate_proofs() -> anyhow::Result<()> {
let (merkle_proof, root) =
test_insert_identity(&uri, &client, &mut ref_tree, &TEST_LEAVES, 0).await;

tokio::time::sleep(Duration::from_secs(5 + batch_timeout_seconds)).await;
// simulate client generating a proof
let nullifier_hash = generate_nullifier_hash(&IDENTITIES[0], external_nullifier_hash);

let proof = generate_proof(
&IDENTITIES[0],
&merkle_proof,
external_nullifier_hash,
signal_hash,
)
.unwrap();
// Generates proof in the background
let merkle_proof_for_task = merkle_proof.clone();
let proof_task = tokio::task::spawn_blocking(move || {
generate_proof(
&IDENTITIES[0],
&merkle_proof_for_task,
external_nullifier_hash,
signal_hash,
)
.unwrap()
});

tokio::time::sleep(Duration::from_secs(15 + batch_timeout_seconds)).await;

let proof = proof_task.await.unwrap();

test_verify_proof(
&uri,
Expand Down
Loading