Skip to content

Commit

Permalink
refactor: move note to shielded pool, nullifier to penumbra-sct
Browse files Browse the repository at this point in the history
Minor API change: Move `Allocation::note` to `Note::from_allocation`
  • Loading branch information
redshiftzero committed Jul 6, 2023
1 parent 853deec commit 116af9b
Show file tree
Hide file tree
Showing 82 changed files with 306 additions and 224 deletions.
24 changes: 24 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/bin/pcli/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ penumbra-view = { path = "../../view" }

# Penumbra dependencies
decaf377 = { version = "0.4" }
decaf377-rdsa = { version = "0.6" }
tendermint = { version = "0.32.0", features = ["rust-crypto"] }
jmt = "0.6"

Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pcli/src/command/query/shielded_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use anyhow::Result;
use colored_json::prelude::*;
use penumbra_chain::{NoteSource, SpendInfo};
use penumbra_compact_block::CompactBlock;
use penumbra_crypto::Nullifier;
use penumbra_proto::DomainType;
use penumbra_sct::Nullifier;
use penumbra_tct::StateCommitment;

#[derive(Debug, clap::Subcommand)]
Expand Down
2 changes: 1 addition & 1 deletion crates/bin/pcli/src/command/view/tx.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use anyhow::{Context, Result};
use comfy_table::{presets, Table};
use penumbra_asset::{asset::Cache, Value};
use penumbra_crypto::{Note, NoteView};
use penumbra_dex::{
lp::position::Position,
swap::SwapPlaintext,
Expand All @@ -11,6 +10,7 @@ use penumbra_dex::{
};
use penumbra_keys::{keys::IncomingViewingKey, Address};
use penumbra_proto::{client::v1alpha1::GetTxRequest, DomainType};
use penumbra_shielded_pool::{Note, NoteView};
use penumbra_transaction::{
view::action_view::{OutputView, SpendView},
Transaction,
Expand Down
13 changes: 6 additions & 7 deletions crates/bin/pcli/tests/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
//! proving/verification key.

use ark_ff::UniformRand;
use decaf377::Fr;
use decaf377::{Fq, Fr};
use decaf377_rdsa::{SigningKey, SpendAuth, VerificationKey};
use penumbra_asset::{asset, Balance, Value};
use penumbra_crypto::{
rdsa::{self, SpendAuth, VerificationKey},
Fq, Note, Nullifier,
};
use penumbra_dex::{
swap::proof::SwapProof, swap::SwapPlaintext, swap_claim::proof::SwapClaimProof,
BatchSwapOutputData, TradingPair,
Expand All @@ -24,6 +21,8 @@ use penumbra_proof_params::{
SWAP_PROOF_PROVING_KEY, SWAP_PROOF_VERIFICATION_KEY, UNDELEGATECLAIM_PROOF_PROVING_KEY,
UNDELEGATECLAIM_PROOF_VERIFICATION_KEY,
};
use penumbra_sct::Nullifier;
use penumbra_shielded_pool::Note;
use penumbra_shielded_pool::{NullifierDerivationProof, OutputProof, SpendProof};
use penumbra_stake::{IdentityKey, Penalty, UnbondingToken, UndelegateClaimProof};
use penumbra_tct as tct;
Expand Down Expand Up @@ -254,7 +253,7 @@ fn swap_claim_parameters_vs_current_swap_claim_circuit() {
let anchor = sct.root();
let state_commitment_proof = sct.witness(swap_commitment).unwrap();
let position = state_commitment_proof.position();
let nullifier: penumbra_crypto::Nullifier = Nullifier::derive(&nk, position, &swap_commitment);
let nullifier = Nullifier::derive(&nk, position, &swap_commitment);
let epoch_duration = 20;
let height = epoch_duration * position.epoch() + position.block();

Expand Down Expand Up @@ -405,7 +404,7 @@ fn undelegate_claim_parameters_vs_current_undelegate_claim_circuit() {

let mut rng = OsRng;

let sk = rdsa::SigningKey::new_from_field(Fr::from(1u8));
let sk = SigningKey::new_from_field(Fr::from(1u8));
let balance_blinding = Fr::from(1u8);
let value1_amount = 1u64;
let penalty_amount = 1u64;
Expand Down
3 changes: 1 addition & 2 deletions crates/core/app/src/action_handler/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,8 @@ mod tests {
use anyhow::Result;
use penumbra_asset::{Value, STAKING_TOKEN_ASSET_ID};
use penumbra_chain::test_keys;
use penumbra_crypto::Note;
use penumbra_fee::Fee;
use penumbra_shielded_pool::{OutputPlan, SpendPlan};
use penumbra_shielded_pool::{Note, OutputPlan, SpendPlan};
use penumbra_tct as tct;
use penumbra_transaction::{plan::TransactionPlan, WitnessData};
use rand_core::OsRng;
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/governance/state_key.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use penumbra_crypto::Nullifier;
use penumbra_sct::Nullifier;
use penumbra_stake::IdentityKey;

pub fn next_proposal_id() -> &'static str {
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/governance/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@ use penumbra_chain::{
component::{StateReadExt as _, StateWriteExt as _},
params::ChainParameters,
};
use penumbra_crypto::Nullifier;
use penumbra_num::Amount;
use penumbra_proto::{StateReadProto, StateWriteProto};
use penumbra_sct::Nullifier;
use penumbra_shielded_pool::component::{StateReadExt as _, SupplyRead};
use penumbra_stake::{DelegationToken, GovernanceKey, IdentityKey};
use penumbra_storage::{StateRead, StateWrite};
Expand Down
2 changes: 1 addition & 1 deletion crates/core/app/src/mock_client.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
use std::collections::BTreeMap;

use penumbra_compact_block::{component::StateReadExt as _, CompactBlock, StatePayload};
use penumbra_crypto::{note, Note};
use penumbra_dex::swap::SwapPlaintext;
use penumbra_keys::FullViewingKey;
use penumbra_sct::component::StateReadExt as _;
use penumbra_shielded_pool::{note, Note};
use penumbra_storage::StateRead;
use penumbra_tct as tct;

Expand Down
23 changes: 0 additions & 23 deletions crates/core/component/chain/src/genesis/allocation.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
use penumbra_asset::{asset, Value};
use penumbra_crypto::{Note, Rseed};
use penumbra_keys::Address;
use penumbra_num::Amount;
use penumbra_proto::{core::chain::v1alpha1 as pb, DomainType, TypeUrl};
Expand Down Expand Up @@ -57,27 +55,6 @@ impl std::fmt::Debug for Allocation {
}
}

impl Allocation {
/// Obtain a note corresponding to this allocation.
///
/// Note: to ensure determinism, this uses a zero rseed when
/// creating the note.
pub fn note(&self) -> Result<Note, anyhow::Error> {
Note::from_parts(
self.address,
Value {
amount: self.amount,
asset_id: asset::REGISTRY
.parse_denom(&self.denom)
.ok_or_else(|| anyhow::anyhow!("invalid denomination"))?
.id(),
},
Rseed([0u8; 32]),
)
.map_err(Into::into)
}
}

impl TypeUrl for Allocation {
// TODO: verify!
const TYPE_URL: &'static str = "/penumbra.core.chain.v1alpha1.genesis_app_state.Allocation";
Expand Down
1 change: 1 addition & 0 deletions crates/core/component/compact-block/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ penumbra-component = { path = "../component", optional = true }
penumbra-chain = { path = "../chain", default-features = false }
penumbra-shielded-pool = { path = "../shielded-pool", default-features = false }
penumbra-dex = { path = "../dex", default-features = false }
penumbra-sct = { path = "../sct", default-features = false }

# Penumbra dependencies
decaf377-rdsa = { version = "0.6" }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/compact-block/src/compact_block.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ use std::{collections::BTreeMap, convert::TryFrom};

use anyhow::Result;
use penumbra_chain::params::{ChainParameters, FmdParameters};
use penumbra_crypto::Nullifier;
use penumbra_dex::{BatchSwapOutputData, TradingPair};
use penumbra_proto::{
client::v1alpha1::CompactBlockRangeResponse, core::chain::v1alpha1 as pb, DomainType, TypeUrl,
};
use penumbra_sct::Nullifier;
use penumbra_tct::builder::{block, epoch};
use serde::{Deserialize, Serialize};

Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/compact-block/src/state_payload.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use std::convert::TryFrom;

use anyhow::Result;
use penumbra_crypto::{note, NotePayload};
use penumbra_dex::swap::SwapPayload;
use penumbra_proto::core::chain::v1alpha1::{self as pb};
use penumbra_shielded_pool::{note, NotePayload};

use serde::{Deserialize, Serialize};

Expand Down
2 changes: 2 additions & 0 deletions crates/core/component/dex/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ penumbra-proof-params = { path = "../../../crypto/proof-params" }
penumbra-asset = { path = "../../../core/asset", default-features = false }
penumbra-num = { path = "../../../core/num", default-features = false }
penumbra-keys = { path = "../../../core/keys", default-features = false }
decaf377-ka = { path = "../../../crypto/decaf377-ka/" }
decaf377-fmd = { path = "../../../crypto/decaf377-fmd/" }

# Penumbra dependencies
poseidon377 = { version = "0.6", features = ["r1cs"] }
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/dex/src/swap/ciphertext.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use anyhow::Result;

use penumbra_crypto::{note, PayloadKey};
use penumbra_keys::keys::OutgoingViewingKey;
use penumbra_shielded_pool::{note, PayloadKey};

use super::{SwapPlaintext, SWAP_CIPHERTEXT_BYTES, SWAP_LEN_BYTES};

Expand Down
4 changes: 3 additions & 1 deletion crates/core/component/dex/src/swap/plaintext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,12 @@ use penumbra_tct::StateCommitment;
use poseidon377::{hash_1, hash_4, hash_7};
use rand_core::{CryptoRng, RngCore};

use decaf377_ka as ka;
use penumbra_asset::{asset, Value, ValueVar};
use penumbra_crypto::{ka, note::StateCommitmentVar, Note, PayloadKey, Rseed};
use penumbra_keys::{keys::OutgoingViewingKey, Address, AddressVar};
use penumbra_num::{Amount, AmountVar};
use penumbra_shielded_pool::{Note, PayloadKey, Rseed};
use penumbra_tct::r1cs::StateCommitmentVar;

use crate::{BatchSwapOutputData, TradingPair, TradingPairVar};

Expand Down
6 changes: 5 additions & 1 deletion crates/core/component/dex/src/swap/proof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,18 +7,22 @@ use ark_relations::r1cs::{ConstraintSynthesizer, ConstraintSystemRef};
use ark_serialize::{CanonicalDeserialize, CanonicalSerialize};
use ark_snark::SNARK;
use decaf377::{Bls12_377, FieldExt};
use decaf377::{Fq, Fr};
use decaf377_fmd as fmd;
use decaf377_ka as ka;
use penumbra_fee::Fee;
use penumbra_proto::{core::crypto::v1alpha1 as pb, DomainType, TypeUrl};
use penumbra_tct as tct;
use penumbra_tct::r1cs::StateCommitmentVar;
use rand_core::OsRng;

use penumbra_asset::{
asset,
balance::{self, commitment::BalanceCommitmentVar, BalanceVar},
Value,
};
use penumbra_crypto::{fmd, ka, note::StateCommitmentVar, Fq, Fr, Rseed};
use penumbra_keys::{keys::Diversifier, Address};
use penumbra_shielded_pool::Rseed;

use crate::{
swap::{SwapPlaintext, SwapPlaintextVar},
Expand Down
2 changes: 1 addition & 1 deletion crates/core/component/dex/src/swap_claim/action.rs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
use anyhow::Context;
use penumbra_asset::Balance;
use penumbra_crypto::Nullifier;
use penumbra_fee::Fee;
use penumbra_proof_params::GROTH16_PROOF_LENGTH_BYTES;
use penumbra_proto::{core::dex::v1alpha1 as pb, DomainType, TypeUrl};
use penumbra_sct::Nullifier;
use penumbra_tct as tct;

use crate::BatchSwapOutputData;
Expand Down
3 changes: 2 additions & 1 deletion crates/core/component/dex/src/swap_claim/plan.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
use penumbra_asset::{Balance, Value};
use penumbra_crypto::{FieldExt, Fq, Nullifier};
use penumbra_crypto::{FieldExt, Fq};
use penumbra_keys::{
keys::{IncomingViewingKey, NullifierKey},
FullViewingKey,
};
use penumbra_proof_params::SWAPCLAIM_PROOF_PROVING_KEY;
use penumbra_proto::{core::dex::v1alpha1 as pb, DomainType, TypeUrl};
use penumbra_sct::Nullifier;
use penumbra_tct as tct;

use serde::{Deserialize, Serialize};
Expand Down
Loading

0 comments on commit 116af9b

Please sign in to comment.