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 7 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
4 changes: 2 additions & 2 deletions crates/core/app/src/app/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -690,7 +690,7 @@ pub trait StateReadExt: StateRead {
let distributions_params = self.get_distributions_params().await?;
let ibc_params = self.get_ibc_params().await?;
let fee_params = self.get_fee_params().await?;
let funding_params = self.get_funding_params().await?;
let funding_params = self.get_staking_funding_params().await?;
let governance_params = self.get_governance_params().await?;
let sct_params = self.get_sct_params().await?;
let shielded_pool_params = self.get_shielded_pool_params().await?;
Expand Down Expand Up @@ -812,7 +812,7 @@ pub trait StateWriteExt: StateWrite {
self.put_community_pool_params(community_pool_params);
self.put_distributions_params(distributions_params);
self.put_fee_params(fee_params);
self.put_funding_params(funding_params);
self.put_staking_funding_params(funding_params);
self.put_governance_params(governance_params);
self.put_ibc_params(ibc_params);
self.put_sct_params(sct_params);
Expand Down
3 changes: 2 additions & 1 deletion 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 All @@ -32,7 +33,7 @@ impl Component for Funding {
match app_state {
None => { /* no-op */ }
Some(genesis) => {
state.put_funding_params(genesis.funding_params.clone());
state.put_staking_funding_params(genesis.funding_params.clone());
}
};
}
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,47 @@
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 {
/// Gets the transaction id associated with the given nullifier from the JMT.
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
async fn get_txid_from_nullifier(&self, nullifier: Nullifier) -> Option<TransactionId> {
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
// 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::lqt_nullifier_lookup_for_txid(epoch_index, &nullifier);

let tx_id: Option<TransactionId> = self
.nonverifiable_get(&nullifier_key.as_bytes())
.await
.expect("infallible");
TalDerei marked this conversation as resolved.
Show resolved Hide resolved

tx_id
}
}

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

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

self.put(nullifier_key, tx_id);
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
}
}

impl<T: StateWrite + ?Sized> NullifierWrite for T {}
17 changes: 16 additions & 1 deletion crates/core/component/funding/src/component/state_key.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
pub fn funding_parameters() -> &'static str {
pub fn staking_funding_parameters() -> &'static str {
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
"funding/parameters"
}

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

pub(crate) fn lqt_nullifier_lookup_for_txid(
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
epoch_index: u64,
nullifier: &Nullifier,
) -> String {
format!("funding/lqt/v1/nullifier/{epoch_index:020}/lookup/{nullifier}")
}
}
}
}
11 changes: 5 additions & 6 deletions crates/core/component/funding/src/component/view.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,14 @@
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};

#[async_trait]
pub trait StateReadExt: StateRead {
/// Gets the funding module chain parameters from the JMT.
async fn get_funding_params(&self) -> Result<FundingParameters> {
self.get(state_key::funding_parameters())
async fn get_staking_funding_params(&self) -> Result<FundingParameters> {
self.get(state_key::staking_funding_parameters())
.await?
.ok_or_else(|| anyhow::anyhow!("Missing FundingParameters"))
}
Expand All @@ -20,8 +19,8 @@ impl<T: StateRead + ?Sized> StateReadExt for T {}
#[async_trait]
pub trait StateWriteExt: StateWrite + StateReadExt {
/// Set the Funding parameters in the JMT.
fn put_funding_params(&mut self, params: FundingParameters) {
self.put(state_key::funding_parameters().into(), params)
fn put_staking_funding_params(&mut self, params: FundingParameters) {
TalDerei marked this conversation as resolved.
Show resolved Hide resolved
self.put(state_key::staking_funding_parameters().into(), params)
}
}
impl<T: StateWrite + ?Sized> StateWriteExt for T {}
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,
}