-
Notifications
You must be signed in to change notification settings - Fork 310
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement stateless handler for LQT voting
- Loading branch information
1 parent
e42c010
commit 98dcc0f
Showing
3 changed files
with
79 additions
and
0 deletions.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
crates/core/component/funding/src/action_handler/liquidity_tournament/mod.rs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
use anyhow::Context as _; | ||
use async_trait::async_trait; | ||
use cnidarium::StateWrite; | ||
use penumbra_sdk_asset::asset::Denom; | ||
use penumbra_sdk_proof_params::DELEGATOR_VOTE_PROOF_VERIFICATION_KEY; | ||
use penumbra_sdk_txhash::TransactionContext; | ||
|
||
use crate::liquidity_tournament::{ | ||
proof::LiquidityTournamentVoteProofPublic, ActionLiquidityTournamentVote, | ||
LiquidityTournamentVoteBody, LIQUIDITY_TOURNAMENT_VOTE_DENOM_MAX_BYTES, | ||
}; | ||
use cnidarium_component::ActionHandler; | ||
|
||
fn is_valid_denom(denom: &Denom) -> anyhow::Result<()> { | ||
anyhow::ensure!( | ||
denom.denom.len() <= LIQUIDITY_TOURNAMENT_VOTE_DENOM_MAX_BYTES, | ||
"denom {} is not <= (MAX OF) {}", | ||
&denom.denom, | ||
LIQUIDITY_TOURNAMENT_VOTE_DENOM_MAX_BYTES | ||
); | ||
anyhow::ensure!( | ||
denom.denom.starts_with("transfer/"), | ||
"denom {} is not an IBC transfer asset", | ||
&denom.denom | ||
); | ||
Ok(()) | ||
} | ||
|
||
#[async_trait] | ||
impl ActionHandler for ActionLiquidityTournamentVote { | ||
type CheckStatelessContext = TransactionContext; | ||
|
||
async fn check_stateless(&self, context: TransactionContext) -> anyhow::Result<()> { | ||
let Self { | ||
auth_sig, | ||
proof, | ||
body: | ||
LiquidityTournamentVoteBody { | ||
start_position, | ||
nullifier, | ||
rk, | ||
value, | ||
incentivized, | ||
.. | ||
}, | ||
} = self; | ||
// 1. Is it ok to vote on this denom? | ||
is_valid_denom(incentivized)?; | ||
// 2. Check spend auth signature using provided spend auth key. | ||
rk.verify(context.effect_hash.as_ref(), auth_sig) | ||
.with_context(|| { | ||
format!( | ||
"{} auth signature failed to verify", | ||
std::any::type_name::<Self>() | ||
) | ||
})?; | ||
|
||
// 3. Verify the proof against the provided anchor and start position: | ||
let public = LiquidityTournamentVoteProofPublic { | ||
anchor: context.anchor, | ||
value: *value, | ||
nullifier: *nullifier, | ||
rk: *rk, | ||
start_position: *start_position, | ||
}; | ||
proof | ||
.verify(&DELEGATOR_VOTE_PROOF_VERIFICATION_KEY, public) | ||
.context("a LiquidityTournamentVote proof did not verify")?; | ||
|
||
Ok(()) | ||
} | ||
|
||
async fn check_and_execute<S: StateWrite>(&self, _state: S) -> anyhow::Result<()> { | ||
todo!() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
pub mod liquidity_tournament; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters