Skip to content
This repository was archived by the owner on Aug 9, 2024. It is now read-only.

Commit

Permalink
chore: cargo update
Browse files Browse the repository at this point in the history
  • Loading branch information
ratankaliani committed Apr 8, 2024
2 parents 525eb64 + a199b11 commit 79f3587
Show file tree
Hide file tree
Showing 13 changed files with 282 additions and 200 deletions.
5 changes: 5 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ jobs:
toolchain: nightly-2024-02-22
override: true

- name: Run cargo audit
uses: actions-rs/audit-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}

- name: Run cargo test
uses: actions-rs/cargo@v1
with:
Expand Down
21 changes: 21 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ ci = []

[dependencies]
env_logger = { version = "0.9.0", default-features = false }
ed25519-dalek = "2.1.1"
hex = "0.4.3"
itertools = "0.10.5"
ff = { package = "ff_ce", version = "0.11", features = ["derive"] }
Expand Down Expand Up @@ -87,6 +86,7 @@ anyhow = "1.0.68"
clap = "4.4.9"
futures = "0.3.30"
async-trait = "0.1.77"
ed25519-dalek = "2.1.1"
[dev-dependencies]
anyhow = "1.0.68"

Expand Down
28 changes: 26 additions & 2 deletions circuits/builder/decoder.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ pub trait DecodingMethods {
compact_bytes: ArrayVariable<ByteVariable, 5>,
) -> (U32Variable, Variable);

/// Get the byte length of a compact int based on the compress mode.
fn get_compact_int_byte_length(&mut self, compress_mode: Variable) -> Variable;

/// Decode a header into its components: {block_nb, parent_hash, state_root and data_root}.
/// header_hash is used for the RLC challenge in get_fixed_subarray.
fn decode_header<const S: usize>(
Expand Down Expand Up @@ -88,6 +91,16 @@ impl<L: PlonkParameters<D>, const D: usize> DecodingMethods for CircuitBuilder<L
(value, compress_mode)
}

fn get_compact_int_byte_length(&mut self, compress_mode: Variable) -> Variable {
// All possible lengths of a SCALE-encoded compact int.
let all_possible_lengths = vec![
self.constant::<Variable>(L::Field::from_canonical_usize(1)),
self.constant::<Variable>(L::Field::from_canonical_usize(2)),
self.constant::<Variable>(L::Field::from_canonical_usize(4)),
self.constant::<Variable>(L::Field::from_canonical_usize(5)),
];
self.select_array_random_gate(&all_possible_lengths, compress_mode)
}
fn decode_header<const S: usize>(
&mut self,
header: &EncodedHeaderVariable<S>,
Expand Down Expand Up @@ -116,7 +129,7 @@ impl<L: PlonkParameters<D>, const D: usize> DecodingMethods for CircuitBuilder<L

// The next field is the data root. The data root is the last 32 bytes of the header.
// Spec: https://github.com/availproject/avail-core/blob/main/core/src/header/extension/v3.rs#L9-L15
let data_root_offset = self.constant::<U32Variable>(DATA_ROOT_OFFSET_FROM_END as u32);
let data_root_offset = self.constant::<U32Variable>(DATA_ROOT_OFFSET_FROM_END);
let mut data_root_start = self.sub(header.header_size, data_root_offset);

// If header_size == 0, then set data_root_start to 0.
Expand Down Expand Up @@ -222,7 +235,18 @@ pub mod tests {
let circuit = builder.build();

// Test cases are (compact int, compress mode).
let test_cases = [(1u32, 0), (64u32, 1), (16384u32, 2), (4294967295u32, 3)];
let test_cases = [
(u32::MIN, 0),
(1u32, 0),
(63u32, 0),
(64u32, 1),
(16383u32, 1),
(16384u32, 2),
(1073741823u32, 2),
(1073741824u32, 3),
(4294967295u32, 3),
(u32::MAX, 3),
];

for i in 0..test_cases.len() {
let mut input = circuit.input();
Expand Down
2 changes: 1 addition & 1 deletion circuits/builder/justification.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ impl<L: PlonkParameters<D>, const D: usize> GrandpaJustificationVerifier for Cir
num_signed = self.add(num_signed, val_signed_u32);
}

// Verify the number of validators that signed is greater than to the threshold.
// Verify the number of validators that signed is greater than the threshold.
let scaled_num_signed = self.mul(num_signed, threshold_denominator);
let scaled_threshold = self.mul(num_active_authorities, threshold_numerator);
let is_valid_num_signed = self.gt(scaled_num_signed, scaled_threshold);
Expand Down
Loading

0 comments on commit 79f3587

Please sign in to comment.