Skip to content

Commit cc0e970

Browse files
committed
triple_masking
* ledger add noah * components add noah * fix lint * update keypair * fix lint * remove is_address_fra * fix xfrboxy * signature.verify * update enable_triple_masking_height to enable_ed25519_triple_masking_height * fix OwnerMemo * fix test * update noah version * fix anon transfer batch --------- Co-authored-by: shaorongqiang <[email protected]> triple_masking dependencies to develop (#926) * dependencies to develop * update wasm-bindgen * remove noah * strike build_record_and_get_blinds --------- Co-authored-by: shaorongqiang <[email protected]> Co-authored-by: weikengchen <[email protected]> Renew #935 for merging develop with main. (#937) * fix * Upgrade noah to v0.4.6 * update --------- Co-authored-by: weikeng <[email protected]> Co-authored-by: Sun <[email protected]> Co-authored-by: weikengchen <[email protected]> Add noah init wasm (#941) Fix abar_to_ar params (#950) Let the Anemoi precompile use the platform-lib-noah library (#963) fix build (#977) Co-authored-by: Weikeng Chen <[email protected]> Improve Noah secp support (#981) * Improve Noah secp support * update deps * update platform-lib-utils for testing * public key to bytes in data_model * fix * fix * Avoid lint bug * fix EVM XfrPublicKey deserialization * edit the dependency * fix error handling --------- Co-authored-by: weikengchen <[email protected]> EIP 1962 is undecided (#984) Use BN254 Anemoi for asset ID mapping (#985) * Improve Noah secp support * update deps * update platform-lib-utils for testing * public key to bytes in data_model * fix * fix * Avoid lint bug * fix EVM XfrPublicKey deserialization * edit the dependency * fix error handling * update the asset code * fix --------- Co-authored-by: Harshad Patil <[email protected]> add validator_whitelist v1 (#972) * fix timeout and checkpoint * add validator_whitelist v1 * add validator_whitelist add validator_whitelist_v2 (#976) * add validator_whitelist_v2 * update timeout_commit 10s * update validator_whitelist * bug fix * fix build validator whitelist v3 (#980) downgrade ctrlc (#973) update timeout_propose 3s (#974) update timeout_commit 10s (#975) Fix Fn_Check Bug (#970) android add execption (#979) validator whitelist v3 (#980) pr Adding checkpoint condition to AnemoiJive381 upgrade only use deprecated AnemoiJive381 for old precompiled contract query server API to get derived asset code fix build remo0ve unneeded sign in tx build fix Lint fmt fix build CLI test file test disable eth address transfer from EVM fix build enable eth-address in CLI fix lint update lib-noah branch update demo tests for triple masking fix CLI eth-address removed unrelated code changes remove some unrelated code review ledger package fix wallet_mobile build remove unneccesary refactoring fix some refactoring synced changes from platform-lib-noah removed testing scripts fmt & lint fix import statements remove unneeded refactoring fix conflicts
1 parent d5cd3b9 commit cc0e970

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

72 files changed

+6817
-780
lines changed

Cargo.toml

+21-9
Original file line numberDiff line numberDiff line change
@@ -37,22 +37,34 @@ members = [
3737
]
3838

3939
[profile.dev]
40-
incremental = false
40+
opt-level = 3
41+
lto = "thin"
42+
incremental = true
43+
debug-assertions = true
44+
debug = true
45+
panic = 'abort'
4146
overflow-checks = true
4247

4348
[profile.release]
49+
opt-level = 3
50+
lto = "thin"
4451
incremental = false
4552
overflow-checks = true
53+
panic = 'abort'
4654

4755
[profile.bench]
56+
opt-level = 3
57+
debug = false
58+
rpath = false
59+
lto = "thin"
4860
codegen-units = 1
61+
incremental = true
62+
debug-assertions = false
4963
overflow-checks = false
5064

51-
[profile.dev.package.curve25519-dalek]
52-
opt-level = 1
53-
overflow-checks = false
54-
55-
[patch.crates-io]
56-
ed25519-dalek = { git = "https://github.com/FindoraNetwork/ed25519-dalek", rev = "ad461f" }
57-
curve25519-dalek = { git = "https://github.com/FindoraNetwork/curve25519-dalek", rev = "a2df65" }
58-
x25519-dalek = { git = "https://github.com/FindoraNetwork/x25519-dalek", rev = "53bb1a" }
65+
[profile.test]
66+
opt-level = 2
67+
lto = "off"
68+
incremental = true
69+
debug-assertions = true
70+
debug = true

src/components/abciapp/src/abci/mod.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ use {
1212
crate::api::{
1313
query_server::query_api, submission_server::submission_api::SubmissionApi,
1414
},
15+
baseapp::tm_events::init_url,
1516
config::abci::{global_cfg::CFG, ABCIConfig},
1617
futures::executor::ThreadPool,
1718
lazy_static::lazy_static,
@@ -94,7 +95,7 @@ pub fn run() -> Result<()> {
9495
"http://{}:{}",
9596
config.tendermint_host, config.tendermint_port
9697
);
97-
98+
pnk!(init_url(tendermint_rpc.as_str()));
9899
// keep them running in the background,
99100
// avoid being dropped by the jsonrpc crate.
100101
mem::forget(fc_rpc::start_web3_service(

src/components/abciapp/src/abci/server/callback/mod.rs

+102-12
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,6 @@
22
//! # Impl function of tendermint ABCI
33
//!
44
5-
use globutils::wallet;
6-
use ledger::{
7-
data_model::ASSET_TYPE_FRA,
8-
staking::{FF_ADDR_EXTRA_120_0000, FF_ADDR_LIST},
9-
};
10-
use zei::noah_api::xfr::asset_record::AssetRecordType;
11-
125
mod utils;
136

147
use {
@@ -32,11 +25,15 @@ use {
3225
STATE_UPDATE_LIST, TXS, WEB3_SERVICE_START_HEIGHT,
3326
},
3427
fp_storage::hash::{Sha256, StorageHasher},
28+
globutils::wallet,
3529
lazy_static::lazy_static,
3630
ledger::{
3731
converter::is_convert_account,
38-
data_model::Operation,
39-
staking::{evm::EVM_STAKING, KEEP_HIST, VALIDATOR_UPDATE_BLOCK_ITV},
32+
data_model::{Operation, Transaction, ASSET_TYPE_FRA},
33+
staking::{
34+
evm::EVM_STAKING, FF_ADDR_EXTRA_120_0000, FF_ADDR_LIST, KEEP_HIST,
35+
VALIDATOR_UPDATE_BLOCK_ITV,
36+
},
4037
store::{
4138
api_cache,
4239
fbnc::{new_mapx, Mapx},
@@ -56,6 +53,7 @@ use {
5653
},
5754
},
5855
tracing::{error, info},
56+
zei::noah_api::xfr::asset_record::AssetRecordType,
5957
};
6058

6159
pub(crate) static TENDERMINT_BLOCK_HEIGHT: AtomicI64 = AtomicI64::new(0);
@@ -100,9 +98,15 @@ pub fn info(s: &mut ABCISubmissionServer, req: &RequestInfo) -> ResponseInfo {
10098
&& h < CFG.checkpoint.enable_frc20_height
10199
{
102100
resp.set_last_block_app_hash(la_hash);
103-
} else {
101+
} else if h < CFG.checkpoint.enable_ed25519_triple_masking_height {
104102
let cs_hash = s.account_base_app.write().info(req).last_block_app_hash;
105103
resp.set_last_block_app_hash(app_hash("info", h, la_hash, cs_hash));
104+
} else {
105+
let cs_hash = s.account_base_app.write().info(req).last_block_app_hash;
106+
let tm_hash = state.get_anon_state_commitment().0;
107+
resp.set_last_block_app_hash(app_hash_v2(
108+
"info", h, la_hash, cs_hash, tm_hash,
109+
));
106110
}
107111
}
108112

@@ -140,6 +144,18 @@ pub fn check_tx(s: &mut ABCISubmissionServer, req: &RequestCheckTx) -> ResponseC
140144
TxCatalog::FindoraTx => {
141145
if matches!(req.field_type, CheckTxType::New) {
142146
if let Ok(tx) = convert_tx(req.get_tx()) {
147+
for op in tx.body.operations.iter() {
148+
if let Operation::TransferAnonAsset(op) = op {
149+
let mut inputs = op.note.body.inputs.clone();
150+
inputs.sort();
151+
inputs.dedup();
152+
if inputs.len() != op.note.body.inputs.len() {
153+
resp.log = "anon Transfer input error".to_owned();
154+
resp.code = 1;
155+
return resp;
156+
}
157+
}
158+
}
143159
if td_height > CFG.checkpoint.check_signatures_num {
144160
for op in tx.body.operations.iter() {
145161
if let Operation::TransferAsset(op) = op {
@@ -171,6 +187,12 @@ pub fn check_tx(s: &mut ABCISubmissionServer, req: &RequestCheckTx) -> ResponseC
171187
} else if TX_HISTORY.read().contains_key(&tx.hash_tm_rawbytes()) {
172188
resp.log = "Historical transaction".to_owned();
173189
resp.code = 1;
190+
} else if is_tm_transaction(&tx)
191+
&& td_height
192+
< CFG.checkpoint.enable_ed25519_triple_masking_height
193+
{
194+
resp.code = 1;
195+
resp.log = "Triple Masking is disabled".to_owned();
174196
}
175197
} else {
176198
resp.log = "Invalid format".to_owned();
@@ -272,6 +294,18 @@ pub fn deliver_tx(
272294
match tx_catalog {
273295
TxCatalog::FindoraTx => {
274296
if let Ok(tx) = convert_tx(req.get_tx()) {
297+
for op in tx.body.operations.iter() {
298+
if let Operation::TransferAnonAsset(op) = op {
299+
let mut inputs = op.note.body.inputs.clone();
300+
inputs.sort();
301+
inputs.dedup();
302+
if inputs.len() != op.note.body.inputs.len() {
303+
resp.log = "anon Transfer input error".to_owned();
304+
resp.code = 1;
305+
return resp;
306+
}
307+
}
308+
}
275309
if td_height > CFG.checkpoint.check_signatures_num {
276310
for op in tx.body.operations.iter() {
277311
if let Operation::TransferAsset(op) = op {
@@ -336,7 +370,7 @@ pub fn deliver_tx(
336370
if let Err(err) =
337371
s.account_base_app.write().deliver_findora_tx(&tx, &hash.0)
338372
{
339-
info!(target: "abciapp", "deliver convert account tx failed: {err:?}");
373+
error!(target: "abciapp", "deliver convert account tx failed: {err:?}");
340374

341375
resp.code = 1;
342376
resp.log =
@@ -375,6 +409,17 @@ pub fn deliver_tx(
375409
.db
376410
.write()
377411
.discard_session();
412+
} else if is_tm_transaction(&tx)
413+
&& td_height
414+
< CFG.checkpoint.enable_ed25519_triple_masking_height
415+
{
416+
info!(target: "abciapp",
417+
"Triple Masking transaction(FindoraTx) detected at early height {}: {:?}",
418+
td_height, tx
419+
);
420+
resp.code = 2;
421+
resp.log = "Triple Masking is disabled".to_owned();
422+
return resp;
378423
} else if CFG.checkpoint.utxo_checktx_height < td_height {
379424
match tx.check_tx() {
380425
Ok(_) => {
@@ -597,8 +642,11 @@ pub fn commit(s: &mut ABCISubmissionServer, req: &RequestCommit) -> ResponseComm
597642
&& td_height < CFG.checkpoint.enable_frc20_height
598643
{
599644
r.set_data(la_hash);
600-
} else {
645+
} else if td_height < CFG.checkpoint.enable_ed25519_triple_masking_height {
601646
r.set_data(app_hash("commit", td_height, la_hash, cs_hash));
647+
} else {
648+
let tm_hash = state.get_anon_state_commitment().0;
649+
r.set_data(app_hash_v2("commit", td_height, la_hash, cs_hash, tm_hash));
602650
}
603651

604652
IN_SAFE_ITV.store(false, Ordering::Release);
@@ -728,3 +776,45 @@ fn app_hash(
728776
la_hash
729777
}
730778
}
779+
780+
/// Combines ledger state hash and EVM chain state hash
781+
/// and print app hashes for debugging
782+
fn app_hash_v2(
783+
when: &str,
784+
height: i64,
785+
mut la_hash: Vec<u8>,
786+
mut cs_hash: Vec<u8>,
787+
mut tm_hash: Vec<u8>,
788+
) -> Vec<u8> {
789+
info!(target: "abciapp",
790+
"app_hash_{}: {}_{}_{}, height: {}",
791+
when,
792+
hex::encode(la_hash.clone()),
793+
hex::encode(cs_hash.clone()),
794+
hex::encode(tm_hash.clone()),
795+
height
796+
);
797+
798+
// append ONLY non-empty EVM chain state hash
799+
if !tm_hash.is_empty() || !cs_hash.is_empty() {
800+
la_hash.append(&mut cs_hash);
801+
la_hash.append(&mut tm_hash);
802+
803+
Sha256::hash(la_hash.as_slice()).to_vec()
804+
} else {
805+
la_hash
806+
}
807+
}
808+
809+
fn is_tm_transaction(tx: &Transaction) -> bool {
810+
tx.body
811+
.operations
812+
.iter()
813+
.try_for_each(|op| match op {
814+
Operation::BarToAbar(_a) => None,
815+
Operation::AbarToBar(_a) => None,
816+
Operation::TransferAnonAsset(_a) => None,
817+
_ => Some(()),
818+
})
819+
.is_none()
820+
}

src/components/abciapp/src/abci/server/callback/utils.rs

+61-1
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,13 @@ pub fn gen_tendermint_attr(tx: &Transaction) -> RepeatedField<Event> {
3939
res.push(ev);
4040

4141
let (from, to) = gen_tendermint_attr_addr(tx);
42+
let (nullifiers, commitments) = gen_tendermint_attr_anon(tx);
4243

43-
if !from.is_empty() || !to.is_empty() {
44+
if !from.is_empty()
45+
|| !to.is_empty()
46+
|| !nullifiers.is_empty()
47+
|| !commitments.is_empty()
48+
{
4449
let mut ev = Event::new();
4550
ev.set_field_type("addr".to_owned());
4651

@@ -76,6 +81,8 @@ pub fn gen_tendermint_attr(tx: &Transaction) -> RepeatedField<Event> {
7681

7782
index_addr!(from, "addr.from");
7883
index_addr!(to, "addr.to");
84+
index_addr!(nullifiers, "nullifier.used");
85+
index_addr!(commitments, "commitment.created");
7986
}
8087

8188
RepeatedField::from_vec(res)
@@ -126,6 +133,59 @@ fn gen_tendermint_attr_addr(tx: &Transaction) -> (Vec<TagAttr>, Vec<TagAttr>) {
126133
Operation::UpdateMemo(d) => {
127134
append_attr!(d);
128135
}
136+
Operation::BarToAbar(d) => {
137+
let mut attr = TagAttr::default();
138+
attr.addr = globutils::wallet::public_key_to_bech32(
139+
&d.input_record().public_key,
140+
);
141+
base.0.push(attr);
142+
}
143+
Operation::AbarToBar(d) => {
144+
let mut attr = TagAttr::default();
145+
attr.addr = globutils::wallet::public_key_to_bech32(
146+
&d.note.get_public_key(),
147+
);
148+
base.1.push(attr);
149+
}
150+
_ => {}
151+
}
152+
153+
base
154+
})
155+
}
156+
157+
fn gen_tendermint_attr_anon(tx: &Transaction) -> (Vec<TagAttr>, Vec<TagAttr>) {
158+
tx.body
159+
.operations
160+
.iter()
161+
.fold((vec![], vec![]), |mut base, op| {
162+
match op {
163+
Operation::BarToAbar(d) => {
164+
let mut attr = TagAttr::default();
165+
attr.addr = globutils::wallet::commitment_to_base58(
166+
&d.output_record().commitment,
167+
);
168+
base.1.push(attr);
169+
}
170+
Operation::AbarToBar(d) => {
171+
let mut attr = TagAttr::default();
172+
attr.addr =
173+
globutils::wallet::nullifier_to_base58(&d.note.get_input());
174+
base.0.push(attr);
175+
}
176+
Operation::TransferAnonAsset(d) => {
177+
for ix in &d.note.body.inputs {
178+
let mut attr = TagAttr::default();
179+
attr.addr = globutils::wallet::nullifier_to_base58(ix);
180+
base.0.push(attr);
181+
}
182+
for ox in &d.note.body.outputs {
183+
let mut attr = TagAttr::default();
184+
attr.addr =
185+
globutils::wallet::commitment_to_base58(&ox.commitment);
186+
base.1.push(attr);
187+
}
188+
}
129189
_ => {}
130190
}
131191

src/components/abciapp/src/abci/staking/test.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ use {
1919
asset_record::{open_blind_asset_record, AssetRecordType},
2020
structs::{AssetRecordTemplate, XfrAmount},
2121
},
22-
{XfrKeyPair, XfrPublicKey},
22+
XfrKeyPair, XfrPublicKey,
2323
},
2424
};
2525

@@ -126,12 +126,12 @@ fn gen_transfer_tx(
126126
&owner_memo.map(|o| o.into_noah()),
127127
&owner_kp.into_noah(),
128128
)
129-
.c(d!())
130-
.and_then(|ob| {
131-
trans_builder
132-
.add_input(TxoRef::Absolute(sid), ob, None, None, i_am)
133-
.c(d!())
134-
})?;
129+
.c(d!())
130+
.and_then(|ob| {
131+
trans_builder
132+
.add_input(TxoRef::Absolute(sid), ob, None, None, i_am)
133+
.c(d!())
134+
})?;
135135

136136
alt!(0 == am, break);
137137
}
@@ -166,5 +166,5 @@ fn gen_transfer_tx(
166166
.c(d!())?;
167167

168168
tx_builder.add_operation(op);
169-
Ok(tx_builder.take_transaction())
169+
tx_builder.build_and_take_transaction()
170170
}

0 commit comments

Comments
 (0)