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

Thermometer Encoding #17

Merged
merged 10 commits into from
May 29, 2023
Merged

Thermometer Encoding #17

merged 10 commits into from
May 29, 2023

Conversation

georgwiese
Copy link
Member

@georgwiese georgwiese commented May 23, 2023

Depends on #20

This PR adds two gadgets:

  • GreaterThanChip: Computes x > y
  • EncodeImageChip: Maps an image to a binary vector by comparing each pixel to multiple binarization thresholds

The WnnChip then wires everything together and now proves the entire prediction, starting from the intensity values of the image! 🎉 The most involved part here was writing a test which asserts the right outputs all the way from the pixel values.

Other Changes:

  • The HashChip no longer needs to range-check its inputs, because they are now comping from the Bits2NumChip, which guarantees that they can be represented by a certain number of bits.
  • I got rid of warnings by allowing dead code in the (currently unused) "Single Bit Bloomfilter" gadget.

These are the benchmark results (including the changes from #20):

benches/proof_generation
                        time:   [1.6548 s 1.6812 s 1.7049 s]
                        change: [+28.771% +31.727% +34.625%] (p = 0.00 < 0.05)
                        Performance has regressed.
benches/key_generation  time:   [888.46 ms 905.16 ms 924.79 ms]
                        change: [+7.9176% +10.317% +13.273%] (p = 0.00 < 0.05)
                        Performance has regressed.
benches/verification    time:   [14.755 ms 15.330 ms 15.743 ms]
                        change: [+3.5830% +11.686% +20.987%] (p = 0.01 < 0.05)
                        Performance has regressed.

Fixes #6

@georgwiese georgwiese changed the base branch from main to feature/bits_to_hash_input_gadget May 24, 2023 20:12
@georgwiese georgwiese marked this pull request as ready for review May 25, 2023 14:41
Copy link
Collaborator

@ElusAegis ElusAegis left a comment

Choose a reason for hiding this comment

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

Good job. We can merge it as it is, but in general I feel like we should make the image as an Instance Column so that we would known on which image we actually got the result

src/gadgets/encode_image.rs Show resolved Hide resolved
src/gadgets/encode_image.rs Show resolved Hide resolved
wnn_chip.load(&mut layouter)?;

let result = wnn_chip.predict(layouter.namespace(|| "wnn"), self.inputs.clone())?;
let result = wnn_chip.predict(layouter.namespace(|| "wnn"), &self.image)?;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should the image be as a public input in Advice? As now we are proving that some image was converted into a valid representation

@georgwiese
Copy link
Member Author

Thanks for the review!

I think both use cases are valid, with public and private input. For private input, you'd probably want to additionally validate the image in the circuit (e.g. by checking the signature of an attested sensor). So then, you'd use this codebase as a library.

I think we should support both and opened #21 to track it.

Base automatically changed from feature/bits_to_hash_input_gadget to main May 29, 2023 08:03
@georgwiese georgwiese merged commit fc49e0e into main May 29, 2023
@georgwiese georgwiese deleted the thermometer-encoding branch May 29, 2023 08:07
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.

5: Gadget: Thermometer Encoding
2 participants