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

[chore] Implement Stateful for all Chips #1199

Merged
merged 1 commit into from
Jan 13, 2025
Merged

Conversation

nyunyunyunyu
Copy link
Contributor

No description provided.

Copy link

github-actions bot commented Jan 9, 2025

group app.proof_time_ms app.cycles app.cells_used leaf.proof_time_ms leaf.cycles leaf.cells_used
verify_fibair (+97 [+2.6%]) 3,891 746,301 30,011,454 - - -
fibonacci_program (+36 [+0.6%]) 6,139 1,500,137 51,505,102 - - -
regex_program (+209 [+1.1%]) 18,745 4,190,904 165,028,173 - - -
ecrecover_program (-4 [-0.2%]) 2,599 285,401 15,092,297 - - -

Commit: baf339a

Benchmark Workflow

@nyunyunyunyu nyunyunyunyu marked this pull request as ready for review January 9, 2025 20:09
impl<const NUM_BITS: usize> Stateful<Vec<u8>> for SharedBitwiseOperationLookupChip<NUM_BITS> {
fn load_state(&mut self, state: Vec<u8>) {
// AtomicU32 can be deserialized as u32
let (count_range, count_xor): (Vec<u32>, Vec<u32>) = bitcode::deserialize(&state).unwrap();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe we should resolve the choice of bitcode vs bincode before/during this PR?

@@ -100,6 +104,9 @@ pub struct RangeTupleCheckerChip<const N: usize> {
count: Vec<Arc<AtomicU32>>,
}

#[derive(Debug, Clone)]
pub struct SharedRangeTupleCheckerChip<const N: usize>(Arc<RangeTupleCheckerChip<N>>);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

did you make a newtype for protected type purposes or because of some practical reason around traits?

@@ -50,7 +50,7 @@ impl Sha256Air {
trace_width: usize,
trace_start_col: usize,
input: &[u32; SHA256_BLOCK_WORDS],
bitwise_lookup_chip: &BitwiseOperationLookupChip<8>,
bitwise_lookup_chip: SharedBitwiseOperationLookupChip<8>,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why are we doing this...? it doesn't really matter, but cloning Arc is worse than &.
You could also make SharedBitwiseOperationLookupChip implement Borrow I think?

Copy link
Contributor

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wasn't clear why we needed Stateful...Chip: does rust prevent you from implementing Stateful on Arc<T> even when you own T?

The fact that you need to specify bitcode explicitly in every load_state seems bad. Let's discuss if we should update Stateful to either pass in a deserializer / serializer (openvm-org/stark-backend#20 (comment)) or you could do impl Stateful<(Deserializer, Vec<u8>)> for ... maybe?

nit: You can implement T on StatefulXChip to prevent some clone.

Copy link
Contributor

@jonathanpwang jonathanpwang left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Approved after responding to comments and resolving choice of bitcode vs bincode.

@nyunyunyunyu nyunyunyunyu merged commit 8ccdf01 into main Jan 13, 2025
22 of 23 checks passed
@nyunyunyunyu nyunyunyunyu deleted the chore/impl-stateful branch January 13, 2025 09:16
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants