Skip to content

Commit

Permalink
format files
Browse files Browse the repository at this point in the history
  • Loading branch information
abenso committed Jan 10, 2025
1 parent c7c05d6 commit 0242da6
Show file tree
Hide file tree
Showing 26 changed files with 489 additions and 296 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ default:
endif

test_all:
make clean
make
make zemu_install
make zemu_test
Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ extern crate no_std_compat as std;

use arrayref as _;
use educe as _;
use poseidon377 as _;
use ethnum as _;
use poseidon377 as _;

pub(crate) mod address;
mod bolos;
Expand Down
6 changes: 3 additions & 3 deletions app/rust/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,16 @@ pub mod detection;
pub mod effect_hash;
mod error;
pub mod fee;
pub mod fixpoint;
pub mod id;
pub mod identity_key;
pub mod memo;
pub mod memo_plain_text;
mod note;
mod note_payload;
pub mod nullifier;
mod parameters;
pub mod penalty;
mod plans;
pub mod rseed;
pub mod swap_ciphertext;
Expand All @@ -45,9 +48,6 @@ pub mod swap_plaintext;
pub mod symmetric;
pub mod trading_pair;
pub mod value;
pub mod identity_key;
pub mod penalty;
pub mod fixpoint;

pub use bytes::BytesC;
pub use error::ParserError;
Expand Down
2 changes: 1 addition & 1 deletion app/rust/src/parser/amount.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
********************************************************************************/

use crate::constants::AMOUNT_LEN_BYTES;
use crate::parser::fixpoint::U128x128;
use crate::utils::protobuf::encode_varint;
use crate::ParserError;
use decaf377::{Fq, Fr};
use crate::parser::fixpoint::U128x128;

