Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CopyCircuit hi-lo changes #1060

Draft
wants to merge 6 commits into
base: word_hi_lo
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 27 additions & 3 deletions bus-mapping/src/circuit_input_builder/execution.rs
Original file line number Diff line number Diff line change
Expand Up @@ -350,11 +350,35 @@ impl_expr!(CopyDataType, u64::from);
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CopyStep {
/// Byte value copied in this step.
pub value: u8,
pub half_word: [u8; 16],
/// Byte value before this step.
pub prev_value: u8,
pub prev_half_word: [u8; 16],
/// mask indicates this byte won't be copied.
pub mask: bool,
pub mask: [bool; 16],
}

impl From<&[(u8, bool, bool)]> for CopyStep {
fn from(steps: &[(u8, bool, bool)]) -> Self {
assert_eq!(steps.len(), 16, "steps length should be 16");
let bytes: [u8; 16] = steps
.iter()
.copied()
.map(|(v, _, _)| v)
.collect::<Vec<_>>()
.try_into()
.unwrap();
Self {
half_word: bytes,
prev_half_word: bytes,
mask: steps
.iter()
.copied()
.map(|(_, _, m)| m)
.collect::<Vec<_>>()
.try_into()
.unwrap(),
}
}
}

/// Defines an enum type that can hold either a number or a hash value.
Expand Down
12 changes: 12 additions & 0 deletions gadgets/src/less_than.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ impl<F: Field, const N_BYTES: usize> LtConfig<F, N_BYTES> {
let rotation = rotation.unwrap_or_else(Rotation::cur);
sum::expr(self.diff.iter().map(|c| meta.query_advice(*c, rotation)))
}

/// Annotates the Lt chip's columns.
pub fn annotate<N, AR>(&self, region: &mut Region<'_, F>, name: N)
where
N: Fn() -> AR,
AR: Into<String>,
{
region.name_column(|| format!("{}.lt", name().into()), self.lt);
for (idx, diff_column) in self.diff.iter().enumerate() {
region.name_column(|| format!("{}.diff[{}]", name().into(), idx), *diff_column);
}
}
}

/// Chip that compares lhs < rhs.
Expand Down
Loading