Skip to content

Commit

Permalink
Merge pull request #237 from dusk-network/mocello/fix_232
Browse files Browse the repository at this point in the history
circuit: Fixes for #232
  • Loading branch information
moCello authored Aug 9, 2024
2 parents 47ceb25 + ccada7e commit 5694c99
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 10 deletions.
2 changes: 2 additions & 0 deletions circuits/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Add `Serializable` trait implementation for `OutputNoteInfo` [#232]
- Add `Clone` and `PartialEq` derives for `TxCircuit` [#232]
- Add `PartialEq` derive for `InputNoteInfo` [#232]
- Add associated const `TxCircuit::SIZE`
- Add associated const `InputNoteInfo::SIZE`
- Add `PartialEq` derive for `OutputNoteInfo` [#232]
- Add `dusk-bls12_381` dependency [#235]
- Add `"plonk"` feature to add the `dusk-plonk` dependency [#235]
Expand Down
11 changes: 7 additions & 4 deletions circuits/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,8 @@ pub struct TxCircuit<const H: usize, const I: usize> {
}

impl<const H: usize, const I: usize> TxCircuit<H, I> {
const SIZE: usize = I * InputNoteInfo::<H>::SIZE
/// The size of a `TxCircuit`.
pub const SIZE: usize = I * InputNoteInfo::<H>::SIZE
+ OUTPUT_NOTES * OutputNoteInfo::SIZE
+ 2 * BlsScalar::SIZE
+ 2 * u64::SIZE
Expand Down Expand Up @@ -102,8 +103,9 @@ impl<const H: usize, const I: usize> TxCircuit<H, I> {
}

let mut input_notes_info = Vec::new();
for _ in 0..I {
input_notes_info.push(InputNoteInfo::from_slice(bytes)?);
for i in 0..I {
let start = i * InputNoteInfo::<H>::SIZE;
input_notes_info.push(InputNoteInfo::from_slice(&bytes[start..])?);
}

let mut reader = &bytes[I * InputNoteInfo::<H>::SIZE..];
Expand Down Expand Up @@ -217,7 +219,8 @@ pub struct InputNoteInfo<const H: usize> {
}

impl<const H: usize> InputNoteInfo<H> {
const SIZE: usize = (1 + H * ARITY) * Item::SIZE
/// The size of an `InputNoteInfo`
pub const SIZE: usize = (1 + H * ARITY) * Item::SIZE
+ H * (u32::BITS as usize / 8)
+ Note::SIZE
+ JubJubAffine::SIZE
Expand Down
12 changes: 6 additions & 6 deletions circuits/tests/serialization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ fn tx_ciruit_1_2() -> Result<(), BytesError> {
fn tx_ciruit_2_2() -> Result<(), BytesError> {
let mut rng = StdRng::seed_from_u64(0xbeef);

let circuit = random_circuit::<1>(&mut rng);
let circuit = random_circuit::<2>(&mut rng);
let circuit_bytes = circuit.to_var_bytes();

assert_eq!(
circuit,
TxCircuit::<HEIGHT, 1>::from_slice(&circuit_bytes[..])?
TxCircuit::<HEIGHT, 2>::from_slice(&circuit_bytes[..])?
);

Ok(())
Expand All @@ -54,12 +54,12 @@ fn tx_ciruit_2_2() -> Result<(), BytesError> {
fn tx_ciruit_3_2() -> Result<(), BytesError> {
let mut rng = StdRng::seed_from_u64(0xbeef);

let circuit = random_circuit::<1>(&mut rng);
let circuit = random_circuit::<3>(&mut rng);
let circuit_bytes = circuit.to_var_bytes();

assert_eq!(
circuit,
TxCircuit::<HEIGHT, 1>::from_slice(&circuit_bytes[..])?
TxCircuit::<HEIGHT, 3>::from_slice(&circuit_bytes[..])?
);

Ok(())
Expand All @@ -69,12 +69,12 @@ fn tx_ciruit_3_2() -> Result<(), BytesError> {
fn tx_ciruit_4_2() -> Result<(), BytesError> {
let mut rng = StdRng::seed_from_u64(0xbeef);

let circuit = random_circuit::<1>(&mut rng);
let circuit = random_circuit::<4>(&mut rng);
let circuit_bytes = circuit.to_var_bytes();

assert_eq!(
circuit,
TxCircuit::<HEIGHT, 1>::from_slice(&circuit_bytes[..])?
TxCircuit::<HEIGHT, 4>::from_slice(&circuit_bytes[..])?
);

Ok(())
Expand Down

0 comments on commit 5694c99

Please sign in to comment.