#[derive(Copy, Clone)]
#[cfg_attr(any(feature = "derive-debug", test), derive(Debug))]
Expand Down
6 changes: 3 additions & 3 deletions app/rust/src/parser/fee.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use crate::constants::{AMOUNT_LEN_BYTES, ID_LEN_BYTES};
use crate::parser::commitment::Commitment;
use crate::parser::id::Id;
use crate::parser::value::Sign;
use crate::parser::value::{Value, ValueC, Imbalance, Balance};
use crate::parser::value::{Balance, Imbalance, Value, ValueC};
use crate::ParserError;
use decaf377::Fq;
use decaf377::Fr;
Expand Down Expand Up @@ -32,7 +32,7 @@ impl TryFrom<FeeC> for Fee {
// If conversion fails, create a new Value with the amount and staking token asset ID
Ok(Fee(Value {
amount: value.0.amount.try_into()?,
asset_id: Id(Fq::from_le_bytes_mod_order(&STAKING_TOKEN_ASSET_ID_BYTES))
asset_id: Id(Fq::from_le_bytes_mod_order(&STAKING_TOKEN_ASSET_ID_BYTES)),
}))
}
}
Expand All @@ -49,7 +49,7 @@ impl Fee {

pub fn commit(&self, blinding: Fr) -> Result<Commitment, ParserError> {
let mut balance = Balance::new();
balance.add(Imbalance{
balance.add(Imbalance {
value: self.0.clone(),
sign: Sign::Required,
})?;
Expand Down
6 changes: 3 additions & 3 deletions app/rust/src/parser/fixpoint.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use ethnum::U256;
use crate::parser::ParserError;
use crate::parser::amount::Amount;
use crate::parser::ParserError;
use ethnum::U256;
use std::ops::Mul;

#[derive(Copy, Clone)]
Expand Down Expand Up @@ -126,4 +126,4 @@ impl Mul<U128x128> for U128x128 {
fn mul(self, rhs: U128x128) -> Self::Output {
self.checked_mul(&rhs)
}
}
}
3 changes: 0 additions & 3 deletions app/rust/src/parser/identity_key.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
use crate::parser::bytes::BytesC;
use decaf377_rdsa::{SpendAuth, VerificationKeyBytes};


pub struct IdentityKey(pub VerificationKeyBytes<SpendAuth>);

#[repr(C)]
Expand All @@ -10,5 +9,3 @@ pub struct IdentityKey(pub VerificationKeyBytes<SpendAuth>);
pub struct IdentityKeyC {
pub ik: BytesC,
}


29 changes: 17 additions & 12 deletions app/rust/src/parser/penalty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,16 @@
********************************************************************************/
use crate::parser::bytes::BytesC;
use crate::parser::{
fixpoint::U128x128,
ParserError,
amount::Amount,
value::{Balance, Imbalance, Sign},
fee::STAKING_TOKEN_ASSET_ID_BYTES,
fixpoint::U128x128,
id::Id,
value::Value,
fee::STAKING_TOKEN_ASSET_ID_BYTES,
value::{Balance, Imbalance, Sign},
ParserError,
};
use decaf377::Fq;


#[derive(Copy, Clone)]
pub struct Penalty(U128x128);

Expand All @@ -44,21 +43,25 @@ impl Penalty {
/// This method takes the `unbonding_id` rather than the `UnbondingToken` so
/// that it can be used in mock proof verification, where computation of the
/// unbonding token's asset ID happens outside of the circuit.
pub fn balance_for_claim(&self, unbonding_id: Id, unbonding_amount: Amount) -> Result<Balance, ParserError> {
pub fn balance_for_claim(
&self,
unbonding_id: Id,
unbonding_amount: Amount,
) -> Result<Balance, ParserError> {
// The undelegate claim action subtracts the unbonding amount and adds
// the unbonded amount from the transaction's value balance.
let mut balance = Balance::new();
balance.add(Imbalance{
value: Value{
balance.add(Imbalance {
value: Value {
amount: unbonding_amount,
asset_id: unbonding_id,
},
sign: Sign::Required,
})?;
balance.add(Imbalance{
value: Value{
balance.add(Imbalance {
value: Value {
amount: self.apply_to_amount(unbonding_amount),
asset_id: Id(Fq::from_le_bytes_mod_order(&STAKING_TOKEN_ASSET_ID_BYTES))
asset_id: Id(Fq::from_le_bytes_mod_order(&STAKING_TOKEN_ASSET_ID_BYTES)),
},
sign: Sign::Provided,
})?;
Expand All @@ -77,7 +80,9 @@ impl<'a> TryFrom<&'a [u8]> for Penalty {
type Error = ParserError;

fn try_from(value: &'a [u8]) -> Result<Self, Self::Error> {
U128x128::try_from(value).map(Self).map_err(|_| ParserError::InvalidLength)
U128x128::try_from(value)
.map(Self)
.map_err(|_| ParserError::InvalidLength)
}
}

Expand Down
18 changes: 8 additions & 10 deletions app/rust/src/parser/plans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,17 @@ use crate::parser::{
};

use crate::constants::EFFECT_HASH_LEN;
use crate::ffi::c_api::c_fvk_bytes;
use crate::parser::bytes::BytesC;
use crate::parser::effect_hash::EffectHash;
use crate::parser::parameters::ParametersHash;
use crate::ffi::c_api::c_fvk_bytes;
use crate::ParserError;

pub mod delegator_vote;
pub mod output;
pub mod spend;
pub mod swap;
pub mod undelegate_claim;
pub mod delegator_vote;

#[repr(C)]
#[cfg_attr(any(feature = "derive-debug", test), derive(Debug))]
Expand Down Expand Up @@ -261,8 +261,6 @@ pub unsafe extern "C" fn rs_delegator_vote_action_hash(
crate::zlog("rs_delegator_vote_action_hash\x00");
let output = std::slice::from_raw_parts_mut(output, output_len);



if output.len() < 64 {
return ParserError::Ok as u32;
}
Expand Down Expand Up @@ -348,14 +346,14 @@ mod tests {
use crate::parser::detection::DetectionDataPlanC;
use crate::parser::fee::FeeC;
use crate::parser::id::IdC;
use crate::parser::identity_key::IdentityKeyC;
use crate::parser::memo::MemoPlanC;
use crate::parser::memo_plain_text::MemoPlaintextC;
use crate::parser::note::NoteC;
use crate::parser::penalty::PenaltyC;
use crate::parser::swap_plaintext::SwapPlaintextC;
use crate::parser::trading_pair::TradingPairC;
use crate::parser::value::ValueC;
use crate::parser::penalty::PenaltyC;
use crate::parser::identity_key::IdentityKeyC;

#[test]
fn test_transaction_plan_hash() {
Expand Down Expand Up @@ -722,7 +720,6 @@ mod tests {
ik: BytesC::from_slice(&ik_bytes),
};


// Create dummy penalty
let inner_bytes =
hex::decode("00000000000000000000000000000000fecbfb15b573eab367a0f9096bb98c7f")
Expand Down Expand Up @@ -761,8 +758,10 @@ mod tests {
let computed_hash = hex::encode(output_action_hash_bytes.as_array());
assert_eq!(computed_hash, expected_hash);
} else {
panic!("output_action_hash is not Ok Error: {:?}", output_action_hash);

panic!(
"output_action_hash is not Ok Error: {:?}",
output_action_hash
);
}
}

Expand Down Expand Up @@ -848,5 +847,4 @@ mod tests {
panic!("spend_action_hash is not Ok");
}
}

}
13 changes: 7 additions & 6 deletions app/rust/src/parser/plans/delegator_vote.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,17 +16,17 @@

use crate::keys::FullViewingKey;
use crate::parser::{
amount::{Amount, AmountC},
bytes::BytesC,
amount::{AmountC, Amount},
effect_hash::{create_personalized_state, EffectHash},
note::{NoteC, Note},
note::{Note, NoteC},
nullifier::Nullifier,
value::Value,
};
use crate::utils::protobuf::encode_varint;
use crate::ParserError;
use decaf377::Fr;
use decaf377_rdsa::{SpendAuth, VerificationKey};
use crate::ParserError;
use crate::utils::protobuf::encode_varint;

pub struct Body {
/// The proposal ID the vote is for.
Expand Down Expand Up @@ -67,7 +67,8 @@ impl DelegatorVotePlanC {
pub fn effect_hash(&self, fvk: &FullViewingKey) -> Result<EffectHash, ParserError> {
let body = self.delegator_vote_body(fvk)?;

let mut state = create_personalized_state("/penumbra.core.component.governance.v1.DelegatorVoteBody");
let mut state =
create_personalized_state("/penumbra.core.component.governance.v1.DelegatorVoteBody");

// proposal
let mut encoded = [0u8; 10];
Expand All @@ -91,7 +92,7 @@ impl DelegatorVotePlanC {
len = encode_varint(body.vote as u64, &mut encoded[pos..]);
state.update(&encoded[..len + 1]);

// value amount
// value amount
state.update(&[0x22]);
let (value, value_len) = body.value.to_proto();
state.update(&value[..value_len]);
Expand Down
4 changes: 2 additions & 2 deletions app/rust/src/parser/plans/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use crate::parser::{
rseed::Rseed,
symmetric::PayloadKey,
symmetric::{OvkWrappedKey, WrappedMemoKey},
value::{Sign, Value, ValueC, Balance, Imbalance},
value::{Balance, Imbalance, Sign, Value, ValueC},
};
use crate::ParserError;
use decaf377::Fr;
Expand Down Expand Up @@ -114,7 +114,7 @@ impl OutputPlanC {

pub fn balance(&self) -> Result<Balance, ParserError> {
let mut balance = Balance::new();
balance.add(Imbalance{
balance.add(Imbalance {
value: Value::try_from(self.value.clone())?,
sign: Sign::Required,
})?;
Expand Down
8 changes: 3 additions & 5 deletions app/rust/src/parser/plans/spend.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ use crate::parser::{
effect_hash::{create_personalized_state, EffectHash},
note::{Note, NoteC},
nullifier::Nullifier,
value::{Sign, Value, Balance, Imbalance},
value::{Balance, Imbalance, Sign, Value},
};
use crate::ParserError;
use decaf377::Fr;
Expand Down Expand Up @@ -65,17 +65,15 @@ impl SpendPlanC {

pub fn spend_body(&self, fvk: &FullViewingKey) -> Result<Body, ParserError> {
Ok(Body {
balance_commitment: self
.balance()?
.commit(self.get_value_blinding_fr()?)?,
balance_commitment: self.balance()?.commit(self.get_value_blinding_fr()?)?,
nullifier: self.nullifier(fvk)?,
rk: self.rk(fvk)?,
})
}

pub fn balance(&self) -> Result<Balance, ParserError> {
let mut balance = Balance::new();
balance.add(Imbalance{
balance.add(Imbalance {
value: Value::try_from(self.note.value.clone())?,
sign: Sign::Provided,
})?;
Expand Down
Loading

0 comments on commit 0242da6

Please sign in to comment.