Skip to content

Commit

Permalink
lqt: propagate lqt vote plan into the app crate
Browse files Browse the repository at this point in the history
  • Loading branch information
cronokirby committed Feb 7, 2025
1 parent 8de4666 commit 9c742ae
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 3 deletions.
1 change: 1 addition & 0 deletions crates/bin/pcli/src/terminal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,7 @@ fn pretty_print_transaction_plan(
ActionPlan::ActionDutchAuctionEnd(_) => None,
ActionPlan::ActionDutchAuctionWithdraw(_) => None,
ActionPlan::IbcAction(_) => todo!(),
ActionPlan::ActionLiquidityTournamentVote(_) => None,
}
}

Expand Down
1 change: 1 addition & 0 deletions crates/core/app/src/action_handler/actions/submit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ impl AppActionHandler for ProposalSubmit {
anyhow::bail!("invalid action in Community Pool spend proposal (not allowed to manipulate proposals from within proposals)")
}
ValidatorDefinition(_)
| ActionLiquidityTournamentVote(_)
| IbcAction(_)
| ValidatorVote(_)
| PositionOpen(_)
Expand Down
83 changes: 81 additions & 2 deletions crates/core/component/funding/src/liquidity_tournament/plan/mod.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
use anyhow::{anyhow, Context};
use decaf377::{Fq, Fr};
use decaf377_rdsa::{Signature, SpendAuth};
use penumbra_sdk_asset::asset::Denom;
use penumbra_sdk_keys::Address;
use penumbra_sdk_keys::{Address, FullViewingKey};
use penumbra_sdk_proof_params::DELEGATOR_VOTE_PROOF_PROVING_KEY;
use penumbra_sdk_proto::{core::component::funding::v1 as pb, DomainType};
use penumbra_sdk_sct::Nullifier;
use penumbra_sdk_shielded_pool::note::Note;
use penumbra_sdk_tct as tct;
use penumbra_sdk_tct::{self as tct};
use rand::{CryptoRng, RngCore};
use serde::{Deserialize, Serialize};
use std::convert::{From, TryFrom};

use super::{
proof::{
LiquidityTournamentVoteProof, LiquidityTournamentVoteProofPrivate,
LiquidityTournamentVoteProofPublic,
},
ActionLiquidityTournamentVote, LiquidityTournamentVoteBody,
};

/// A plan to vote in the liquidity tournament.
///
/// This structure represents the planned vote before it is actually executed,
Expand Down Expand Up @@ -59,6 +70,74 @@ impl ActionLiquidityTournamentVotePlan {
proof_blinding_s: Fq::rand(rng),
}
}

pub fn to_body(&self, fvk: &FullViewingKey) -> LiquidityTournamentVoteBody {
let commitment = self.staked_note.commit();

let nk = fvk.nullifier_key();
let nullifier = Nullifier::derive(nk, self.staked_note_position, &commitment);
let ak = fvk.spend_verification_key();
let rk = ak.randomize(&self.randomizer);
let value = self.staked_note.value();

LiquidityTournamentVoteBody {
incentivized: self.incentivized.clone(),
rewards_recipient: self.rewards_recipient.clone(),
start_position: self.start_position,
value,
nullifier,
rk,
}
}

/// Convert this plan into an action.
///
/// * `fvk`: [`FullViewingKey`], in order to derive keys.
/// * `auth_sig`: [`Signature<SpendAuth>`], as the signature for the transaction.
/// * `auth_path`: [`tct::Proof`], witnessing the inclusion of the spent note.
pub fn to_action(
self,
fvk: &FullViewingKey,
auth_sig: Signature<SpendAuth>,
auth_path: tct::Proof,
) -> ActionLiquidityTournamentVote {
let commitment = self.staked_note.commit();

let nk = fvk.nullifier_key();
let nullifier = Nullifier::derive(nk, self.staked_note_position, &commitment);
let ak = fvk.spend_verification_key();
let rk = ak.randomize(&self.randomizer);
let value = self.staked_note.value();

let public = LiquidityTournamentVoteProofPublic {
anchor: auth_path.root(),
value,
nullifier,
rk,
start_position: self.start_position,
};
let private = LiquidityTournamentVoteProofPrivate {
state_commitment_proof: auth_path,
note: self.staked_note.clone(),
spend_auth_randomizer: self.randomizer,
ak: *ak,
nk: *nk,
};
let proof = LiquidityTournamentVoteProof::prove(
self.proof_blinding_r,
self.proof_blinding_s,
&DELEGATOR_VOTE_PROOF_PROVING_KEY,
public,
private,
)
.expect("can generate ZK LQT voting proof");

ActionLiquidityTournamentVote {
body: self.to_body(fvk),
auth_sig,
proof,
}
}
}

