diff --git a/src/blockchain/mempool.rs b/src/blockchain/mempool.rs index a54a8de5..3b1b1465 100644 --- a/src/blockchain/mempool.rs +++ b/src/blockchain/mempool.rs @@ -19,7 +19,7 @@ impl Nonced for MpnTransaction { impl Nonced for MpnWithdraw { fn nonce(&self) -> u32 { - self.zk_nonce + self.mpn_withdraw_nonce } } diff --git a/src/client/explorer.rs b/src/client/explorer.rs index b0fe22b9..a9097cde 100644 --- a/src/client/explorer.rs +++ b/src/client/explorer.rs @@ -506,14 +506,14 @@ impl From<&(Address, Amount)> for ExplorerStaker { #[derive(Deserialize, Serialize, Debug, Clone)] pub struct ExplorerMpnDeposit { - pub zk_address: String, + pub mpn_address: String, pub payment: ExplorerContractDeposit, } impl From<&MpnDeposit> for ExplorerMpnDeposit { fn from(obj: &MpnDeposit) -> Self { Self { - zk_address: obj.zk_address.to_string(), + mpn_address: obj.mpn_address.to_string(), payment: (&obj.payment).into(), } } @@ -521,18 +521,18 @@ impl From<&MpnDeposit> for ExplorerMpnDeposit { #[derive(Deserialize, Serialize, Debug, Clone)] pub struct ExplorerMpnWithdraw { - pub zk_address: String, - pub zk_nonce: u32, - pub zk_sig: String, + pub mpn_address: String, + pub mpn_withdraw_nonce: u32, + pub mpn_sig: String, pub payment: ExplorerContractWithdraw, } impl From<&MpnWithdraw> for ExplorerMpnWithdraw { fn from(obj: &MpnWithdraw) -> Self { Self { - zk_address: obj.zk_address.to_string(), - zk_nonce: obj.zk_nonce, - zk_sig: "".into(), // TODO: Convert sig to hex + mpn_address: obj.mpn_address.to_string(), + mpn_withdraw_nonce: obj.mpn_withdraw_nonce, + mpn_sig: "".into(), // TODO: Convert sig to hex payment: (&obj.payment).into(), } } diff --git a/src/core/mod.rs b/src/core/mod.rs index a7a4d63b..c0108c84 100644 --- a/src/core/mod.rs +++ b/src/core/mod.rs @@ -156,7 +156,7 @@ impl GeneralTransaction { pub_key: mpn_tx.src_pub_key.clone(), }), GeneralTransaction::MpnWithdraw(mpn_withdraw) => NonceGroup::MpnWithdraw(MpnAddress { - pub_key: mpn_withdraw.zk_address.clone(), + pub_key: mpn_withdraw.mpn_address.clone(), }), } } @@ -175,7 +175,7 @@ impl GeneralTransaction { GeneralTransaction::TransactionAndDelta(tx_delta) => tx_delta.tx.nonce, GeneralTransaction::MpnDeposit(mpn_deposit) => mpn_deposit.payment.nonce, GeneralTransaction::MpnTransaction(mpn_tx) => mpn_tx.nonce, - GeneralTransaction::MpnWithdraw(mpn_withdraw) => mpn_withdraw.zk_nonce, + GeneralTransaction::MpnWithdraw(mpn_withdraw) => mpn_withdraw.mpn_withdraw_nonce, } } pub fn fee(&self) -> Money { @@ -199,7 +199,7 @@ impl GeneralTransaction { }), GeneralTransaction::MpnWithdraw(mpn_withdraw) => { GeneralAddress::MpnAddress(MpnAddress { - pub_key: mpn_withdraw.zk_address.clone(), + pub_key: mpn_withdraw.mpn_address.clone(), }) } } diff --git a/src/core/transaction.rs b/src/core/transaction.rs index ff24a09c..0f1650b3 100644 --- a/src/core/transaction.rs +++ b/src/core/transaction.rs @@ -203,31 +203,31 @@ pub struct ContractWithdraw { #[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)] pub struct MpnDeposit { - pub zk_address: ZS::Pub, + pub mpn_address: ZS::Pub, pub payment: ContractDeposit, } #[derive(serde::Serialize, serde::Deserialize, Clone, Debug, Default)] pub struct MpnWithdraw { - pub zk_address: ZS::Pub, - pub zk_nonce: u32, - pub zk_sig: ZS::Sig, + pub mpn_address: ZS::Pub, + pub mpn_withdraw_nonce: u32, + pub mpn_sig: ZS::Sig, pub payment: ContractWithdraw, } impl MpnWithdraw { pub fn verify_calldata(&self) -> bool { - let mut preimage: Vec = self.zk_address.clone().into(); - preimage.push((self.zk_nonce as u64).into()); - preimage.extend(&self.zk_sig.clone().into()); + let mut preimage: Vec = self.mpn_address.clone().into(); + preimage.push((self.mpn_withdraw_nonce as u64).into()); + preimage.extend(&self.mpn_sig.clone().into()); self.payment.calldata == ZH::hash(&preimage) } pub fn verify_signature(&self) -> bool { let msg = ZH::hash(&[ self.payment.fingerprint(), - ZkScalar::from(self.zk_nonce as u64), + ZkScalar::from(self.mpn_withdraw_nonce as u64), ]); - ZS::verify(&self.zk_address, msg, &self.zk_sig) + ZS::verify(&self.mpn_address, msg, &self.mpn_sig) } } diff --git a/src/mpn/circuits/deposit_circuit.rs b/src/mpn/circuits/deposit_circuit.rs index 0170185b..9a8770f3 100644 --- a/src/mpn/circuits/deposit_circuit.rs +++ b/src/mpn/circuits/deposit_circuit.rs @@ -99,7 +99,7 @@ impl Circuit for DepositCircuit { // Pub-key only needs to reside on curve if tx is enabled, which is checked in the main loop let pub_key = - AllocatedPoint::alloc(&mut *cs, || Ok(trans.tx.zk_address.0.decompress()))?; + AllocatedPoint::alloc(&mut *cs, || Ok(trans.tx.mpn_address.0.decompress()))?; tx_wits.push(( Boolean::Is(enabled.clone()), diff --git a/src/mpn/circuits/withdraw_circuit.rs b/src/mpn/circuits/withdraw_circuit.rs index 4848f398..d15048c1 100644 --- a/src/mpn/circuits/withdraw_circuit.rs +++ b/src/mpn/circuits/withdraw_circuit.rs @@ -120,10 +120,11 @@ impl Circuit for WithdrawCircuit { // Pub-key only needs to reside on curve if tx is enabled, which is checked in the main loop let pub_key = - AllocatedPoint::alloc(&mut *cs, || Ok(trans.tx.zk_address.0.decompress()))?; - let nonce = AllocatedNum::alloc(&mut *cs, || Ok((trans.tx.zk_nonce as u64).into()))?; - let sig_r = AllocatedPoint::alloc(&mut *cs, || Ok(trans.tx.zk_sig.r))?; - let sig_s = AllocatedNum::alloc(&mut *cs, || Ok(trans.tx.zk_sig.s.into()))?; + AllocatedPoint::alloc(&mut *cs, || Ok(trans.tx.mpn_address.0.decompress()))?; + let nonce = + AllocatedNum::alloc(&mut *cs, || Ok((trans.tx.mpn_withdraw_nonce as u64).into()))?; + let sig_r = AllocatedPoint::alloc(&mut *cs, || Ok(trans.tx.mpn_sig.r))?; + let sig_s = AllocatedNum::alloc(&mut *cs, || Ok(trans.tx.mpn_sig.s.into()))?; tx_wits.push(( Boolean::Is(enabled.clone()), diff --git a/src/mpn/deposit.rs b/src/mpn/deposit.rs index 0300d08f..05aa5621 100644 --- a/src/mpn/deposit.rs +++ b/src/mpn/deposit.rs @@ -38,7 +38,7 @@ pub fn deposit>( } let mpn_addr = MpnAddress { - pub_key: tx.zk_address.clone(), + pub_key: tx.mpn_address.clone(), }; let mut new_index = None; let account_index = if let Some(ind) = db.get_mpn_account_indices(mpn_addr.clone())?.first() @@ -75,7 +75,7 @@ pub fn deposit>( let mut isolated = mirror.mirror(); let mut isolated_state_size = state_size; if rejected_pub_keys.contains(&src_pub) - || (acc.address != Default::default() && tx.zk_address.0.decompress() != acc.address) + || (acc.address != Default::default() && tx.mpn_address.0.decompress() != acc.address) || (acc_token.is_some() && acc_token.unwrap().token_id != tx.payment.amount.token_id) { rejected.push(tx.clone()); @@ -107,7 +107,7 @@ pub fn deposit>( } let mut updated_acc = MpnAccount { - address: tx.zk_address.0.decompress(), + address: tx.mpn_address.0.decompress(), tokens: acc.tokens.clone(), withdraw_nonce: acc.withdraw_nonce, tx_nonce: acc.tx_nonce, @@ -191,8 +191,8 @@ pub fn deposit>( for (i, trans) in transitions.iter().enumerate() { use crate::zk::ZkHasher; let calldata = crate::core::ZkHasher::hash(&[ - ZkScalar::from(trans.tx.zk_address.0.decompress().0), - ZkScalar::from(trans.tx.zk_address.0.decompress().1), + ZkScalar::from(trans.tx.mpn_address.0.decompress().0), + ZkScalar::from(trans.tx.mpn_address.0.decompress().1), ]); state_builder .batch_set(&ZkDeltaPairs( diff --git a/src/mpn/withdraw.rs b/src/mpn/withdraw.rs index 081e19cf..8617e429 100644 --- a/src/mpn/withdraw.rs +++ b/src/mpn/withdraw.rs @@ -33,7 +33,7 @@ pub fn withdraw>( } let mpn_addr = MpnAddress { - pub_key: tx.zk_address.clone(), + pub_key: tx.mpn_address.clone(), }; let account_index = if let Some(ind) = db.get_mpn_account_indices(mpn_addr.clone())?.first() { @@ -73,10 +73,10 @@ pub fn withdraw>( let mut isolated = mirror.mirror(); let mut isolated_state_size = state_size; - if (acc.address != Default::default() && tx.zk_address.0.decompress() != acc.address) + if (acc.address != Default::default() && tx.mpn_address.0.decompress() != acc.address) || !tx.verify_calldata::() || !tx.verify_signature::() - || tx.zk_nonce != acc.withdraw_nonce + 1 + || tx.mpn_withdraw_nonce != acc.withdraw_nonce + 1 || tx.payment.amount.token_id != acc_token.token_id || tx.payment.amount.amount > acc_token.amount { @@ -84,7 +84,7 @@ pub fn withdraw>( continue; } else { let mut updated_acc = MpnAccount { - address: tx.zk_address.0.decompress(), + address: tx.mpn_address.0.decompress(), tokens: acc.tokens.clone(), tx_nonce: acc.tx_nonce, withdraw_nonce: acc.withdraw_nonce + 1, @@ -205,12 +205,12 @@ pub fn withdraw>( for (i, trans) in transitions.iter().enumerate() { use crate::zk::ZkHasher; let calldata = crate::core::ZkHasher::hash(&[ - ZkScalar::from(trans.tx.zk_address.0.decompress().0), - ZkScalar::from(trans.tx.zk_address.0.decompress().1), - ZkScalar::from(trans.tx.zk_nonce as u64), - ZkScalar::from(trans.tx.zk_sig.r.0), - ZkScalar::from(trans.tx.zk_sig.r.1), - ZkScalar::from(trans.tx.zk_sig.s), + ZkScalar::from(trans.tx.mpn_address.0.decompress().0), + ZkScalar::from(trans.tx.mpn_address.0.decompress().1), + ZkScalar::from(trans.tx.mpn_withdraw_nonce as u64), + ZkScalar::from(trans.tx.mpn_sig.r.0), + ZkScalar::from(trans.tx.mpn_sig.r.1), + ZkScalar::from(trans.tx.mpn_sig.s), ]); state_builder .batch_set(&ZkDeltaPairs( diff --git a/src/wallet/tx_builder.rs b/src/wallet/tx_builder.rs index 3742e634..918e2c72 100644 --- a/src/wallet/tx_builder.rs +++ b/src/wallet/tx_builder.rs @@ -21,7 +21,7 @@ pub struct TxBuilder { private_key: ::Priv, zk_private_key: ::Priv, address: Address, - zk_address: ::Pub, + mpn_address: ::Pub, } impl TxBuilder { @@ -33,7 +33,7 @@ impl TxBuilder { let (vrf_public_key, vrf_private_key) = Vrf::generate_keys(&mut chacha_rng); Self { address: pk, - zk_address: zk_pk, + mpn_address: zk_pk, private_key: sk, zk_private_key: zk_sk, vrf_public_key, @@ -50,7 +50,7 @@ impl TxBuilder { self.vrf_public_key.clone() } pub fn get_zk_address(&self) -> ::Pub { - self.zk_address.clone() + self.mpn_address.clone() } pub fn get_mpn_address(&self) -> MpnAddress { MpnAddress { @@ -353,7 +353,7 @@ impl TxBuilder { }; self.sign_deposit(&mut tx); MpnDeposit { - zk_address: to.pub_key, + mpn_address: to.pub_key, payment: tx, } } @@ -402,9 +402,9 @@ impl TxBuilder { .unwrap(); tx.calldata = calldata_builder.compress().unwrap().state_hash; MpnWithdraw { - zk_address: self.get_zk_address(), - zk_nonce: nonce, - zk_sig: sig, + mpn_address: self.get_zk_address(), + mpn_withdraw_nonce: nonce, + mpn_sig: sig, payment: tx, } }