Skip to content

Commit

Permalink
Merge pull request #17 from matter-labs/final_janitor_fixes
Browse files Browse the repository at this point in the history
Move src/ to core/, add logging
  • Loading branch information
dvush authored Jun 25, 2019
2 parents d489f0d + 2a8d20d commit 6099358
Show file tree
Hide file tree
Showing 105 changed files with 510 additions and 339 deletions.
103 changes: 103 additions & 0 deletions Cargo.lock

Large diffs are not rendered by default.

22 changes: 11 additions & 11 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
[workspace]
members = [
"src/data_restore",
"src/key_generator",
"src/merkle_tree",
"src/eth_client",
"src/models",
"src/plasma",
"src/prover",
"src/sandbox",
"src/server",
"src/storage",
"src/circuit",
"core/data_restore",
"core/key_generator",
"core/merkle_tree",
"core/eth_client",
"core/models",
"core/plasma",
"core/prover",
"core/sandbox",
"core/server",
"core/storage",
"core/circuit",
]
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ db-reset: confirm_action db-drop db-setup db-insert-contract
@echo database is ready

db-migrate: confirm_action
@cd src/storage && diesel migration run
@cd core/storage && diesel migration run

db-drop: confirm_action
@# this is used to clear the produciton db; cannot do `diesel database reset` because we don't own the db
Expand Down Expand Up @@ -299,4 +299,4 @@ tesseracts-up:
@docker-compose up -d tesseracts

tesseracts-down:
@docker-compose stop tesseracts
@docker-compose stop tesseracts
6 changes: 3 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ Client UI will be available at http://localhost:8080

## Database migrations

- ```cd src/storage```
- ```cd core/storage```
- Add diesel migration
- Rename `src/storage/schema.rs.generated` to `schema.rs`
- Rename `core/storage/schema.rs.generated` to `schema.rs`
- Run tests: ```franklin db-tests```

## Generating keys
Expand Down Expand Up @@ -129,4 +129,4 @@ So you need to rebuild the code on every change (to be automated).

