Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ed25519 triple masking #794

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 0 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,13 +58,5 @@ opt-level = 1
overflow-checks = false

[patch.crates-io]
ark-ec = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" }
ark-ff = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" }
ark-serialize = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" }
ark-std = { git = "https://github.com/FindoraNetwork/ark-std", tag = "stable-2022" }
ark-bls12-381 = { git = "https://github.com/FindoraNetwork/ark-curves", tag = "stable-2022" }
ark-ed-on-bls12-381 = { git = "https://github.com/FindoraNetwork/ark-curves", tag = "stable-2022" }
ark-algebra-test-templates = { git = "https://github.com/FindoraNetwork/ark-algebra", tag = "stable-2022" }
curve25519-dalek = { git = "https://github.com/FindoraNetwork/curve25519-dalek", tag = "v3.2.0-f" }
ed25519-dalek = { git = "https://github.com/FindoraNetwork/ed25519-dalek", tag = "v1.0.1-f" }
abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" }
4 changes: 2 additions & 2 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ ruc = { version = "1.0.5", default-features = false, features = ["compact"] }
module-evm = { path = "../contracts/modules/evm"}
ethereum-types = { version = "0.13.1", default-features = false }

noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }

abci = { git = "https://github.com/FindoraNetwork/tendermint-abci", tag = "0.7.5" }
config = { path = "../config"}
Expand Down
12 changes: 7 additions & 5 deletions src/components/abciapp/src/abci/staking/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ use {
store::LedgerState,
utils::fra_gen_initial_tx,
},
noah::xfr::{
asset_record::{open_blind_asset_record, AssetRecordType},
sig::{XfrKeyPair, XfrPublicKey},
structs::{AssetRecordTemplate, XfrAmount},
noah::{
keys::{KeyPair as XfrKeyPair, PublicKey as XfrPublicKey},
xfr::{
asset_record::{open_blind_asset_record, AssetRecordType},
structs::{AssetRecordTemplate, XfrAmount},
},
},
rand::random,
rand_chacha::ChaChaRng,
Expand All @@ -33,7 +35,7 @@ fn staking_block_rewards_rate() {
// 4. check if the block rewards rate is correct per loop
fn check_block_rewards_rate() -> Result<()> {
let mut ledger = LedgerState::tmp_ledger();
let root_kp = XfrKeyPair::generate(&mut ChaChaRng::from_entropy());
let root_kp = XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy());

let tx = fra_gen_initial_tx(&root_kp);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ use {
TendermintAddrRef,
},
},
noah::xfr::{sig::XfrPublicKey, structs::OwnerMemo},
noah::keys::PublicKey as XfrPublicKey,
noah::xfr::structs::OwnerMemo,
parking_lot::RwLock,
ruc::*,
serde::{Deserialize, Serialize},
Expand Down
3 changes: 2 additions & 1 deletion src/components/abciapp/src/api/query_server/query_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ use {
ledger_api::*,
noah::{
anon_xfr::structs::{AxfrOwnerMemo, Commitment, MTLeafInfo},
xfr::{sig::XfrPublicKey, structs::OwnerMemo},
keys::PublicKey as XfrPublicKey,
xfr::structs::OwnerMemo,
},
noah_algebra::serialization::NoahFromToBytes,
parking_lot::RwLock,
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/modules/account/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ parking_lot = "0.12"
rand_chacha = "0.3"
storage = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
fin_db = { git = "https://github.com/FindoraNetwork/storage.git", tag = "v1.1.4" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }

[features]
web3_service = ["enterprise-web3"]
46 changes: 23 additions & 23 deletions src/components/contracts/modules/account/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use fp_storage::{Borrow, BorrowMut};
use fp_traits::account::AccountAsset;
use fp_types::crypto::Address;
use fp_types::U256;
use noah::xfr::sig::XfrKeyPair;
use noah::keys::KeyPair as XfrKeyPair;
use parking_lot::RwLock;
use rand_chacha::rand_core::SeedableRng;
use rand_chacha::ChaChaRng;
Expand Down Expand Up @@ -48,8 +48,8 @@ fn test_accounts_set_get() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand Down Expand Up @@ -79,8 +79,8 @@ fn test_account_of() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let addr = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let addr = Address::from(key.get_pk());

//Generate SmartAccount
let sa1 = SmartAccount {
Expand Down Expand Up @@ -154,8 +154,8 @@ fn test_account_balance() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand All @@ -179,8 +179,8 @@ fn test_account_nonce() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand All @@ -204,8 +204,8 @@ fn test_account_inc_nonce() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand All @@ -232,10 +232,10 @@ fn test_account_transfer() {

//Generate Addresses
let mut prng = ChaChaRng::from_entropy();
let key1 = XfrKeyPair::generate(&mut prng);
let key2 = XfrKeyPair::generate(&mut prng);
let address1 = Address::from(key1.pub_key);
let address2 = Address::from(key2.pub_key);
let key1 = XfrKeyPair::generate_ed25519(&mut prng);
let key2 = XfrKeyPair::generate_ed25519(&mut prng);
let address1 = Address::from(key1.get_pk());
let address2 = Address::from(key2.get_pk());

//Generate accounts with different amounts
let mut acct1 = SmartAccount::default();
Expand Down Expand Up @@ -272,8 +272,8 @@ fn test_account_mint() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand All @@ -298,8 +298,8 @@ fn test_account_burn() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand All @@ -325,8 +325,8 @@ fn test_account_withdraw() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand Down Expand Up @@ -354,8 +354,8 @@ fn test_account_refund() {

//Generate Address
let mut prng = ChaChaRng::from_entropy();
let key = XfrKeyPair::generate(&mut prng);
let address = Address::from(key.pub_key);
let key = XfrKeyPair::generate_ed25519(&mut prng);
let address = Address::from(key.get_pk());

//Generate SmartAccount
let account = SmartAccount {
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/modules/evm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ serde_json = "1.0.64"
sha3 = { version = "0.10", default-features = false }
hex = "0.4.2"
ethabi = "17.1.0"
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }

# primitives, don't depend on any modules
fp-core = { path = "../../primitives/core" }
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/modules/evm/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ use fp_types::{
actions::evm::Action,
crypto::{Address, HA160},
};
use noah::xfr::sig::XfrPublicKey;
use noah::keys::PublicKey as XfrPublicKey;
use noah_algebra::serialization::NoahFromToBytes;
use precompile::PrecompileSet;
use ruc::*;
Expand Down
7 changes: 4 additions & 3 deletions src/components/contracts/modules/evm/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ use ethabi::{Event, EventParam, ParamType, RawLog};
use fp_traits::evm::{DecimalsMapping, EthereumDecimalsMapping};
use fp_types::actions::xhub::NonConfidentialOutput;
use ledger::data_model::ASSET_TYPE_FRA;
use noah::xfr::structs::ASSET_TYPE_LENGTH;
use noah::xfr::{sig::XfrPublicKey, structs::AssetType};
use noah::keys::PublicKey as XfrPublicKey;
use noah::xfr::structs::{AssetType, ASSET_TYPE_LENGTH};
use noah_algebra::serialization::NoahFromToBytes;
use ruc::*;

Expand Down Expand Up @@ -69,7 +69,8 @@ pub fn parse_deposit_asset_event(data: Vec<u8>) -> Result<NonConfidentialOutput>
.clone()
.into_bytes()
.unwrap_or_default();
let target = XfrPublicKey::noah_from_bytes(receiver.as_slice()).unwrap_or_default();
let target = XfrPublicKey::noah_from_bytes(receiver.as_slice())
.unwrap_or_else(|_| XfrPublicKey::default_ed25519());

let amount = result.params[2]
.value
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ fn run_all_tests() {
test_abci_info();
test_abci_init_chain();
test_mint_balance(
&ALICE_XFR.pub_key.into(),
&ALICE_XFR.get_pk().into(),
100_0000_0000_0000_0000_u64.into(),
0,
);
Expand Down Expand Up @@ -79,7 +79,7 @@ fn test_abci_check_tx() {
assert_eq!(
module_account::App::<BaseApp>::balance(
&BASE_APP.lock().unwrap().check_state,
&ALICE_XFR.pub_key.into()
&ALICE_XFR.get_pk().into()
),
U256::from(100_0000_0000_0000_0000_u64)
);
Expand Down Expand Up @@ -146,7 +146,7 @@ fn test_abci_commit() {
assert_eq!(
module_account::App::<BaseApp>::balance(
&BASE_APP.lock().unwrap().deliver_state,
&ALICE_XFR.pub_key.into()
&ALICE_XFR.get_pk().into()
),
U256::from(100_0000_0000_0000_0000_u64).saturating_sub(
<BaseApp as module_account::Config>::FeeCalculator::min_fee()
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/mocks/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ rand_chacha = "0.3"
rlp = "0.5"
serde_json = "1.0"
sha3 = "0.10"
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }

# primitives
fp-traits = { path = "../traits" }
Expand Down
6 changes: 3 additions & 3 deletions src/components/contracts/primitives/mocks/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ use fp_traits::account::AccountAsset;
use fp_traits::evm::{AddressMapping, EthereumAddressMapping};
use fp_types::crypto::{Address, MultiSignature};
use lazy_static::lazy_static;
use noah::xfr::sig::XfrKeyPair;
use noah::keys::KeyPair as XfrKeyPair;
use primitive_types::{H160, H256, U256};
use rand_chacha::{rand_core::SeedableRng, ChaChaRng};
use rlp::*;
Expand All @@ -29,9 +29,9 @@ lazy_static! {
pub static ref ALICE_ECDSA: KeyPair = generate_address(1);
pub static ref BOB_ECDSA: KeyPair = generate_address(2);
pub static ref ALICE_XFR: XfrKeyPair =
XfrKeyPair::generate(&mut ChaChaRng::from_entropy());
XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy());
pub static ref BOB_XFR: XfrKeyPair =
XfrKeyPair::generate(&mut ChaChaRng::from_entropy());
XfrKeyPair::generate_ed25519(&mut ChaChaRng::from_entropy());
}

pub fn test_mint_balance(who: &Address, balance: U256, height: u64) {
Expand Down
4 changes: 2 additions & 2 deletions src/components/contracts/primitives/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0"
serde-big-array = "0.4"
sha3 = "0.10"
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.3.2" }
noah = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }
noah-algebra = { git = "https://github.com/FindoraNetwork/noah", tag = "v0.4.3" }

# primitives
fp-utils = { path = "../utils" }
Expand Down
16 changes: 14 additions & 2 deletions src/components/contracts/primitives/types/src/actions/xhub.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use noah::xfr::sig::XfrPublicKey;
use noah::keys::{PublicKey as XfrPublicKey, PublicKey};
use noah::xfr::structs::AssetType;
use serde::{Deserialize, Serialize};

Expand All @@ -15,7 +15,7 @@ pub struct NonConfidentialTransfer {
}

/// Evm account balance convert to NonConfidential utxo.
#[derive(Clone, Debug, Default, PartialEq, Eq, Serialize, Deserialize)]
#[derive(Clone, Debug, PartialEq, Eq, Serialize, Deserialize)]
pub struct NonConfidentialOutput {
pub asset: AssetType,
pub amount: u64,
Expand All @@ -25,3 +25,15 @@ pub struct NonConfidentialOutput {
#[serde(skip)]
pub max_supply: u64,
}

impl Default for NonConfidentialOutput {
fn default() -> Self {
NonConfidentialOutput {
asset: Default::default(),
amount: 0,
target: PublicKey::default_ed25519(),
decimal: 0,
max_supply: 0,
}
}
}
Loading