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

funding: LQT nullifier set for epoch #5034

Merged
merged 10 commits into from
Jan 31, 2025
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
4 changes: 3 additions & 1 deletion crates/core/app-tests/tests/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ use penumbra_sdk_sct::{
use penumbra_sdk_shielded_pool::{
component::ShieldedPool, Note, SpendPlan, SpendProof, SpendProofPrivate, SpendProofPublic,
};
use penumbra_sdk_txhash::{EffectHash, TransactionContext};
use penumbra_sdk_txhash::{EffectHash, TransactionContext, TransactionId};
use rand_core::{OsRng, SeedableRng};
use std::{ops::Deref, sync::Arc};
use tendermint::abci;
Expand Down Expand Up @@ -65,6 +65,7 @@ async fn spend_happy_path() -> anyhow::Result<()> {
let transaction_context = TransactionContext {
anchor: root,
effect_hash: EffectHash(dummy_effect_hash),
transaction_id: TransactionId([0; 32]),
};

// 3. Simulate execution of the Spend action
Expand Down Expand Up @@ -189,6 +190,7 @@ async fn invalid_dummy_spend() {
let transaction_context = TransactionContext {
anchor: root,
effect_hash: EffectHash(dummy_effect_hash),
transaction_id: TransactionId([0; 32]),
};

// 3. Simulate execution of the Spend action
Expand Down
1 change: 1 addition & 0 deletions crates/core/component/funding/src/component.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use penumbra_sdk_asset::{Value, STAKING_TOKEN_ASSET_ID};
use penumbra_sdk_proto::{DomainType, StateWriteProto};
use penumbra_sdk_stake::component::validator_handler::ValidatorDataRead;
pub use view::{StateReadExt, StateWriteExt};
pub(crate) mod liquidity_tournament;

use std::sync::Arc;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pub mod nullifier;
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use async_trait::async_trait;
use penumbra_sdk_txhash::TransactionId;

use crate::component::state_key;
use cnidarium::{StateRead, StateWrite};
use penumbra_sdk_proto::{StateReadProto, StateWriteProto};
use penumbra_sdk_sct::{component::clock::EpochRead, Nullifier};

#[allow(dead_code)]
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will be consumed by #5033, silencing for compilation purposes

#[async_trait]
pub trait NullifierRead: StateRead {
/// Returns the `TransactionId` if the nullifier has been spent; otherwise, returns None.
async fn get_lqt_spent_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> {
// Grab the ambient epoch index.
let epoch_index = self
.get_current_epoch()
.await
.expect("epoch is always set")
.index;

let nullifier_key = &state_key::lqt::v1::nullifier::key(epoch_index, &nullifier);

let tx_id: Option<TransactionId> = self
.nonverifiable_get(&nullifier_key.as_bytes())
.await
.expect(&format!(
"failed to retrieve key {} from non-verifiable storage",
nullifier_key,
));

tx_id
}
}

impl<T: StateRead + ?Sized> NullifierRead for T {}

#[allow(dead_code)]
#[async_trait]
pub trait NullifierWrite: StateWrite {
/// Sets the LQT nullifier in the NV storage.
fn put_lqt_spent_nullifier(
&mut self,
epoch_index: u64,
nullifier: Nullifier,
tx_id: TransactionId,
) {
let nullifier_key = state_key::lqt::v1::nullifier::key(epoch_index, &nullifier);

self.nonverifiable_put(nullifier_key.into(), tx_id);
}
}

impl<T: StateWrite + ?Sized> NullifierWrite for T {}
13 changes: 13 additions & 0 deletions crates/core/component/funding/src/component/state_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,16 @@
pub fn funding_parameters() -> &'static str {
"funding/parameters"
}

pub mod lqt {
pub mod v1 {
pub mod nullifier {
use penumbra_sdk_sct::Nullifier;

/// A nullifier set indexed by epoch, mapping each epoch to its corresponding `TransactionId`.
pub(crate) fn key(epoch_index: u64, nullifier: &Nullifier) -> String {
format!("funding/lqt/v1/nullifier/{epoch_index:020}/lookup/{nullifier}")
}
}
}
}
3 changes: 1 addition & 2 deletions crates/core/component/funding/src/component/view.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use async_trait::async_trait;

use crate::{component::state_key, params::FundingParameters};
use anyhow::Result;
use async_trait::async_trait;
use cnidarium::{StateRead, StateWrite};
use penumbra_sdk_proto::{StateReadProto, StateWriteProto};

Expand Down
1 change: 1 addition & 0 deletions crates/core/transaction/src/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ impl Transaction {
TransactionContext {
anchor: self.anchor,
effect_hash: self.effect_hash(),
transaction_id: self.id(),
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
}
}

Expand Down
4 changes: 3 additions & 1 deletion crates/core/txhash/src/context.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::EffectHash;
use crate::{EffectHash, TransactionId};
use penumbra_sdk_tct as tct;

/// Stateless verification context for a transaction.
Expand All @@ -10,4 +10,6 @@ pub struct TransactionContext {
pub anchor: tct::Root,
/// The transaction's effect hash.
pub effect_hash: EffectHash,
/// The transaction's id.
pub transaction_id: TransactionId,
}