```
franklin flatten source
```
```
2 changes: 1 addition & 1 deletion bin/db-setup
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# Force read env
FRANKLIN_ENV=
. .setup_env
cd src/storage
cd core/storage

echo DATABASE_URL=$DATABASE_URL
diesel database setup || exit 1
Expand Down
2 changes: 1 addition & 1 deletion bin/db-test
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/bin/bash

. .setup_env
cd src/storage
cd core/storage

export DATABASE_URL=postgres://postgres@localhost/plasma_test

Expand Down
3 changes: 3 additions & 0 deletions src/circuit/Cargo.toml → core/circuit/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,6 @@ ff = { package = "ff_ce", version = "0.6.0", features = ["derive"] }
rand = "0.4"
rust-crypto = "0.2"
hex = "0.3.2"

[dev-dependencies]
log = "0.4"
Original file line number Diff line number Diff line change
Expand Up @@ -456,9 +456,10 @@ impl<'a, E: JubjubEngine> Circuit<E> for BitSet<'a, E> {

#[cfg(test)]
mod test {

use super::*;

use log::{debug, error};

use bellman::groth16::{
create_random_proof, generate_random_parameters, prepare_verifying_key, verify_proof,
};
Expand Down Expand Up @@ -514,21 +515,21 @@ mod test {

instance.synthesize(&mut cs).expect("must synthesize");

println!("{}", cs.find_unconstrained());
debug!("{}", cs.find_unconstrained());

println!("{}", cs.num_constraints());
debug!("{}", cs.num_constraints());

assert_eq!(cs.num_inputs(), 1);

let err = cs.which_is_unsatisfied();
if err.is_some() {
println!(
error!(
"Error for bitfield = {:#b}, bit of interest = {}",
existing_field, bit_of_interest
);
panic!("ERROR satisfying in {}", err.unwrap());
} else {
println!("Satisfied for bit = {}", bit_of_interest);
debug!("Satisfied for bit = {}", bit_of_interest);
}
}
}
Expand Down Expand Up @@ -668,7 +669,7 @@ mod test {
for i in 0..=max_with_shift {
let x = Fr::from_str(&i.to_string()).unwrap();
let val = evaluate_at_x::<Bn256>(&interpolation[..], &x);
println!("X = {}, Y = {}", x, val);
debug!("X = {}, Y = {}", x, val);
}
}

Expand All @@ -684,7 +685,7 @@ mod test {
for i in 0..=max_with_shift {
let x = Fr::from_str(&i.to_string()).unwrap();
let val = evaluate_at_x::<Bn256>(&interpolation[..], &x);
println!("X = {}, Y = {}", x, val);
debug!("X = {}, Y = {}", x, val);
}
}

Expand All @@ -700,7 +701,7 @@ mod test {
for i in 0..=full_range {
let x = Fr::from_str(&i.to_string()).unwrap();
let val = evaluate_at_x::<Bn256>(&interpolation[..], &x);
println!("X = {}, Y = {}", x, val);
debug!("X = {}, Y = {}", x, val);
}
}
}
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -519,8 +519,10 @@ where

#[cfg(test)]
mod test {

use super::*;

use log::debug;

use ff::PrimeFieldRepr;
use sapling_crypto::jubjub::FixedGenerators;

Expand Down Expand Up @@ -550,15 +552,15 @@ mod test {
let tree_depth = plasma_constants::BALANCE_TREE_DEPTH as u32;
let mut tree = CircuitAccountTree::new(tree_depth);
let initial_root = tree.root_hash();
println!("Initial root = {}", initial_root);
debug!("Initial root = {}", initial_root);

let capacity = tree.capacity();
assert_eq!(capacity, 1 << plasma_constants::BALANCE_TREE_DEPTH);

let sender_sk = PrivateKey::<Bn256>(rng.gen());
let sender_pk = PublicKey::from_private(&sender_sk, p_g, params);
let (sender_x, sender_y) = sender_pk.0.into_xy();
println!("x = {}, y = {}", sender_x, sender_y);
debug!("x = {}, y = {}", sender_x, sender_y);

// give some funds to sender and make zero balance for recipient

Expand All @@ -580,7 +582,7 @@ mod test {

tree.insert(sender_leaf_number, sender_leaf.clone());

println!(
debug!(
"Sender leaf hash is {}",
tree.get_hash((tree_depth, sender_leaf_number))
);
Expand Down Expand Up @@ -618,14 +620,14 @@ mod test {

let new_root = tree.root_hash();

println!("New root = {}", new_root);
debug!("New root = {}", new_root);

assert!(initial_root != new_root);
assert_ne!(initial_root, new_root);

{
let mut cs = TestConstraintSystem::<Bn256>::new();

let mut public_data_initial_bits = vec![];
let mut public_data_initial_bits = Vec::new();

// these two are BE encodings because an iterator is BE. This is also an Ethereum standard behavior

Expand All @@ -646,7 +648,7 @@ mod test {
let mut hash_result = [0u8; 32];
h.result(&mut hash_result[..]);

println!("Initial hash hex {}", hex::encode(hash_result));
debug!("Initial hash hex {}", hex::encode(hash_result));

let mut packed_transaction_data = vec![];
let transaction_data = request.public_data_into_bits();
Expand All @@ -656,7 +658,7 @@ mod test {

let packed_transaction_data_bytes = be_bit_vector_into_bytes(&packed_transaction_data);

println!(
debug!(
"Packed transaction data hex {}",
hex::encode(packed_transaction_data_bytes.clone())
);
Expand All @@ -670,7 +672,7 @@ mod test {
hash_result = [0u8; 32];
h.result(&mut hash_result[..]);

println!("Final hash as hex {}", hex::encode(hash_result));
debug!("Final hash as hex {}", hex::encode(hash_result));

hash_result[0] &= 0x1f; // temporary solution

Expand All @@ -680,7 +682,7 @@ mod test {

let public_data_commitment = Fr::from_repr(repr).unwrap();

println!(
debug!(
"Final data commitment as field element = {}",
public_data_commitment
);
Expand All @@ -697,9 +699,9 @@ mod test {

instance.synthesize(&mut cs).unwrap();

println!("{}", cs.find_unconstrained());
debug!("{}", cs.find_unconstrained());

println!("{}", cs.num_constraints());
debug!("{}", cs.num_constraints());

assert_eq!(cs.num_inputs(), 4);

Expand Down Expand Up @@ -761,15 +763,15 @@ mod test {

tree.insert(sender_leaf_number, sender_leaf.clone());

println!(
debug!(
"Sender leaf hash is {}",
tree.get_hash((tree_depth, sender_leaf_number))
);

//assert!(tree.verify_proof(sender_leaf_number, sender_leaf.clone(), tree.merkle_path(sender_leaf_number)));

let initial_root = tree.root_hash();
println!("Initial root = {}", initial_root);
debug!("Initial root = {}", initial_root);

let mut double_the_amount = transfer_amount_as_field_element;
double_the_amount.double();
Expand Down Expand Up @@ -814,7 +816,7 @@ mod test {

let new_root = tree.root_hash();

println!("New root = {}", new_root);
debug!("New root = {}", new_root);

assert!(initial_root != new_root);

Expand Down Expand Up @@ -842,7 +844,7 @@ mod test {
let mut hash_result = [0u8; 32];
h.result(&mut hash_result[..]);

println!("Initial hash hex {}", hex::encode(hash_result));
debug!("Initial hash hex {}", hex::encode(hash_result));

let mut packed_transaction_data = vec![];
let transaction_data = request.public_data_into_bits();
Expand All @@ -852,7 +854,7 @@ mod test {

let packed_transaction_data_bytes = be_bit_vector_into_bytes(&packed_transaction_data);

println!(
debug!(
"Packed transaction data hex {}",
hex::encode(packed_transaction_data_bytes.clone())
);
Expand All @@ -866,7 +868,7 @@ mod test {
hash_result = [0u8; 32];
h.result(&mut hash_result[..]);

println!("Final hash as hex {}", hex::encode(hash_result));
debug!("Final hash as hex {}", hex::encode(hash_result));

hash_result[0] &= 0x1f; // temporary solution

Expand All @@ -876,7 +878,7 @@ mod test {

let public_data_commitment = Fr::from_repr(repr).unwrap();

println!(
debug!(
"Final data commitment as field element = {}",
public_data_commitment
);
Expand All @@ -893,9 +895,9 @@ mod test {

instance.synthesize(&mut cs).unwrap();

println!("{}", cs.find_unconstrained());
debug!("{}", cs.find_unconstrained());

println!("{}", cs.num_constraints());
debug!("{}", cs.num_constraints());

assert_eq!(cs.num_inputs(), 4);

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
Loading

0 comments on commit 6099358

Please sign in to comment.