Skip to content

Commit de83fc2

Browse files
committed
impl: prover, reimpl Withdrawals DB, fix and update crates
1 parent 9ed4667 commit de83fc2

Some content is hidden

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

42 files changed

+802
-1337
lines changed

Cargo.lock

+50-36
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+9-3
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,20 @@ members = [
99
"executor",
1010
"liquidities-db",
1111
"mempool",
12-
"merkle-tree",
12+
"static-merkle-tree",
13+
"dynamic-merkle-tree",
1314
"pools-db",
1415
"poseidon-hash",
1516
"processes",
1617
"proofpool",
1718
"rpc-server",
19+
"prover",
1820
"rollup",
1921
"transactions-db",
2022
"withdrawals-db",
2123
"schnorr-signature",
22-
"proofs-db", "prover-method",
24+
"proofs-db",
25+
"macros",
2326
]
2427

2528
[workspace.dependencies]
@@ -42,18 +45,21 @@ o1-utils = { git = "https://github.com/o1-labs/proof-systems", branch = "master"
4245
# Local dependencies.
4346
nacho-balances-db.path = "balances-db"
4447
nacho-burns-db.path = "burns-db"
48+
nacho-macros.path = "macros"
49+
nacho-static-merkle-tree.path = "static-merkle-tree"
4550
nacho-data-structures.path = "data-structures"
4651
nacho-dynamic-queue.path = "dynamic-queue"
4752
nacho-liquidities-db.path = "liquidities-db"
4853
nacho-dynamic-list.path = "dynamic-list"
4954
nacho-executor.path = "executor"
5055
nacho-mempool.path = "mempool"
51-
nacho-merkle-tree.path = "merkle-tree"
56+
nacho-dynamic-merkle-tree.path = "dynamic-merkle-tree"
5257
nacho-pools-db.path = "pools-db"
5358
nacho-poseidon-hash.path = "poseidon-hash"
5459
nacho-processes.path = "processes"
5560
nacho-proofpool.path = "proofpool"
5661
nacho-proofs-db.path = "proofs-db"
62+
nacho-prover.path = "prover"
5763
nacho-rpc-server.path = "rpc-server"
5864
nacho-schnorr-signature.path = "schnorr-signature"
5965
nacho-withdrawals-db.path = "withdrawals-db"

burns-db/src/burns_db.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,7 @@ mod tests {
346346
.unwrap()
347347
);
348348

349-
let balance = Burn {
349+
let burn = Burn {
350350
burner: Address::from_bytes(
351351
"B62qiiGxLsqNemiKFKiD19JdTHmqbE5YKAkMuXGachSdYkTi8xR2dfY"
352352
.as_bytes()
@@ -357,8 +357,8 @@ mod tests {
357357
token_amount: 250,
358358
};
359359

360-
burns_db.push(&balance).await.unwrap();
361-
burns_db.push_leaf(&balance).await.unwrap();
360+
burns_db.push(&burn).await.unwrap();
361+
burns_db.push_leaf(&burn).await.unwrap();
362362

363363
let root = burns_db.get_root().await.unwrap();
364364

@@ -371,7 +371,7 @@ mod tests {
371371

372372
let updated_burn = Burn {
373373
token_amount: 300,
374-
..balance
374+
..burn
375375
};
376376

377377
burns_db.update(&updated_burn).await.unwrap();

data-structures/src/withdrawal.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@ use crate::{Address, ByteConversion, Field, FieldConversion, U256};
1010
///
1111
#[derive(Clone, Debug, PartialEq, Eq, PartialOrd, Ord)]
1212
pub struct Withdrawal {
13-
withdrawer: Address,
14-
token_id: U256,
15-
token_amount: u64,
13+
pub withdrawer: Address,
14+
pub token_id: U256,
15+
pub token_amount: u64,
1616
}
1717

1818
impl FieldConversion<4> for Withdrawal {

executor/src/deposit_tokens.rs

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
use nacho_data_structures::{Address, Balance, U256};
2+
3+
use crate::Result;
4+
5+
pub fn deposit_tokens(
6+
maybe_balance: Option<&mut Balance>,
7+
amount_to_deposit: u64,
8+
token_id: U256,
9+
user_address: Address,
10+
) -> Result<Option<Balance>> {
11+
match maybe_balance {
12+
Some(balance) => {
13+
balance.token_amount += amount_to_deposit;
14+
Ok(None)
15+
}
16+
None => Ok(Some(Balance {
17+
owner: user_address,
18+
token_id: token_id,
19+
token_amount: amount_to_deposit,
20+
})),
21+
}
22+
}

executor/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
mod burn_tokens;
22
mod buy_tokens;
33
mod create_pool;
4+
mod deposit_tokens;
45
mod error;
56
mod provide_liqudity;
67
mod remove_liquidity;
@@ -9,6 +10,7 @@ mod sell_tokens;
910
pub use burn_tokens::burn_tokens;
1011
pub use buy_tokens::buy_tokens;
1112
pub use create_pool::create_pool;
13+
pub use deposit_tokens::deposit_tokens;
1214
pub use error::ExecutorError;
1315
pub use provide_liqudity::provide_liquidity;
1416
pub use remove_liquidity::remove_liquidity;

liquidities-db/src/liqudities_db.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ mod tests {
405405
.unwrap()
406406
);
407407

408-
let balance = Liquidity {
408+
let liquidity = Liquidity {
409409
provider: Address::from_bytes(
410410
"B62qr1H2QvZVSz7jBEyr91LXFvFTLfHB1W2S9TcMrBiZPHnPQ7yGohY"
411411
.as_bytes()
@@ -417,8 +417,8 @@ mod tests {
417417
points: U256([44; 32]),
418418
};
419419

420-
liquidities_db.push(&balance).await.unwrap();
421-
liquidities_db.push_leaf(&balance).await.unwrap();
420+
liquidities_db.push(&liquidity).await.unwrap();
421+
liquidities_db.push_leaf(&liquidity).await.unwrap();
422422

423423
let root = liquidities_db.get_root().await.unwrap();
424424

@@ -431,7 +431,7 @@ mod tests {
431431

432432
let updated_liquidity = Liquidity {
433433
points: U256([35; 32]),
434-
..balance
434+
..liquidity
435435
};
436436

437437
liquidities_db.update(&updated_liquidity).await.unwrap();

macros/Cargo.toml

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
[package]
2+
name = "nacho-macros"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
[dependencies]

macros/src/calculate_sibling_index.rs

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/// The macro that calculates the sibling index of the given index in a Merkle tree.
2+
///
3+
/// # Examples
4+
///
5+
/// Calculate sibling index of seven:
6+
///
7+
/// ```rs
8+
/// let six = calculate_sibling_index!(7);
9+
/// ```
10+
///
11+
/// Calculate sibling index of six:
12+
///
13+
/// ```rs
14+
/// let seven = calculate_sibling_index!(6);
15+
/// ```
16+
///
17+
#[macro_export]
18+
macro_rules! calculate_sibling_index {
19+
($x:expr) => {{
20+
if $x % 2 == 0 {
21+
$x + 1
22+
} else {
23+
$x - 1
24+
}
25+
}};
26+
}

0 commit comments

Comments
 (0)