Skip to content

Commit

Permalink
feat:add deposit
Browse files Browse the repository at this point in the history
  • Loading branch information
Nickqiaoo committed Dec 19, 2023
1 parent 7bbeba1 commit 3995e4f
Show file tree
Hide file tree
Showing 13 changed files with 99 additions and 434 deletions.
4 changes: 3 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,6 @@ ecies = "0.2.6"
halo2_proofs = "0.3.0"
plotters = { version = "0.3.0", default-features = true, optional = true }
pasta_curves = "0.5"
orchard = "0.6.0"
orchard = "0.6.0"
bridgetree = "0.4"
lazy_static = "1.4"
172 changes: 0 additions & 172 deletions src/circuit.rs

This file was deleted.

77 changes: 0 additions & 77 deletions src/coin.rs

This file was deleted.

20 changes: 3 additions & 17 deletions src/deposit.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::{wallets::Wallets};
use crate::{wallets::Wallets, merkle,};
use rand::rngs::OsRng;
use orchard::{
builder::Builder,
Expand Down Expand Up @@ -27,11 +27,11 @@ pub fn deposit(address: String, value: u64) -> Bundle<Authorized, i64> {
// Create a shielding bundle.
let shielding_bundle: Bundle<_, i64> = {
// Use the empty tree.
let anchor = MerkleHashOrchard::empty_root(32.into()).into();
let anchor = merkle::MERKLE.root(0).unwrap().into();

let mut builder = Builder::new(Flags::from_parts(false, true), anchor);
assert_eq!(
builder.add_recipient(None, recipient, NoteValue::from_raw(5000), None),
builder.add_recipient(None, recipient, NoteValue::from_raw(value), None),
Ok(())
);
let unauthorized = builder.build(&mut rng).unwrap();
Expand All @@ -40,18 +40,4 @@ pub fn deposit(address: String, value: u64) -> Bundle<Authorized, i64> {
proven.apply_signatures(rng, sighash, &[]).unwrap()
};
shielding_bundle
}

pub fn verify_bundle(bundle: &Bundle<Authorized, i64>) {
let vk = VerifyingKey::build();
assert!(matches!(bundle.verify_proof(&vk), Ok(())));
let sighash: [u8; 32] = bundle.commitment().into();
let bvk = bundle.binding_validating_key();
for action in bundle.actions() {
assert_eq!(action.rk().verify(&sighash, action.authorization()), Ok(()));
}
assert_eq!(
bvk.verify(&sighash, bundle.authorization().binding_signature()),
Ok(())
);
}
5 changes: 1 addition & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,16 @@ use structopt::StructOpt;

mod block;
mod blockchain;
mod circuit;
mod cli;
mod coin;
mod iterator;
mod mint;
mod pour;
mod pow;
mod transaction;
mod transaction_input;
mod transaction_output;
mod wallet;
mod wallets;
mod deposit;
mod merkle;
mod transfer;

fn main() {
Expand Down
7 changes: 7 additions & 0 deletions src/merkle.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
use bridgetree::BridgeTree;
use orchard::tree::{MerkleHashOrchard, MerklePath};
use lazy_static::lazy_static;

lazy_static! {
pub static ref MERKLE:BridgeTree::<MerkleHashOrchard, u32, 32> = BridgeTree::<MerkleHashOrchard, u32, 32>::new(100);
}
37 changes: 0 additions & 37 deletions src/mint.rs

This file was deleted.

Loading

0 comments on commit 3995e4f

Please sign in to comment.