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

deps: update code to compile with latest miden-object #109

Merged
merged 1 commit into from
Dec 18, 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
2 changes: 1 addition & 1 deletion block-producer/src/batch_builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ impl TransactionBatch {
let produced_nullifiers = txs
.iter()
.flat_map(|tx| tx.consumed_notes())
.map(|consumed_note| consumed_note.nullifier())
.map(|nullifier| nullifier.inner())
.collect();

let (created_notes, created_notes_smt) = {
Expand Down
2 changes: 1 addition & 1 deletion block-producer/src/server/api.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ impl Store for DefaultStore {
nullifiers: proven_tx
.consumed_notes()
.iter()
.map(|note| note.nullifier().into())
.map(|nullifier| (*nullifier).into())
.collect(),
});
let response = self
Expand Down
28 changes: 17 additions & 11 deletions block-producer/src/state_view/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{collections::BTreeSet, sync::Arc};

use async_trait::async_trait;
use miden_objects::{accounts::AccountId, Digest};
use miden_objects::{accounts::AccountId, notes::Nullifier, Digest};
use tokio::sync::RwLock;

use crate::{
Expand Down Expand Up @@ -80,8 +80,11 @@ where
// Success! Register transaction as successfully verified
locked_accounts_in_flight.insert(candidate_tx.account_id());

let mut nullifiers_in_tx: BTreeSet<_> =
candidate_tx.consumed_notes().iter().map(|note| note.nullifier()).collect();
let mut nullifiers_in_tx: BTreeSet<_> = candidate_tx
.consumed_notes()
.iter()
.map(|nullifier| nullifier.inner())
.collect();
locked_nullifiers_in_flight.append(&mut nullifiers_in_tx);
}

Expand Down Expand Up @@ -142,11 +145,14 @@ fn ensure_in_flight_constraints(
}

// 2. Check no consumed notes were already consumed
let infracting_nullifiers: Vec<Digest> = {
let nullifiers_in_tx = candidate_tx.consumed_notes().iter().map(|note| note.nullifier());

nullifiers_in_tx
.filter(|nullifier_in_tx| already_consumed_nullifiers.contains(nullifier_in_tx))
let infracting_nullifiers: Vec<Nullifier> = {
candidate_tx
.consumed_notes()
.iter()
.filter(|&nullifier_in_tx| {
already_consumed_nullifiers.contains(&nullifier_in_tx.inner())
})
.cloned()
.collect()
};

Expand Down Expand Up @@ -178,11 +184,11 @@ fn ensure_tx_inputs_constraints(
},
}

let infracting_nullifiers: Vec<_> = tx_inputs
let infracting_nullifiers: Vec<Nullifier> = tx_inputs
.nullifiers
.into_iter()
.filter(|&(_nullifier_in_tx, is_already_consumed)| is_already_consumed)
.map(|(nullifier_in_tx, _is_already_consumed)| nullifier_in_tx)
.filter(|&(_, is_already_consumed)| is_already_consumed)
.map(|(nullifier_in_tx, _)| nullifier_in_tx.into())
.collect();

if !infracting_nullifiers.is_empty() {
Expand Down
4 changes: 1 addition & 3 deletions block-producer/src/state_view/tests/apply_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,6 @@ async fn test_apply_block_ab3() {
let verify_tx_res = state_view.verify_tx(tx_new.into()).await;
assert_eq!(
verify_tx_res,
Err(VerifyTxError::ConsumedNotesAlreadyConsumed(
txs[0].consumed_notes().iter().map(|note| note.nullifier()).collect()
))
Err(VerifyTxError::ConsumedNotesAlreadyConsumed(txs[0].consumed_notes().to_vec()))
);
}
9 changes: 6 additions & 3 deletions block-producer/src/state_view/tests/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use miden_objects::{transaction::ConsumedNoteInfo, Hasher};
use miden_crypto::ZERO;
use miden_objects::{notes::Nullifier, Hasher, EMPTY_WORD};

use super::*;
use crate::test_utils::{DummyProvenTxGenerator, MockPrivateAccount};
Expand All @@ -9,15 +10,17 @@ mod verify_tx;
// HELPERS
// -------------------------------------------------------------------------------------------------

pub fn consumed_note_by_index(index: u32) -> ConsumedNoteInfo {
ConsumedNoteInfo::new(
pub fn consumed_note_by_index(index: u32) -> Nullifier {
Nullifier::new(
Hasher::hash(&index.to_be_bytes()),
Hasher::hash(
&[index.to_be_bytes(), index.to_be_bytes()]
.into_iter()
.flatten()
.collect::<Vec<_>>(),
),
EMPTY_WORD.into(),
[ZERO, ZERO, ZERO, index.into()],
)
}

Expand Down
10 changes: 3 additions & 7 deletions block-producer/src/state_view/tests/verify_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ async fn test_verify_tx_vt3() {
let store = Arc::new(
MockStoreSuccessBuilder::new()
.initial_accounts(iter::once((account.id, account.states[0])))
.initial_nullifiers(BTreeSet::from_iter(iter::once(consumed_note_in_store.nullifier())))
.initial_nullifiers(BTreeSet::from_iter(iter::once(consumed_note_in_store.inner())))
.build(),
);

Expand All @@ -174,9 +174,7 @@ async fn test_verify_tx_vt3() {

assert_eq!(
verify_tx_result,
Err(VerifyTxError::ConsumedNotesAlreadyConsumed(vec![
consumed_note_in_store.nullifier()
]))
Err(VerifyTxError::ConsumedNotesAlreadyConsumed(vec![consumed_note_in_store]))
);
}

Expand Down Expand Up @@ -269,8 +267,6 @@ async fn test_verify_tx_vt5() {
let verify_tx2_result = state_view.verify_tx(tx2.into()).await;
assert_eq!(
verify_tx2_result,
Err(VerifyTxError::ConsumedNotesAlreadyConsumed(vec![
consumed_note_in_both_txs.nullifier()
]))
Err(VerifyTxError::ConsumedNotesAlreadyConsumed(vec![consumed_note_in_both_txs]))
);
}
6 changes: 3 additions & 3 deletions block-producer/src/test_utils/proven_tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ use miden_crypto::hash::rpo::Rpo256;
use miden_mock::constants::ACCOUNT_ID_REGULAR_ACCOUNT_UPDATABLE_CODE_ON_CHAIN;
use miden_objects::{
accounts::AccountId,
notes::{NoteEnvelope, NoteMetadata},
transaction::{ConsumedNoteInfo, ProvenTransaction},
notes::{NoteEnvelope, NoteMetadata, Nullifier},
transaction::ProvenTransaction,
Digest, ONE, ZERO,
};
use once_cell::sync::Lazy;
Expand Down Expand Up @@ -127,7 +127,7 @@ impl DummyProvenTxGenerator {
account_id: AccountId,
initial_account_hash: Digest,
final_account_hash: Digest,
consumed_notes: Vec<ConsumedNoteInfo>,
consumed_notes: Vec<Nullifier>,
created_notes: Vec<NoteEnvelope>,
) -> ProvenTransaction {
ProvenTransaction::new(
Expand Down
4 changes: 3 additions & 1 deletion block-producer/src/test_utils/store.rs
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,9 @@ impl Store for MockStoreSuccess {
let nullifiers = proven_tx
.consumed_notes()
.iter()
.map(|note| (note.nullifier(), locked_consumed_nullifiers.contains(&note.nullifier())))
.map(|nullifier| {
(nullifier.inner(), locked_consumed_nullifiers.contains(&nullifier.inner()))
})
.collect();

Ok(TxInputs {
Expand Down
4 changes: 2 additions & 2 deletions block-producer/src/txqueue/mod.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{fmt::Debug, sync::Arc, time::Duration};

use async_trait::async_trait;
use miden_objects::{accounts::AccountId, Digest};
use miden_objects::{accounts::AccountId, notes::Nullifier, Digest};
use tokio::{sync::RwLock, time};

use crate::{batch_builder::BatchBuilder, store::TxInputsError, SharedProvenTx, SharedRwVec};
Expand All @@ -19,7 +19,7 @@ pub enum VerifyTxError {
AccountAlreadyModifiedByOtherTx(AccountId),

/// Another transaction already consumed the notes with given nullifiers
ConsumedNotesAlreadyConsumed(Vec<Digest>),
ConsumedNotesAlreadyConsumed(Vec<Nullifier>),

/// The account's initial hash did not match the current account's hash
IncorrectAccountInitialHash {
Expand Down
21 changes: 19 additions & 2 deletions proto/src/conversion.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,15 @@ use miden_crypto::{
merkle::{MerklePath, MmrDelta, MmrPeaks, TieredSmtProof},
Felt, FieldElement, StarkField, Word,
};
use miden_objects::{accounts::AccountId, notes::NoteEnvelope, BlockHeader, Digest as RpoDigest};
use miden_objects::{
accounts::AccountId,
notes::{NoteEnvelope, Nullifier},
BlockHeader, Digest as RpoDigest,
};

use crate::{
account_id, block_header, digest,
account_id, block_header,
digest::{self, Digest},
domain::{AccountInputRecord, BlockInputs, NullifierInputRecord},
error, merkle, mmr, note, requests, responses, tsmt,
};
Expand Down Expand Up @@ -375,6 +380,18 @@ impl From<(u64, NoteEnvelope)> for note::NoteCreated {
}
}

impl From<&Nullifier> for Digest {
fn from(value: &Nullifier) -> Self {
(*value).inner().into()
}
}

impl From<Nullifier> for Digest {
fn from(value: Nullifier) -> Self {
value.inner().into()
}
}

// UTILITIES
// ================================================================================================

Expand Down
Loading