mirror of
https://github.com/darkrenaissance/darkfi.git
synced 2026-04-28 03:00:18 -04:00
drk: Use bridgetree instead of incrementalmerkletree.
This commit is contained in:
@@ -38,7 +38,6 @@ use darkfi_sdk::{
|
||||
pedersen_commitment_u64, Keypair, PublicKey, SecretKey, TokenId, DAO_CONTRACT_ID,
|
||||
MONEY_CONTRACT_ID,
|
||||
},
|
||||
incrementalmerkletree::Tree,
|
||||
pasta::pallas,
|
||||
ContractCall,
|
||||
};
|
||||
@@ -178,9 +177,7 @@ impl Drk {
|
||||
|
||||
// Get the Merkle path for the gov coin in the money tree
|
||||
let money_merkle_tree = self.get_money_tree().await?;
|
||||
let root = money_merkle_tree.root(0).unwrap();
|
||||
let gov_coin_merkle_path =
|
||||
money_merkle_tree.authentication_path(gov_coin.leaf_position, &root).unwrap();
|
||||
let gov_coin_merkle_path = money_merkle_tree.witness(gov_coin.leaf_position, 0).unwrap();
|
||||
|
||||
// Fetch the daos Merkle tree
|
||||
let (daos_tree, _) = self.get_dao_trees().await?;
|
||||
@@ -196,7 +193,7 @@ impl Drk {
|
||||
let (dao_merkle_path, dao_merkle_root) = {
|
||||
let root = daos_tree.root(0).unwrap();
|
||||
let leaf_pos = dao.leaf_position.unwrap();
|
||||
let dao_merkle_path = daos_tree.authentication_path(leaf_pos, &root).unwrap();
|
||||
let dao_merkle_path = daos_tree.witness(leaf_pos, 0).unwrap();
|
||||
(dao_merkle_path, root)
|
||||
};
|
||||
|
||||
@@ -290,9 +287,8 @@ impl Drk {
|
||||
let signature_secret = SecretKey::random(&mut OsRng);
|
||||
input_secrets.push(signature_secret);
|
||||
|
||||
let root = money_tree.root(0).unwrap();
|
||||
let leaf_position = coin.leaf_position;
|
||||
let merkle_path = money_tree.authentication_path(coin.leaf_position, &root).unwrap();
|
||||
let merkle_path = money_tree.witness(coin.leaf_position, 0).unwrap();
|
||||
|
||||
let input = DaoVoteInput {
|
||||
secret: coin.secret,
|
||||
@@ -421,7 +417,6 @@ impl Drk {
|
||||
}
|
||||
|
||||
let money_merkle_tree = self.get_money_tree().await?;
|
||||
let money_merkle_root = money_merkle_tree.root(0).unwrap();
|
||||
|
||||
let mut input_value_blind = pallas::Scalar::from(0);
|
||||
for coin in &input_coins {
|
||||
@@ -431,9 +426,7 @@ impl Drk {
|
||||
|
||||
xfer_inputs.push(money_client::TransferInput {
|
||||
leaf_position: coin.leaf_position,
|
||||
merkle_path: money_merkle_tree
|
||||
.authentication_path(coin.leaf_position, &money_merkle_root)
|
||||
.unwrap(),
|
||||
merkle_path: money_merkle_tree.witness(coin.leaf_position, 0).unwrap(),
|
||||
secret: dao.secret_key,
|
||||
note: coin.note.clone(),
|
||||
user_data_blind,
|
||||
|
||||
@@ -44,10 +44,10 @@ use darkfi_dao_contract::{
|
||||
DaoFunction,
|
||||
};
|
||||
use darkfi_sdk::{
|
||||
bridgetree,
|
||||
crypto::{
|
||||
poseidon_hash, MerkleNode, MerkleTree, PublicKey, SecretKey, TokenId, DAO_CONTRACT_ID,
|
||||
},
|
||||
incrementalmerkletree::{Position, Tree},
|
||||
pasta::pallas,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize, SerialDecodable, SerialEncodable};
|
||||
@@ -122,7 +122,7 @@ pub struct Dao {
|
||||
/// DAO bulla blind
|
||||
pub bulla_blind: pallas::Base,
|
||||
/// Leaf position of the DAO in the Merkle tree of DAOs
|
||||
pub leaf_position: Option<Position>,
|
||||
pub leaf_position: Option<bridgetree::Position>,
|
||||
/// The transaction hash where the DAO was deployed
|
||||
pub tx_hash: Option<blake3::Hash>,
|
||||
/// The call index in the transaction where the DAO was deployed
|
||||
@@ -200,7 +200,7 @@ pub struct DaoProposal {
|
||||
/// Proposal's bulla blind
|
||||
pub bulla_blind: pallas::Base,
|
||||
/// Leaf position of this proposal in the Merkle tree of proposals
|
||||
pub leaf_position: Option<Position>,
|
||||
pub leaf_position: Option<bridgetree::Position>,
|
||||
/// Transaction hash where this proposal was proposed
|
||||
pub tx_hash: Option<blake3::Hash>,
|
||||
/// call index in the transaction where this proposal was proposed
|
||||
@@ -1019,7 +1019,7 @@ impl Drk {
|
||||
// have to make sure it's the same for everyone.
|
||||
if confirm {
|
||||
for new_bulla in new_dao_bullas {
|
||||
daos_tree.append(&MerkleNode::from(new_bulla.0.inner()));
|
||||
daos_tree.append(MerkleNode::from(new_bulla.0.inner()));
|
||||
for dao in daos.iter_mut() {
|
||||
if dao.bulla() == new_bulla.0 {
|
||||
eprintln!(
|
||||
@@ -1027,7 +1027,7 @@ impl Drk {
|
||||
new_bulla.0
|
||||
);
|
||||
// We have this DAO imported in our wallet. Add the metadata:
|
||||
dao.leaf_position = daos_tree.witness();
|
||||
dao.leaf_position = daos_tree.mark();
|
||||
dao.tx_hash = new_bulla.1;
|
||||
dao.call_index = Some(new_bulla.2);
|
||||
daos_to_confirm.push(dao.clone());
|
||||
@@ -1036,7 +1036,7 @@ impl Drk {
|
||||
}
|
||||
|
||||
for proposal in new_dao_proposals {
|
||||
proposals_tree.append(&MerkleNode::from(proposal.0.proposal_bulla));
|
||||
proposals_tree.append(MerkleNode::from(proposal.0.proposal_bulla));
|
||||
// FIXME: EncryptedNote2 should perhaps be something generic?
|
||||
let enc_note = EncryptedNote2 {
|
||||
ciphertext: proposal.0.ciphertext,
|
||||
@@ -1062,7 +1062,7 @@ impl Drk {
|
||||
amount: note.proposal.amount,
|
||||
token_id: note.proposal.token_id,
|
||||
bulla_blind: note.proposal.blind,
|
||||
leaf_position: proposals_tree.witness(),
|
||||
leaf_position: proposals_tree.mark(),
|
||||
tx_hash: proposal.1,
|
||||
call_index: Some(proposal.2),
|
||||
vote_id: None,
|
||||
|
||||
@@ -39,12 +39,11 @@ use darkfi_money_contract::{
|
||||
MoneyFunction,
|
||||
};
|
||||
use darkfi_sdk::{
|
||||
bridgetree,
|
||||
crypto::{
|
||||
poseidon_hash, Keypair, MerkleNode, MerkleTree, Nullifier, PublicKey, SecretKey, TokenId,
|
||||
MONEY_CONTRACT_ID,
|
||||
},
|
||||
incrementalmerkletree,
|
||||
incrementalmerkletree::Tree,
|
||||
pasta::pallas,
|
||||
};
|
||||
use darkfi_serial::{deserialize, serialize};
|
||||
@@ -332,7 +331,7 @@ impl Drk {
|
||||
let nullifier: Nullifier = deserialize(&nullifier_bytes)?;
|
||||
|
||||
let leaf_position_bytes: Vec<u8> = serde_json::from_value(row[12].clone())?;
|
||||
let leaf_position: incrementalmerkletree::Position = deserialize(&leaf_position_bytes)?;
|
||||
let leaf_position: bridgetree::Position = deserialize(&leaf_position_bytes)?;
|
||||
|
||||
let memo: Vec<u8> = serde_json::from_value(row[13].clone())?;
|
||||
|
||||
@@ -546,14 +545,14 @@ impl Drk {
|
||||
let coin = output.coin;
|
||||
|
||||
// Append the new coin to the Merkle tree. Every coin has to be added.
|
||||
tree.append(&MerkleNode::from(coin.inner()));
|
||||
tree.append(MerkleNode::from(coin.inner()));
|
||||
|
||||
// Attempt to decrypt the note
|
||||
for secret in secrets.iter().chain(dao_secrets.iter()) {
|
||||
if let Ok(note) = output.note.decrypt::<MoneyNote>(secret) {
|
||||
eprintln!("Successfully decrypted a Money Note");
|
||||
eprintln!("Witnessing coin in Merkle tree");
|
||||
let leaf_position = tree.witness().unwrap();
|
||||
let leaf_position = tree.mark().unwrap();
|
||||
|
||||
let owncoin = OwnCoin {
|
||||
coin,
|
||||
|
||||
Reference in New Issue
Block a user