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

Encrypted Shift Right and Shift Left Circuits #129

Merged
merged 3 commits into from
Feb 18, 2025
Merged

Conversation

NMCarv
Copy link
Member

@NMCarv NMCarv commented Feb 18, 2025

Problem

We needed to add dynamic shift operators (both left and right) for our garbled integers (both GarbledUint and GarbledInt) as part of our circuit SDK, so we can implement this as a circuit itself on revm.

Implementation

  1. Bit–Order Reversal:

    • Modified the shift operators so that the input is reversed (converting LSB–first to MSB–first), the circuit is executed, and then the result is reversed back to our native order.
  2. Operator Trait Integration:

    • Implemented the standard Rust operator traits (Shl, Shr, ShlAssign, and ShrAssign) for both GarbledUint and GarbledInt.
    • For GarbledInt, the operators convert the value to a GarbledUint, perform the shift, then convert back.
    • Both dynamic (with a garbled shift amount) and literal shift amounts (using usize) are supported.
  3. Testing:

    • Updated and ran comprehensive tests in our tests/bitwise.rs file.
    • All tests (including left/right shifts for both unsigned and signed types) now pass.

Outcome:

This pull request fixes the shift operator implementations by reconciling the bit–ordering differences between our internal representation and the circuit–builder expectations, and fully integrates shift operators for both garbled unsigned and signed integers.

@NMCarv NMCarv added the bug Something isn't working label Feb 18, 2025
@NMCarv NMCarv requested a review from 10d9e February 18, 2025 17:48
@NMCarv NMCarv self-assigned this Feb 18, 2025
Copy link
Collaborator

@10d9e 10d9e left a comment

Choose a reason for hiding this comment

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

image

@NMCarv NMCarv merged commit d29737c into main Feb 18, 2025
4 checks passed
@NMCarv NMCarv deleted the feat/shift-circuits branch February 18, 2025 17:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants