diff --git a/crates/core/component/stake/src/penalty.rs b/crates/core/component/stake/src/penalty.rs index d7a7ff224b..2b568768e9 100644 --- a/crates/core/component/stake/src/penalty.rs +++ b/crates/core/component/stake/src/penalty.rs @@ -44,6 +44,7 @@ impl Penalty { Self(U128x128::ratio(bps_squared, 1_0000_0000).expect(&format!( "{bps_squared} bps^2 should be convertible to a U128x128" ))) + .one_minus_this() } fn one_minus_this(&self) -> Penalty { @@ -55,24 +56,22 @@ impl Penalty { /// Compound this `Penalty` with another `Penalty`. pub fn compound(&self, other: Penalty) -> Penalty { - // We want to compute q sth (1 - q) = (1-p1)(1-p2) - // q = 1 - (1-p1)(1-p2) - Self( - (self.one_minus_this().0 * other.one_minus_this().0) - .expect("compounding penalties will never overflow, both are <= 1"), - ) - .one_minus_this() + Self((self.0 * other.0).expect("compounding penalities will not overflow")) } /// Apply this `Penalty` to an `Amount` of unbonding tokens. - pub fn apply_to(&self, amount: Amount) -> Amount { - (U128x128::from(amount) * self.one_minus_this().0) - .expect("should not overflow, because penalty is <= 1") + pub fn apply_to_amount(&self, amount: Amount) -> Amount { + self.apply_to(amount) .round_down() .try_into() .expect("converting integral U128xU128 into Amount will succeed") } + /// Apply this `Penalty` to an some fracton. + pub fn apply_to(&self, amount: impl Into) -> U128x128 { + (amount.into() * self.0).expect("should not overflow, because penalty is <= 1") + } + /// Helper method to compute the effect of an UndelegateClaim on the /// transaction's value balance, used in planning and (transparent) proof /// verification. @@ -89,7 +88,7 @@ impl Penalty { asset_id: unbonding_id, } + Value { - amount: self.apply_to(unbonding_amount), + amount: self.apply_to_amount(unbonding_amount), asset_id: *STAKING_TOKEN_ASSET_ID, } } @@ -101,12 +100,6 @@ impl ToConstraintField for Penalty { } } -impl From for U128x128 { - fn from(value: Penalty) -> Self { - value.0 - } -} - impl From for [u8; 32] { fn from(value: Penalty) -> Self { value.0.into() @@ -146,22 +139,9 @@ impl AllocVar for PenaltyVar { } impl PenaltyVar { - fn one_minus_this(&self) -> Result { - // Calculate 1 - self outside the circuit - let ooc_result = { - let value = self.value().unwrap_or(Penalty::default()); - PenaltyVar::new_witness(self.cs(), || Ok(value.one_minus_this()))? - }; - // Check that 1 + (1 - self) is self - let one = PenaltyVar::new_constant(self.cs(), Penalty::from_percent(100))?; - self.inner - .enforce_equal(&one.inner.checked_add(&ooc_result.inner)?)?; - Ok(ooc_result) - } - pub fn apply_to(&self, amount: AmountVar) -> Result { U128x128Var::from_amount_var(amount)? - .checked_mul(&self.one_minus_this()?.inner)? + .checked_mul(&self.inner)? .round_down_to_amount() } diff --git a/crates/core/component/stake/src/rate.rs b/crates/core/component/stake/src/rate.rs index 8c3b13e565..c88ef51451 100644 --- a/crates/core/component/stake/src/rate.rs +++ b/crates/core/component/stake/src/rate.rs @@ -1,6 +1,5 @@ //! Staking reward and delegation token exchange rates. -use penumbra_num::fixpoint::U128x128; use penumbra_num::Amount; use penumbra_proto::core::component::stake::v1alpha1::CurrentValidatorRateResponse; use penumbra_proto::{penumbra::core::component::stake::v1alpha1 as pb, DomainType}; @@ -98,10 +97,11 @@ impl RateData { let mut slashed = self.clone(); // This will automatically produce a ratio which is multiplied by 1_0000_0000, and so // rounding down does what we want. - let penalty_times_exchange_rate: u64 = (U128x128::from(self.validator_exchange_rate) - * U128x128::from(penalty)) - .and_then(|x| x.round_down().try_into()) - .expect("multiplying will not overflow"); + let penalty_times_exchange_rate: u64 = penalty + .apply_to(self.validator_exchange_rate) + .round_down() + .try_into() + .expect("multiplying will not overflow"); // (1 - penalty) * exchange_rate slashed.validator_exchange_rate = self .validator_exchange_rate diff --git a/crates/crypto/proof-params/src/gen/delegator_vote_id.rs b/crates/crypto/proof-params/src/gen/delegator_vote_id.rs index 19b81c843c..5fd03d04d1 100644 --- a/crates/crypto/proof-params/src/gen/delegator_vote_id.rs +++ b/crates/crypto/proof-params/src/gen/delegator_vote_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk1hehwn62m7zwzycpdl8lf4g2x6eyut7y0av4ahnn3vmfdxz9qt85s3mu9u4"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1ph7cd0kp8r5fvnkmesn5f7hmuv5nex095d73l6spm0at83tqk5ss97wnft"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1hqv7y72vx5hgzfkzcajf5mg6plc3hvnhjqg8zaclymv4m9lfj99sn7w8wv"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1knhcr7yduj48sdrx4htfrth45ptqmjwtsyywwg5vl4pucrwm368qeqzj84"; diff --git a/crates/crypto/proof-params/src/gen/delegator_vote_pk.bin b/crates/crypto/proof-params/src/gen/delegator_vote_pk.bin index e60e634c7a..57d6ee4530 100644 --- a/crates/crypto/proof-params/src/gen/delegator_vote_pk.bin +++ b/crates/crypto/proof-params/src/gen/delegator_vote_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:e07ab33c37873ce5c9a8c3a4cbe65f1dd03ae6733df69913ebd15227280cb1c7 +oid sha256:151efa4f4441a7cd008f77e91e461ae70fed5ea5f8d89a5193709ae2154bd570 size 21943632 diff --git a/crates/crypto/proof-params/src/gen/delegator_vote_vk.param b/crates/crypto/proof-params/src/gen/delegator_vote_vk.param index 2a5a115774..7d2ccfc8be 100644 Binary files a/crates/crypto/proof-params/src/gen/delegator_vote_vk.param and b/crates/crypto/proof-params/src/gen/delegator_vote_vk.param differ diff --git a/crates/crypto/proof-params/src/gen/nullifier_derivation_id.rs b/crates/crypto/proof-params/src/gen/nullifier_derivation_id.rs index 95e54e390d..f584ec3eed 100644 --- a/crates/crypto/proof-params/src/gen/nullifier_derivation_id.rs +++ b/crates/crypto/proof-params/src/gen/nullifier_derivation_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk1rhgr5tunmrkz0wntj42lezj0am93w9tarm00vvttln05mnw597tsj2hka9"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1ynkrptkcd4jvqpn9zz0u7te4cmkjjdmammpf906yfyswhfh0c28qarttna"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1706hzsn4sn3ewwhnavgyql7pa289qwkze3eq8533wwdcqfzh5lrsz79klh"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1us3xkxnj8eks0mkk72z5h42mxhs4du5knm3m3llcghv635pn0qequt4yc2"; diff --git a/crates/crypto/proof-params/src/gen/nullifier_derivation_pk.bin b/crates/crypto/proof-params/src/gen/nullifier_derivation_pk.bin index 4464660923..912eafbe65 100644 --- a/crates/crypto/proof-params/src/gen/nullifier_derivation_pk.bin +++ b/crates/crypto/proof-params/src/gen/nullifier_derivation_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:b38dcea9deafaae849a540ed0a13b426b25315334e1887915b87b37e0ed448ce +oid sha256:38d3e29801419c7c4b29a96af9868bb35ef82b520ddafc6841e9b0d2b477b1aa size 232368 diff --git a/crates/crypto/proof-params/src/gen/nullifier_derivation_vk.param b/crates/crypto/proof-params/src/gen/nullifier_derivation_vk.param index d1410a9cea..648f32a0ba 100644 Binary files a/crates/crypto/proof-params/src/gen/nullifier_derivation_vk.param and b/crates/crypto/proof-params/src/gen/nullifier_derivation_vk.param differ diff --git a/crates/crypto/proof-params/src/gen/output_id.rs b/crates/crypto/proof-params/src/gen/output_id.rs index 9ad2070ec4..e84d2c742f 100644 --- a/crates/crypto/proof-params/src/gen/output_id.rs +++ b/crates/crypto/proof-params/src/gen/output_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk1v5d36h5lgtvw3u3r5t5v5y70n9wlqydyr6cts8cwal47s5p4nxgqfg8kqk"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1j7uwrfeqcxz5jyeh2qykrkfra8wqn8qq9qknvtm3s5dh7rxq9vkq3d460q"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1cjr04fvt8n59fzwdlmqrs9e9v7j8syfenvjax2krqjjr3ky0jlfqxalshd"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk15hyzxz5zkc5zszg3n0g0247jp3h87w2dgu8zhe5k89wqesy7hxfqntspmu"; diff --git a/crates/crypto/proof-params/src/gen/output_pk.bin b/crates/crypto/proof-params/src/gen/output_pk.bin index 7016cb228c..cbf80d7732 100644 --- a/crates/crypto/proof-params/src/gen/output_pk.bin +++ b/crates/crypto/proof-params/src/gen/output_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:499f2b8e08cef527ddd9ebd54ca8aef45003159327051b0c98deef3aecfe7dcc +oid sha256:806f7d080e9b570b6d1cc8e8d72300c58e8c9c4daf02b0799d27869ef5202f64 size 7257360 diff --git a/crates/crypto/proof-params/src/gen/output_vk.param b/crates/crypto/proof-params/src/gen/output_vk.param index 7bc7ceeabe..5cf507f2a6 100644 Binary files a/crates/crypto/proof-params/src/gen/output_vk.param and b/crates/crypto/proof-params/src/gen/output_vk.param differ diff --git a/crates/crypto/proof-params/src/gen/spend_id.rs b/crates/crypto/proof-params/src/gen/spend_id.rs index ed2bcdee01..f8132e8415 100644 --- a/crates/crypto/proof-params/src/gen/spend_id.rs +++ b/crates/crypto/proof-params/src/gen/spend_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk10atmn9a9t8ntnn2t7hn9lrzkj06wpeusytcsdt8jycun4ype52fstf0fdj"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk15t67ksyu3gfcwe8zzthty03hxy8zagp97zhet6jlk6tq2cgd7yjs0a9e05"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1fcytclqvsqmleer6w87cnyvfw9gvksydren89r4hejhkmq8njl8qanww5n"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1xtreus06n3ewt2q3wt3jy79umjpytr7c9z9pfggahhzdl848299qxajy7v"; diff --git a/crates/crypto/proof-params/src/gen/spend_pk.bin b/crates/crypto/proof-params/src/gen/spend_pk.bin index 0cc5e86455..558c779f3f 100644 --- a/crates/crypto/proof-params/src/gen/spend_pk.bin +++ b/crates/crypto/proof-params/src/gen/spend_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:d45b71186464810a879c70d84f219aa9d5c74623fc1d14a78ebaf9e603ced2a0 +oid sha256:89979fd45f4cebeaa6ad7c5cb1134401234d3a167e4eeafd61a3beb959727e62 size 21187632 diff --git a/crates/crypto/proof-params/src/gen/spend_vk.param b/crates/crypto/proof-params/src/gen/spend_vk.param index a8b3984f8e..8f193906ec 100644 Binary files a/crates/crypto/proof-params/src/gen/spend_vk.param and b/crates/crypto/proof-params/src/gen/spend_vk.param differ diff --git a/crates/crypto/proof-params/src/gen/swap_id.rs b/crates/crypto/proof-params/src/gen/swap_id.rs index 8e898e9135..3b65a2d65a 100644 --- a/crates/crypto/proof-params/src/gen/swap_id.rs +++ b/crates/crypto/proof-params/src/gen/swap_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk17qn3cw8kmp2xjlk9uhdtdlckrngzgj6203upha4ft0k84u5yunrqn0mu3j"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1e49hj5sd2dc5jntpu3f2wxxuwtmfalntltyak3wlu5qs3yvp4wksz84pzy"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1u5xk2s2uxnz7370mt5f84yvcc0qdz42v6lsdjy3w6vyv6gaympms22kn8r"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1qsujtjs2pgumus0sx5unmygv0uq78t8x2eht4ry89qempx8wh4gs4gaped"; diff --git a/crates/crypto/proof-params/src/gen/swap_pk.bin b/crates/crypto/proof-params/src/gen/swap_pk.bin index 6a7fc6c336..8417a55694 100644 --- a/crates/crypto/proof-params/src/gen/swap_pk.bin +++ b/crates/crypto/proof-params/src/gen/swap_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:bd6d63c14cc968c838025e2d6514ee5666262f86124eccdc7ec17222c779a337 +oid sha256:071ac75dfbb01be415d3915f8fc003d99d54763826bd4a693c0c7a359c910543 size 14019984 diff --git a/crates/crypto/proof-params/src/gen/swap_vk.param b/crates/crypto/proof-params/src/gen/swap_vk.param index 1c8145bfe1..0386e2365f 100644 Binary files a/crates/crypto/proof-params/src/gen/swap_vk.param and b/crates/crypto/proof-params/src/gen/swap_vk.param differ diff --git a/crates/crypto/proof-params/src/gen/swapclaim_id.rs b/crates/crypto/proof-params/src/gen/swapclaim_id.rs index 3d25b56276..473e18d654 100644 --- a/crates/crypto/proof-params/src/gen/swapclaim_id.rs +++ b/crates/crypto/proof-params/src/gen/swapclaim_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk1h6k8m496se0fudkvcuvk0yh37u0h2n3kztqagqxfp0r82d4l2alse72l59"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1r3ds2sf5365s6yh6e50degnh0tudx78fd3r9l3u4gq8ncctm82js48984w"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1jxrg7qd577py094z6430e5y8864ya5dwevh879aj6qk2qq3r7exq49ftnq"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1rg87uv9a6qphylmk6n66llaj954zq0jpwkx5cw5sfwpgaw0ym4mqkrn2ct"; diff --git a/crates/crypto/proof-params/src/gen/swapclaim_pk.bin b/crates/crypto/proof-params/src/gen/swapclaim_pk.bin index 3f6c5caa72..923efc5e77 100644 --- a/crates/crypto/proof-params/src/gen/swapclaim_pk.bin +++ b/crates/crypto/proof-params/src/gen/swapclaim_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:2e208e89445ac39f5d71c3ea30feb6938e8fd587ad426fecc8d9ba231ab72ca0 +oid sha256:79ef9a0cfa4a09670641f43b6ec543d9c620539ca7e8c1d8544ec4346ba9190d size 22569072 diff --git a/crates/crypto/proof-params/src/gen/swapclaim_vk.param b/crates/crypto/proof-params/src/gen/swapclaim_vk.param index 72d2c994a0..210f4a8b5c 100644 Binary files a/crates/crypto/proof-params/src/gen/swapclaim_vk.param and b/crates/crypto/proof-params/src/gen/swapclaim_vk.param differ diff --git a/crates/crypto/proof-params/src/gen/undelegateclaim_id.rs b/crates/crypto/proof-params/src/gen/undelegateclaim_id.rs index 02c233b10d..ce7b2bd5ce 100644 --- a/crates/crypto/proof-params/src/gen/undelegateclaim_id.rs +++ b/crates/crypto/proof-params/src/gen/undelegateclaim_id.rs @@ -1,3 +1,3 @@ -pub const PROVING_KEY_ID: &'static str = "groth16pk1yyep0mkzclzhfl7shner7hqmt4xlafufc9qqrhffzcngnxhsr7jq4pvjx8"; -pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1wjdcyp8psfar83nq9wepavznh2yw596aa8emd50z9rwpecyeksusq7acdt"; +pub const PROVING_KEY_ID: &'static str = "groth16pk1kz7ck7fsulndvp23zf6knnt7gvkh3pycryj9q95k4vlc4fmv2ptqq4pw65"; +pub const VERIFICATION_KEY_ID: &'static str = "groth16vk1edaemnjzh22hmkms4mqw9mhh9kt79qjvdgtr5gurn4k8yc7860xqx5ecxk"; diff --git a/crates/crypto/proof-params/src/gen/undelegateclaim_pk.bin b/crates/crypto/proof-params/src/gen/undelegateclaim_pk.bin index 09c081974b..dcfa8f9e69 100644 --- a/crates/crypto/proof-params/src/gen/undelegateclaim_pk.bin +++ b/crates/crypto/proof-params/src/gen/undelegateclaim_pk.bin @@ -1,3 +1,3 @@ version https://git-lfs.github.com/spec/v1 -oid sha256:83e03ac885eb470e051a416ed78105a6f382194b726eefaafffd43e69e49d00d -size 8543280 +oid sha256:2e373a86e5bd24252b195e6fc4f283facac605ea0312dc2b013ee7de90a2f22c +size 7926960 diff --git a/crates/crypto/proof-params/src/gen/undelegateclaim_vk.param b/crates/crypto/proof-params/src/gen/undelegateclaim_vk.param index 9f35894103..306896bc7a 100644 Binary files a/crates/crypto/proof-params/src/gen/undelegateclaim_vk.param and b/crates/crypto/proof-params/src/gen/undelegateclaim_vk.param differ