Skip to content

Commit

Permalink
Fix enc_balance getter
Browse files Browse the repository at this point in the history
  • Loading branch information
osuketh committed Sep 17, 2019
1 parent b414ee4 commit 83e1931
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 16 deletions.
1 change: 0 additions & 1 deletion modules/anonymous-balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,6 @@ impl<T: Trait> Module<T> {
/// To achieve this, we define a separate (internal) method for rolling over,
/// and the first thing every other method does is to call this method.
/// More details in Section 3.1: https://crypto.stanford.edu/~buenz/papers/zether.pdf
pub fn rollover(addr: &EncKey) -> result::Result<(), &'static str> {
let current_epoch = <zk_system::Module<T>>::get_current_epoch();

Expand Down
2 changes: 1 addition & 1 deletion modules/encrypted-assets/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
use support::{decl_module, decl_storage, decl_event, StorageMap, Parameter, StorageValue, ensure};
use rstd::prelude::*;
use rstd::result;
use runtime_primitives::traits::{SimpleArithmetic, Zero, One, As};
use runtime_primitives::traits::{SimpleArithmetic, Zero, One};
use system::ensure_signed;
use zprimitives::{
EncKey, Proof,
Expand Down
2 changes: 1 addition & 1 deletion modules/encrypted-balances/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,7 +224,7 @@ impl<T: Trait> Module<T> {

impl<T: Trait> IsDeadAccount<T::AccountId> for Module<T>
{
fn is_dead_account(who: &T::AccountId) -> bool {
fn is_dead_account(_who: &T::AccountId) -> bool {
unimplemented!();
}
}
Expand Down
2 changes: 1 addition & 1 deletion modules/executive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use primitives::traits::{
self, Header, Zero, One, Checkable, Applyable, CheckEqual, OnFinalize,
OnInitialize, Hash, As, Digest, NumberFor, Block as BlockT, OffchainWorker
};
use srml_support::{Dispatchable, traits::MakePayment};
use srml_support::Dispatchable;
use parity_codec::{Codec, Encode};
use system::extrinsics_root;
use primitives::{ApplyOutcome, ApplyError};
Expand Down
15 changes: 3 additions & 12 deletions zface/src/utils/getter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,12 +138,9 @@ impl BalanceQuery {
dec_key: &DecryptionKey<Bls12>
) -> Result<Self> {
let p_g = zFixedGenerators::Diversifier; // 1
let decrypted_balance;
let p_decrypted_balance;
let mut ciphertext = None;
let mut p_ciphertext = None;

// TODO: redundant code
if encrypted_balance_str.as_str() != "0x00" {
// TODO: remove unnecessary prefix. If it returns `0x00`, it will be panic.
for _ in 0..4 {
Expand All @@ -152,11 +149,7 @@ impl BalanceQuery {

let encrypted_balance = hexstr_to_vec(encrypted_balance_str.clone());
ciphertext = Some(zelgamal::Ciphertext::<zBls12>::read(&mut &encrypted_balance[..], &ZPARAMS)?);
decrypted_balance = ciphertext.clone().unwrap().decrypt(&no_std(&dec_key)?, p_g, &ZPARAMS).unwrap();
} else {
decrypted_balance = 0;
}

if pending_transfer_str.as_str() != "0x00" {
// TODO: remove unnecessary prefix. If it returns `0x00`, it will be panic.
for _ in 0..4 {
Expand All @@ -165,18 +158,16 @@ impl BalanceQuery {

let pending_transfer = hexstr_to_vec(pending_transfer_str.clone());
p_ciphertext = Some(zelgamal::Ciphertext::<zBls12>::read(&mut &pending_transfer[..], &ZPARAMS)?);
p_decrypted_balance = p_ciphertext.clone().unwrap().decrypt(&no_std(&dec_key)?, p_g, &ZPARAMS).unwrap();
} else {
p_decrypted_balance = 0;
}

let zero = zelgamal::Ciphertext::<zBls12>::zero();
let enc_total = ciphertext.unwrap_or(zero.clone()).add(&p_ciphertext.unwrap_or(zero), &*ZPARAMS);
let dec_balance = enc_total.decrypt(&no_std(&dec_key)?, p_g, &ZPARAMS).unwrap();
let mut buf = vec![0u8; 64];
enc_total.write(&mut buf[..])?;

Ok(BalanceQuery {
decrypted_balance: decrypted_balance + p_decrypted_balance,
decrypted_balance: dec_balance,
encrypted_balance: buf,
encrypted_balance_str,
pending_transfer_str,
Expand All @@ -201,7 +192,7 @@ pub fn g_epoch(api: &Api) -> Result<edwards::Point<Bls12, PrimeOrder>> {

let point = edwards::Point::<Bls12, _>::read(&mut g_epoch.as_ref(), &PARAMS)?
.as_prime_order(&PARAMS)
.unwrap();
.unwrap();

Ok(point)
}
Expand Down

0 comments on commit 83e1931

Please sign in to comment.