Skip to content

Commit

Permalink
Merge pull request #356 from dusk-network/release-0.4
Browse files Browse the repository at this point in the history
Release 0.4
  • Loading branch information
vlopes11 authored Aug 13, 2021
2 parents 845d5c2 + 9f24c9f commit 7ddd7de
Show file tree
Hide file tree
Showing 68 changed files with 2,508 additions and 1,055 deletions.
2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,13 @@ members = [
"circuits/blindbid",
"circuits/transfer",
"contracts/bid",
"contracts/stake",
"contracts/transfer",
"macros/code-hasher",
"rusk-profile",
"rusk-abi",
"rusk",
"test-utils/transfer-wrapper",
]
resolver = "2"

Expand Down
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ circuits: keys ## Build and test circuit crates
contracts: ## Execute the test for all contracts
$(MAKE) -C ./contracts test

test: abi circuits macros contracts ## Run the tests
utils: ## Execute the test for utils
$(MAKE) -C ./test-utils test

test: abi circuits macros contracts utils ## Run the tests
$(MAKE) -C ./rusk/ $@

run: wasm ## Run the server
Expand Down
11 changes: 7 additions & 4 deletions circuits/bid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "bid-circuits"
version = "0.1.0"
version = "0.3.0"
authors = ["CPerezz <[email protected]>", "Jules de Smit <[email protected]>"]
edition = "2018"
license = "MPL-2.0"
Expand All @@ -18,10 +18,13 @@ exclude = [
[dependencies]
dusk-plonk = "0.8"
plonk_gadgets = "0.6.0-rc"
dusk-blindbid = "0.8.0-rc"
code-hasher = {path = "../../macros/code-hasher"}
dusk-blindbid = "0.10.0-rc"
code-hasher = { path = "../../macros/code-hasher" }

[dev-dependencies]
rand = "0.8"
phoenix-core = { version = "0.14.0-rc", features = ["canon"] }
dusk-pki = "0.8.0-rc"
rusk-profile = { path = "../../rusk-profile" }

dusk-poseidon = { version = "0.22.0-rc", features = ["std", "canon"] }
lazy_static = "1.4"
125 changes: 86 additions & 39 deletions circuits/bid/src/correctness.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,81 +70,128 @@ impl Circuit for BidCorrectnessCircuit {
mod tests {
use super::*;
use dusk_plonk::jubjub::JubJubAffine;
use lazy_static::lazy_static;
use phoenix_core::Message;

lazy_static! {
static ref PP: PublicParameters = unsafe {
let pp = rusk_profile::get_common_reference_string().unwrap();

PublicParameters::from_slice_unchecked(pp.as_slice())
};
static ref KEYS: (ProverKey, VerifierData) = {
let keys =
rusk_profile::keys_for(&BidCorrectnessCircuit::CIRCUIT_ID)
.unwrap();

(
ProverKey::from_slice(&keys.get_prover().unwrap()).unwrap(),
VerifierData::from_slice(&keys.get_verifier().unwrap())
.unwrap(),
)
};
}

#[test]
fn test_correctness_circuit() -> Result<(), Error> {
let value = JubJubScalar::from(100000 as u64);
let blinder = JubJubScalar::from(50000 as u64);
let value = JubJubScalar::from(100000_u64);
let blinder = JubJubScalar::from(50000_u64);
let commitment = JubJubAffine::from(
(GENERATOR_EXTENDED * value) + (GENERATOR_NUMS_EXTENDED * blinder),
);

let mut circuit = BidCorrectnessCircuit {
commitment: commitment,
value: value,
blinder: blinder,
};

// Generate Composer & Public Parameters
let pub_params = unsafe {
PublicParameters::from_slice_unchecked(
rusk_profile::get_common_reference_string()
.expect("Failed to fetch CRS from rusk_profile")
.as_slice(),
)
commitment,
value,
blinder,
};

let (pk, vd) = circuit.compile(&pub_params)?;

let proof = circuit.gen_proof(&pub_params, &pk, b"BidCorrectness")?;
let proof = circuit.gen_proof(&PP, &KEYS.0, b"BidCorrectness")?;
let pi = vec![commitment.into()];
circuit::verify_proof(
&pub_params,
&vd.key(),
&PP,
KEYS.1.key(),
&proof,
&pi,
&vd.pi_pos(),
KEYS.1.pi_pos(),
b"BidCorrectness",
)?;
Ok(())
}

#[test]
fn test_correctness_circuit_out_of_bounds() -> Result<(), Error> {
let value = JubJubScalar::from(100 as u64);
let blinder = JubJubScalar::from(50000 as u64);
let value = JubJubScalar::from(100_u64);
let blinder = JubJubScalar::from(50000_u64);
let commitment = JubJubAffine::from(
(GENERATOR_EXTENDED * value) + (GENERATOR_NUMS_EXTENDED * blinder),
);

let mut circuit = BidCorrectnessCircuit {
commitment: commitment,
value: value,
blinder: blinder,
};

// Generate Composer & Public Parameters
let pub_params = unsafe {
PublicParameters::from_slice_unchecked(
rusk_profile::get_common_reference_string()
.expect("Failed to fetch CRS from rusk_profile")
.as_slice(),
)
commitment,
value,
blinder,
};

let (pk, vd) = circuit.compile(&pub_params)?;
let proof = circuit.gen_proof(&pub_params, &pk, b"BidCorrectness")?;
let proof = circuit.gen_proof(&PP, &KEYS.0, b"BidCorrectness")?;

let pi = vec![commitment.into()];
assert!(circuit::verify_proof(
&pub_params,
&vd.key(),
&PP,
KEYS.1.key(),
&proof,
&pi,
&vd.pi_pos(),
KEYS.1.pi_pos(),
b"BidCorrectness",
)
.is_err());
Ok(())
}

#[test]
fn test_correctness_with_message() -> Result<(), Error> {
use dusk_blindbid::Bid;
use dusk_pki::{PublicSpendKey, SecretSpendKey};
use dusk_poseidon::sponge;
use rand::Rng;

let mut rng = rand::thread_rng();
let secret = JubJubScalar::random(&mut rand::thread_rng());
let secret_k = BlsScalar::random(&mut rand::thread_rng());
let psk = PublicSpendKey::from(SecretSpendKey::random(
&mut rand::thread_rng(),
));
let value: u64 =
(&mut rand::thread_rng()).gen_range(V_RAW_MIN..V_RAW_MAX);

let r = JubJubScalar::random(&mut rand::thread_rng());
let bid = Bid::new(
Message::new(&mut rng, &r, &psk, value),
sponge::sponge::sponge_hash(&[secret_k]),
psk.gen_stealth_address(&secret),
u64::MAX,
u64::MAX,
);

let (value, blinder) =
bid.decrypt_data(&r, &psk).expect("decryption error");

let mut circuit = BidCorrectnessCircuit {
commitment: JubJubAffine::from(bid.commitment()),
value,
blinder,
};

let proof = circuit.gen_proof(&PP, &KEYS.0, b"BidCorrectness")?;
let pi = vec![JubJubAffine::from(bid.commitment()).into()];
circuit::verify_proof(
&PP,
KEYS.1.key(),
&proof,
&pi,
KEYS.1.pi_pos(),
b"BidCorrectness",
)?;
Ok(())
}
}
11 changes: 11 additions & 0 deletions circuits/blindbid/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,26 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## Unreleased

## [0.2.0] - 2021-07-15

### Added

- Add `phoenix-core-0.13.0-rc` to dev-deps [#327]

### Changed

- Change CIRCUIT_ID to use `code-hasher` to generate it [#284]
- Update `dusk-plonk` to `0.22.0-rc` [#327]
- Update `dusk-pki` to `0.8.0-rc` [#327]
- Update `dusk-blindbid` to `0.10.0-rc` [#327]
- Update `microkelvin` to `0.10.0-rc` [#327]

## [0.1.0] - 2021-05-05

### Added
- Add `blindbid-circuits` as workspace member [#274]

[#327]: https://github.com/dusk-network/rusk/issues/327
[#284]: https://github.com/dusk-network/rusk/issues/284
[#274]: https://github.com/dusk-network/rusk/issues/274
[0.1.0]: https://github.com/dusk-network/rusk/releases/tag/blindbid-circuits-0.1.0
13 changes: 7 additions & 6 deletions circuits/blindbid/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "blindbid-circuits"
version = "0.1.0"
version = "0.2.0"
authors = ["CPerezz <[email protected]>"]
edition = "2018"
license = "MPL-2.0"
Expand All @@ -20,15 +20,16 @@ exclude = [
dusk-plonk = {version = "0.8", default-features = false, features = ["std"]}
plonk_gadgets = {version = "0.6.0-rc", features = ["std"]}
code-hasher = {path = "../../macros/code-hasher"}
dusk-blindbid = "0.8.0-rc"
dusk-poseidon = {version = "0.21.0-rc", features = ["std", "canon"] }
dusk-pki = "0.7.0-rc"
dusk-blindbid = "0.10.0-rc"
dusk-poseidon = {version = "0.22.0-rc", features = ["std", "canon"] }
dusk-pki = "0.8.0-rc"
dusk-bytes = "0.1"


[dev-dependencies]
microkelvin = "0.7"
microkelvin = "0.10.0-rc"
rand = "0.8"
canonical_derive = "0.6"
canonical = "0.6"
rusk-profile = { path = "../../rusk-profile" }

phoenix-core = { version = "0.14.0-rc", features = ["canon"] }
Loading

0 comments on commit 7ddd7de

Please sign in to comment.