Skip to content

Conversation

@lorenzorota
Copy link
Contributor

Reopened PR #218 to fix branching issues


Currently, program inputs cannot be declared for structs that are being returned. Take the following program

struct Pt {
    field x
    field y
}
struct Pts {
    Pt[2] pts
}

def main(private Pts[1] pts) -> Pt:
    return Pt {x: pts[0].pts[0].x * pts[0].pts[1].x, y: pts[0].pts[0].y * pts[0].pts[1].y}

with the value maps

(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513
(let (
    (pts.0.pts.0.x #f2)
    (pts.0.pts.0.y #f4)
    (pts.0.pts.1.x #f2)
    (pts.0.pts.1.y #f4)
) true ;ignored
)
)

and

(set_default_modulus 52435875175126190479447740508185965837690552500527637822603658699938581184513
(let (
    (return.x #f4)
    (return.y #f16)
) true ;ignored
)
)

for the prover and verifier, respectively. This would throw a not implemented error since precomputations are not handled.

This PR adds the missing precomputations, similar to how it's done for arrays and mutable arrays, i.e., computing the precomputations by unwrapping all the struct fields. For this I included two new functions in T: unwrap_struct and unwrap_struct_ir, which both return a FieldList or an error.

@alex-ozdemir alex-ozdemir self-requested a review February 10, 2025 22:07
Copy link
Contributor

@alex-ozdemir alex-ozdemir left a comment

Choose a reason for hiding this comment

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

This looks great. Once the build passes, I'll merge it.
I recommend you rebase/merge in the new master and then fix any remaining build issues.

@lorenzorota lorenzorota force-pushed the extend-input-declarations branch from bf25d1a to ea55e94 Compare February 11, 2025 10:20
@lorenzorota
Copy link
Contributor Author

I'm running the lint checker locally and I get the following error:

error[E0432]: unresolved import `std::num::NonZero`
 --> circ_hc/src/collections/lru.rs:3:5
  |
3 | use std::num::NonZero;
  |     ^^^^^^^^^^-------
  |     |         |
  |     |         help: a similar name exists in the module: `NonZeroI8`
  |     no `NonZero` in `num`

I'll see if this has something to do with my version of rust. Does this also happen on your end?

+ Use unwrap_or_else instead of expect
@lorenzorota
Copy link
Contributor Author

I'll see if this has something to do with my version of rust. Does this also happen on your end?

Fixed it now, it was indeed a rust version issue.

@alex-ozdemir alex-ozdemir merged commit 38f585e into circify:master Feb 11, 2025
1 check passed
@alex-ozdemir
Copy link
Contributor

Great, thanks for this patch!

StefanosChaliasos pushed a commit to StefanosChaliasos/circ that referenced this pull request Feb 12, 2025
@lorenzorota lorenzorota deleted the extend-input-declarations branch February 17, 2025 10:19
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