impl DomainType for ActionLiquidityTournamentVotePlan {
Expand Down
1 change: 1 addition & 0 deletions crates/core/transaction/src/gas.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,7 @@ impl GasCost for ActionPlan {
ActionPlan::CommunityPoolOutput(d) => d.gas_cost(),
ActionPlan::CommunityPoolDeposit(dd) => dd.gas_cost(),
ActionPlan::Ics20Withdrawal(w) => w.gas_cost(),
ActionPlan::ActionLiquidityTournamentVote(_) => liquidity_tournament_vote_gas_cost(),
}
}
}
Expand Down
28 changes: 27 additions & 1 deletion crates/core/transaction/src/plan/action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use penumbra_sdk_auction::auction::dutch::actions::ActionDutchAuctionEnd;
use penumbra_sdk_auction::auction::dutch::actions::ActionDutchAuctionSchedule;
use penumbra_sdk_auction::auction::dutch::actions::ActionDutchAuctionWithdrawPlan;
use penumbra_sdk_community_pool::{CommunityPoolDeposit, CommunityPoolOutput, CommunityPoolSpend};
use penumbra_sdk_funding::liquidity_tournament::ActionLiquidityTournamentVotePlan;
use penumbra_sdk_txhash::{EffectHash, EffectingData};

use penumbra_sdk_dex::{
Expand Down Expand Up @@ -82,6 +83,8 @@ pub enum ActionPlan {
ActionDutchAuctionSchedule(ActionDutchAuctionSchedule),
ActionDutchAuctionEnd(ActionDutchAuctionEnd),
ActionDutchAuctionWithdraw(ActionDutchAuctionWithdrawPlan),

ActionLiquidityTournamentVote(ActionLiquidityTournamentVotePlan),
}

impl ActionPlan {
Expand Down Expand Up @@ -165,6 +168,18 @@ impl ActionPlan {
ActionDutchAuctionWithdraw(plan) => {
Action::ActionDutchAuctionWithdraw(plan.to_action())
}
ActionLiquidityTournamentVote(plan) => {
let note_commitment = plan.staked_note.commit();
let auth_path = witness_data
.state_commitment_proofs
.get(&note_commitment)
.context(format!("could not get proof for {note_commitment:?}"))?;
Action::ActionLiquidityTournamentVote(plan.to_action(
fvk,
[0; 64].into(),
auth_path.clone(),
))
}
})
}

Expand Down Expand Up @@ -195,6 +210,7 @@ impl ActionPlan {
ActionPlan::ActionDutchAuctionSchedule(_) => 53,
ActionPlan::ActionDutchAuctionEnd(_) => 54,
ActionPlan::ActionDutchAuctionWithdraw(_) => 55,
ActionPlan::ActionLiquidityTournamentVote(_) => 70,
}
}

Expand Down Expand Up @@ -225,7 +241,10 @@ impl ActionPlan {
ActionDutchAuctionWithdraw(action) => action.balance(),

// None of these contribute to transaction balance:
IbcAction(_) | ValidatorDefinition(_) | ValidatorVote(_) => Balance::default(),
IbcAction(_)
| ValidatorDefinition(_)
| ValidatorVote(_)
| ActionLiquidityTournamentVote(_) => Balance::default(),
}
}

Expand Down Expand Up @@ -257,6 +276,7 @@ impl ActionPlan {
ActionDutchAuctionSchedule(_) => Fr::zero(),
ActionDutchAuctionEnd(_) => Fr::zero(),
ActionDutchAuctionWithdraw(_) => Fr::zero(),
ActionLiquidityTournamentVote(_) => Fr::zero(),
}
}

Expand Down Expand Up @@ -289,6 +309,7 @@ impl ActionPlan {
ActionDutchAuctionSchedule(plan) => plan.effect_hash(),
ActionDutchAuctionEnd(plan) => plan.effect_hash(),
ActionDutchAuctionWithdraw(plan) => plan.to_action().effect_hash(),
ActionLiquidityTournamentVote(plan) => plan.to_body(fvk).effect_hash(),
}
}
}
Expand Down Expand Up @@ -532,6 +553,11 @@ impl From<ActionPlan> for pb_t::ActionPlan {
inner.into(),
)),
},
ActionPlan::ActionLiquidityTournamentVote(inner) => pb_t::ActionPlan {
action: Some(
pb_t::action_plan::Action::ActionLiquidityTournamentVotePlan(inner.into()),
),
},
}
}
}
Expand Down
1 change: 1 addition & 0 deletions crates/core/transaction/src/view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -710,6 +710,7 @@ mod test {
ActionPlan::ActionDutchAuctionEnd(_) => None,
ActionPlan::ActionDutchAuctionWithdraw(_) => None,
ActionPlan::IbcAction(_) => todo!(),
ActionPlan::ActionLiquidityTournamentVote(_) => todo!(),
}
}

Expand Down

0 comments on commit 9c742ae

Please sign in to comment.