Skip to content

Commit

Permalink
Triple Masking (Anonymous Transfers) (#237)
Browse files Browse the repository at this point in the history
* CHANGELOG update

* dding triple masking code to ledger and query server package

* integrating finutils and all non-src

* additions and fixes in wasm, query server and ledger (#173)

also dependencies and misc changes

* Added functionality to return list of randomizer strings through wasm

* Adding WASM wrappers to triple masking key serialization/deserialization functions

* anon pub key randomizer wasm

* Returning Randomized AXfr pub key as string

* ruc fixes and integration test scripts improvements

* adding wasmcat into this branch

* remove auto wasm build from pull request to main branch

* Integrate zei arkworks backend (#192)

switched to zei develop, added ark patch and fixes for BLSScalar bytes, changed anon keys

* Nullifier hash, wasm oabar and integrate new setup params (#210)

* added a function in wasm for nullifier hash generation
* added to query server a way to check if a nullifier hash exists or not
* added a wasm function to get oabar
* made some changes to support new zei setup parameters

* update positive unit test on txn_builder with anon fees (#208)

* modified axfr_create_verify_unit_positive_tests() by adding fee input

Author: hridambasu
Co-authored-by: Serge-Juarez
Co-authored-by: akhilpeddireddy
Co-authored-by: Harshad Patil

* wasm randomize AXfrKeyPair fn and fix lint

lint errors due to rustwasm/wasm-bindgen#2774

* sync with zei updates

* Fix node reset and start in devnet

* fix compile error caused by yanked anomaly

* Wasm function to deserialize ABAR

* Fix nullifier hash serialization

* Adding serialization, deserialization for AnonKeys object

* Removing fee for non-Fra assets in bar2abar for testing

* Fix AnonKeys serialization

* Fix FeeInputs Vector capacity limit

* Fix added capacity for FeeInputs

* Integrating anon transfer fee and remainder with txn builder and CLI (#231)

Co-authored-by: akhilpeddireddy <akhilpeddireddy@gmail.com>

* cli abar spent status, handle randomizer for axfr remainder

* fix build after zei merkle tree optimization

* Abar to bar integration (#213)

* Added abar_to_bar integration to the platform

1. made changes to ledger to handle the conv ops
2. added script to test abar_to_bar conversion on fresh local net

* Wasm bindingg for abar_to_bar conversion operation

* FeeOp for Abar - Bar conversions

* change axfr public key in integration/demo script

new keys are used after the arkworks switch in zei

* fix compile error caused by yanked anomaly

* Removing Rocksdb patch as the bug in librocksdb is fixed

* Removed invalid short flags for fn commands

* Fix public key and address CLI flags

Co-authored-by: akhilpeddireddy <akhilpeddireddy@gmail.com>
Co-authored-by: charlie <charlie@findora.org>

* Fix FeeInputs multiple insert call

* Fix build error

* Fix new merkle tree depth and abar to bar demo script

* adding wasm support for anon fee and remainder

* fix storage version, lint and wasm build

* fix clippy errors in smt

* add back wasm_bindgen

were removed in v3 when develop got merged in

* Change names of wasm functions

* Apply precompute verifier parameters (#246)

* Apply precompute verifier parameters

* hotfix verifier test code

* Fix add_input bug in add_fee of transaction builder (#245)

* Fix add_input bug in add_fee of transaction builder

* fix fmt

* Anon assets mixing (#244)

* check abar unspent before transfer

* update anon-transfer CLI to support assets

* update anon-transfer-batch CLI to support assets

* add test shell for anon assets mixing

* fix multi_axfr_test shell

* cleanup test tmp_file

* cut down test shell sleep time

* This includes the function descibed in FO-887 (#251)

* This includes the function descibed in FO-887

* dding wasm interface to fee estimation

Co-authored-by: Harshad Patil <harshad0402@gmail.com>

* Anon Fee for ABAR to BAR (#249)

* Updating zei library version

* Regression tests for triple masking (#254)

* Regression tests for
- bar to abar
- abar transfer
- abar to bar

* fix binary path

* Anon fee for abar to bar conversion

* Updating the zei library version

* Upgrade zei version & hotfix unwrap

* randomizer map and remove amount.rs (#256)

* Update zei version for anon_fee

* Triple masking docs (#258)

* Adding docs for Abar conversions

* fix SID pick in bar to abar conversion

* Fix: user param generation after fee calculation in anon transfer

* Fix algo for FRA fee estimation for some corner cases (#262)

* Fix algo for FRA fee estimation for some corner cases

* Fix fmt

* Fix anon transfer transaction build

* Fix build failure & txn serialization

* Fix handle AXfrKeypair pointer in abar_to_bar conversion

* Fix wasm Key null pointer issue

Clonig all the signing and encryption keys to avoid moving of
pointer in rust-wasm code.

Co-authored-by: charlie <charlie@findora.org>
Co-authored-by: Harshad Patil <harshad0402@gmail.com>
Co-authored-by: tommady <tommady@users.noreply.github.com>
Co-authored-by: Hridam Basu <hridam.basu@gmail.com>
Co-authored-by: findora-crypto <weikeng@findora.org>
Co-authored-by: Serge-Juarez <86990655+Serge-Juarez@users.noreply.github.com>
Co-authored-by: Findora-Sun <94740291+findora-sun@users.noreply.github.com>
Co-authored-by: Sun <sun@findora.org>
  • Loading branch information
9 people authored Apr 1, 2022
1 parent 9e8f65e commit b730823
Show file tree
Hide file tree
Showing 45 changed files with 6,086 additions and 76 deletions.
4 changes: 1 addition & 3 deletions .github/workflows/WasmCat.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
name: Wasm Building And Pushing
on:
push:
branches: ['**_wasm']
on: [push]

jobs:
build-push:
Expand Down
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ Cargo.lock
nohup.out

*.keys
randomizers
sent_randomizers
owned_randomizers
**/.wasm.sh

tools/tendermint
seq_id.str
Expand Down
8 changes: 8 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,11 @@ overflow-checks = false
[profile.dev.package.curve25519-dalek]
opt-level = 1
overflow-checks = false

[patch.crates-io]
ark-ec = { git = "https://github.com/FindoraNetwork/ark-algebra" }
ark-ff = { git = "https://github.com/FindoraNetwork/ark-algebra" }
ark-serialize = { git = "https://github.com/FindoraNetwork/ark-algebra" }
ark-std = { git = "https://github.com/FindoraNetwork/ark-std" }
ark-bls12-381 = { git = "https://github.com/FindoraNetwork/ark-curves" }
ark-ed-on-bls12-381 = { git = "https://github.com/FindoraNetwork/ark-curves" }
14 changes: 13 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ define pack
$(shell go env GOPATH)/bin/tendermint \
$(1)/$(bin_dir)/
cp $(1)/$(bin_dir)/* ~/.cargo/bin/
cd $(1)/$(bin_dir)/ && findorad pack
cd $(1)/$(bin_dir)/ && ./findorad pack
cp -f /tmp/findorad $(1)/$(bin_dir)/
cp -f /tmp/findorad ~/.cargo/bin/
endef
Expand Down Expand Up @@ -275,5 +275,17 @@ evmtest:

devnet: reset snapshot

run_bar_to_abar_demo: devnet
@./tools/triple_masking/bar_to_abar_convert.sh

run_anon_transfer_demo: devnet
@./tools/triple_masking/anonxfr_test_demo.sh

run_multi_anon_transfer_demo: devnet
@./tools/triple_masking/multi_axfr_test_demo.sh

run_anon_asset_mixing_demo: devnet
@./tools/triple_masking/assets_mixing_test_demo.sh

devnet_bridge: devnet
@./tools/devnet/startbridge.sh
5 changes: 3 additions & 2 deletions src/components/abciapp/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@ percent-encoding = "2.1.0"

nix = "0.22.1"

zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4x" }
ruc = { version = "1.0.5", default-features = false, features = ["compact"] }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
ruc = "1.0"
abci = { git = "https://github.com/FindoraNetwork/rust-abci", tag = "v0.7.2" }
config = { path = "../config"}
ledger = { path = "../../ledger" }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ use {
globutils::HashOf,
ledger::{
data_model::{
AssetType, AssetTypeCode, AuthenticatedUtxo, StateCommitmentData, TxnSID,
TxoSID, UnAuthenticatedUtxo, Utxo,
ATxoSID, AssetType, AssetTypeCode, AuthenticatedUtxo, StateCommitmentData,
TxnSID, TxoSID, UnAuthenticatedUtxo, Utxo,
},
staking::{
DelegationRwdDetail, DelegationState, Staking, TendermintAddr,
Expand All @@ -25,6 +25,7 @@ use {
ruc::*,
serde::{Deserialize, Serialize},
std::{collections::BTreeMap, mem, sync::Arc},
zei::anon_xfr::structs::AnonBlindAssetRecord,
zei::xfr::{sig::XfrPublicKey, structs::OwnerMemo},
};

Expand Down Expand Up @@ -689,6 +690,19 @@ pub async fn query_owned_utxos(
.map(|pk| web::Json(pnk!(ledger.get_owned_utxos(&pk))))
}

// query utxos according `public_key`
pub(super) async fn query_owned_abars(
data: web::Data<Arc<RwLock<QueryServer>>>,
owner: web::Path<String>,
) -> actix_web::Result<web::Json<Vec<(ATxoSID, AnonBlindAssetRecord)>>> {
let qs = data.read();
let ledger = &qs.ledger_cloned;
globutils::wallet::anon_public_key_from_base64(owner.as_str())
.c(d!())
.map_err(|e| error::ErrorBadRequest(e.generate_log(None)))
.map(|pk| web::Json(ledger.get_owned_abars(&pk)))
}

#[allow(missing_docs)]
pub enum ApiRoutes {
UtxoSid,
Expand All @@ -701,6 +715,7 @@ pub enum ApiRoutes {
TxnSidLight,
GlobalStateVersion,
OwnedUtxos,
OwnedAbars,
ValidatorList,
DelegationInfo,
DelegatorList,
Expand All @@ -724,6 +739,7 @@ impl NetworkRoute for ApiRoutes {
ApiRoutes::DelegationInfo => "delegation_info",
ApiRoutes::DelegatorList => "delegator_list",
ApiRoutes::ValidatorDetail => "validator_detail",
ApiRoutes::OwnedAbars => "owned_abars",
};
"/".to_owned() + endpoint
}
Expand Down
75 changes: 73 additions & 2 deletions src/components/abciapp/src/api/query_server/query_api/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ use {
globutils::wallet,
ledger::{
data_model::{
b64dec, AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction, TxOutput,
TxnIDHash, TxnSID, TxoSID, XfrAddress, BLACK_HOLE_PUBKEY,
b64dec, ATxoSID, AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction,
TxOutput, TxnIDHash, TxnSID, TxoSID, XfrAddress, BLACK_HOLE_PUBKEY,
},
staking::{
ops::mint_fra::MintEntry, FF_PK_EXTRA_120_0000, FRA, FRA_TOTAL_AMOUNT,
Expand All @@ -33,6 +33,7 @@ use {
sync::Arc,
},
zei::{
anon_xfr::structs::MTLeafInfo,
serialization::ZeiFromToBytes,
xfr::{sig::XfrPublicKey, structs::OwnerMemo},
},
Expand Down Expand Up @@ -93,6 +94,16 @@ pub async fn get_owner_memo_batch(
Ok(web::Json(resp))
}

/// Returns the owner memo required to decrypt the asset record stored at given index, if it exists.
#[allow(clippy::unnecessary_wraps)]
async fn get_abar_memo(
data: web::Data<Arc<RwLock<QueryServer>>>,
info: web::Path<u64>,
) -> actix_web::Result<web::Json<Option<OwnerMemo>>, actix_web::error::Error> {
let server = data.read();
Ok(web::Json(server.get_abar_memo(ATxoSID(*info))))
}

/// Returns an array of the utxo sids currently spendable by a given address
pub async fn get_owned_utxos(
data: web::Data<Arc<RwLock<QueryServer>>>,
Expand All @@ -106,13 +117,48 @@ pub async fn get_owned_utxos(
.map(|pk| web::Json(pnk!(ledger.get_owned_utxos(&pk)).keys().copied().collect()))
}

/// Returns an array of the ATxo Sids currently spendable by a given address
async fn get_owned_abars(
data: web::Data<Arc<RwLock<QueryServer>>>,
owner: web::Path<String>,
) -> actix_web::Result<web::Json<HashSet<ATxoSID>>> {
let qs = data.read();
let ledger = &qs.ledger_cloned;
//let read = qs.state.as_ref().unwrap().read();
globutils::wallet::anon_public_key_from_base64(owner.as_str())
.c(d!())
.map_err(|e| error::ErrorBadRequest(e.generate_log(None)))
.map(|pk| web::Json(ledger.get_owned_abars(&pk).iter().map(|a| a.0).collect()))
}
/// Returns the merkle proof for anonymous transactions
async fn get_abar_proof(
data: web::Data<Arc<RwLock<QueryServer>>>,
info: web::Path<u64>,
) -> actix_web::Result<web::Json<Option<MTLeafInfo>>, actix_web::error::Error> {
let server = data.read();
Ok(web::Json(server.get_abar_proof(ATxoSID(*info))))
}

/// Checks if a nullifier hash is present in nullifier set
async fn check_nullifier_hash(
data: web::Data<Arc<RwLock<QueryServer>>>,
info: web::Path<String>,
) -> actix_web::Result<web::Json<Option<bool>>, actix_web::error::Error> {
let server = data.read();
Ok(web::Json(server.check_nullifier_hash((*info).clone())))
}

/// Define interface type
#[allow(missing_docs)]
pub enum QueryServerRoutes {
GetAddress,
GetOwnerMemo,
GetOwnerMemoBatch,
GetOwnedUtxos,
GetOwnedAbars,
GetAbarMemo,
GetAbarProof,
CheckNullifierHash,
GetCreatedAssets,
GetIssuedRecords,
GetIssuedRecordsByCode,
Expand All @@ -131,8 +177,12 @@ impl NetworkRoute for QueryServerRoutes {
QueryServerRoutes::GetRelatedTxns => "get_related_txns",
QueryServerRoutes::GetRelatedXfrs => "get_related_xfrs",
QueryServerRoutes::GetOwnedUtxos => "get_owned_utxos",
QueryServerRoutes::GetOwnedAbars => "get_owned_abars",
QueryServerRoutes::GetOwnerMemo => "get_owner_memo",
QueryServerRoutes::GetOwnerMemoBatch => "get_owner_memo_batch",
QueryServerRoutes::GetAbarMemo => "get_abar_memo",
QueryServerRoutes::GetAbarProof => "get_abar_proof",
QueryServerRoutes::CheckNullifierHash => "check_nullifier_hash",
QueryServerRoutes::GetCreatedAssets => "get_created_assets",
QueryServerRoutes::GetIssuedRecords => "get_issued_records",
QueryServerRoutes::GetIssuedRecordsByCode => "get_issued_records_by_code",
Expand Down Expand Up @@ -506,6 +556,10 @@ impl QueryApi {
&QueryServerRoutes::GetOwnedUtxos.with_arg_template("address"),
web::get().to(get_owned_utxos),
)
.route(
&QueryServerRoutes::GetOwnedAbars.with_arg_template("address"),
web::get().to(get_owned_abars),
)
.route(
&QueryServerRoutes::GetOwnerMemo.with_arg_template("txo_sid"),
web::get().to(get_owner_memo),
Expand All @@ -515,6 +569,19 @@ impl QueryApi {
.with_arg_template("txo_sid_list"),
web::get().to(get_owner_memo_batch),
)
.route(
&QueryServerRoutes::GetAbarMemo.with_arg_template("atxo_sid"),
web::get().to(get_abar_memo),
)
.route(
&QueryServerRoutes::GetAbarProof.with_arg_template("atxo_sid"),
web::get().to(get_abar_proof),
)
.route(
&QueryServerRoutes::CheckNullifierHash
.with_arg_template("null_hash"),
web::get().to(check_nullifier_hash),
)
.route(
&QueryServerRoutes::GetRelatedTxns.with_arg_template("address"),
web::get().to(get_related_txns),
Expand Down Expand Up @@ -600,6 +667,10 @@ impl QueryApi {
&ApiRoutes::OwnedUtxos.with_arg_template("owner"),
web::get().to(query_owned_utxos),
)
.route(
&ApiRoutes::OwnedAbars.with_arg_template("owner"),
web::get().to(query_owned_abars),
)
.route(
&ApiRoutes::ValidatorList.route(),
web::get().to(query_validators),
Expand Down
27 changes: 25 additions & 2 deletions src/components/abciapp/src/api/query_server/query_api/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use {
lazy_static::lazy_static,
ledger::{
data_model::{
AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction, TxOutput,
ATxoSID, AssetTypeCode, DefineAsset, IssuerPublicKey, Transaction, TxOutput,
TxnIDHash, TxnSID, TxoSID, XfrAddress,
},
staking::{ops::mint_fra::MintEntry, BlockHeight},
Expand All @@ -15,7 +15,7 @@ use {
parking_lot::{Condvar, Mutex, RwLock},
ruc::*,
std::{collections::HashSet, sync::Arc},
zei::xfr::structs::OwnerMemo,
zei::{anon_xfr::structs::MTLeafInfo, xfr::structs::OwnerMemo},
};

lazy_static! {
Expand Down Expand Up @@ -300,6 +300,29 @@ impl QueryServer {
.get(&txo_sid)
}

/// Returns the abar owner memo required to decrypt the asset record stored at given index, if it exists.
#[inline(always)]
pub fn get_abar_memo(&self, atxo_sid: ATxoSID) -> Option<OwnerMemo> {
self.ledger_cloned
.api_cache
.as_ref()
.unwrap()
.abar_memos
.get(&atxo_sid)
}

/// Returns the merkle proof from the given ATxoSID
#[inline(always)]
pub fn get_abar_proof(&self, atxo_sid: ATxoSID) -> Option<MTLeafInfo> {
self.ledger_cloned.get_abar_proof(atxo_sid).ok()
}

/// Returns a bool value from the given hash
#[inline(always)]
pub fn check_nullifier_hash(&self, null_hash: String) -> Option<bool> {
self.ledger_cloned.check_nullifier_hash(null_hash).ok()
}

/// retrieve block reward rate at specified block height
#[inline(always)]
pub fn query_block_rewards_rate(&self, height: &BlockHeight) -> Option<[u128; 2]> {
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 @@ -26,4 +26,4 @@ fp-types = { path = "../../primitives/types" }
[dev-dependencies]
parking_lot = "0.11.1"
rand_chacha = "0.2.0"
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4x" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
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.2.0"
rlp = "0.5"
serde_json = "1.0"
sha3 = "0.8"
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4x" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }

# primitives
fp-traits = { path = "../traits" }
Expand Down
2 changes: 1 addition & 1 deletion src/components/contracts/primitives/types/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ ruc = "1.0"
serde = { version = "1.0.124", features = ["derive"] }
serde_json = "1.0"
sha3 = "0.8"
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4x" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
fixed-hash = "0.7.0"

# primitives
Expand Down
5 changes: 4 additions & 1 deletion src/components/finutils/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@ serde = { version = "1.0.124", features = ["derive"] }
rand = "0.8"
rand_core = { version = "0.5", default-features = false, features = ["alloc"] }
rand_chacha = "0.2.0"
parking_lot = "0.11.1"
curve25519-dalek = { version = "3.0", features = ["serde"] }
wasm-bindgen = { version = "0.2.50", features = ["serde-serialize"] }

zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.4x" }
zei = { git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
crypto = { package = "crypto", git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
zeialgebra = { package = "algebra", git = "https://github.com/FindoraNetwork/zei", tag = "v0.1.5a" }
ruc = "1.0"

ledger = { path = "../../ledger" }
Expand Down
Loading

0 comments on commit b730823

Please sign in to comment.