8000 Refactor conditional statements by collinc97 · Pull Request #55 · ProvableHQ/leo · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Refactor conditional statements #55

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

Merged
merged 10 commits into from
Jun 16, 2020
Merged

Refactor conditional statements #55

merged 10 commits into from
Jun 16, 2020

Conversation

collinc97
Copy link
Collaborator
@collinc97 collinc97 commented Jun 13, 2020

Overview

Currently conditional statements create branches in code where only one path is enforced in the underlying circuit.

Changes

First, we need a gadget that can conditionally enforce assertion statements #52. This will ensure that all branch paths of a conditional statement are enforced.

With our new gadget we can now write assert statements inside the branch of a conditional.

Consider the function enforceBit() which enforces that bit must be a zero or one in the circuit.

function enforceBit(bit: u8) {
  if bit == 1u8 { // <- evaluation only
    assert_eq!(bit, 1u8); // <- enforced constraint (must not fail)
  } else {
    assert_eq!(bit, 0u8);
  }
}

Next, we need to pass an indicator bit down to all child statements. This adds support for definition, assignment, for loops, expression, return, and nested conditional statements.

@collinc97 collinc97 self-assigned this Jun 13, 2020
@collinc97 collinc97 added feature A new feature. refactor Refactor or cleanup. labels Jun 13, 2020
@collinc97
Copy link
Collaborator Author

This branch uses the feature/comparator branch from snarkos which adds support for boolean and integer u8, u16, u32, u64, u128 equality ==

@howardwu howardwu added this to the Leo Developer Preview I milestone Jun 16, 2020
@collinc97 collinc97 requested a review from howardwu June 16, 2020 05:45
@howardwu howardwu merged commit b0773e0 into master Jun 16, 2020
@collinc97 collinc97 deleted the refactor/conditional branch June 18, 2020 00:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feature A new feature. refactor Refactor or cleanup.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants
0