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

Introduce mul_by_inverse_unchecked, and use it #75

Merged
merged 18 commits into from
Jul 15, 2021

Conversation

Pratyush
Copy link
Member

@Pratyush Pratyush commented Jul 7, 2021

Description

Resolves #70 (comment).


Before we can merge this PR, please make sure that all the following items have been
checked off. If any of the checklist items are not applicable, please leave them but
write a little note why.

  • Targeted PR against correct branch (master)
  • Linked to Github issue with discussion and accepted design OR have an explanation in the PR that describes this work.
  • Wrote unit tests
  • Updated relevant documentation in the code
  • Added a relevant changelog entry to the Pending section in CHANGELOG.md
  • Re-reviewed Files changed in the Github PR explorer

src/fields/mod.rs Outdated Show resolved Hide resolved
@Pratyush
Copy link
Member Author

Pratyush commented Jul 7, 2021

Do you have a good way to add a regression test for this behaviour?

src/fields/mod.rs Outdated Show resolved Hide resolved
Copy link
Member

@tsunrise tsunrise left a comment

Choose a reason for hiding this comment

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

looks good to me (though we need to make sure domain.offset != 0 if we plan to use unchecked)

@Pratyush
Copy link
Member Author

Pratyush commented Jul 13, 2021

Ok I added a check to make sure domain.offset is non-zero by construction. I don't know if this is a good idea: is there ever a case where domain.offset is supposed to be zero? If so, then I can change it to enforce the check inside lagrange_interpolate_with_non_constant_offset, instead of in Radix2DomainVar::new

cc @ValarDragon @tsunrise

@ValarDragon
Copy link
Member

domain.offset should never be zero for multiplicative domains, but I don't think that needs to be proven in circuit. Thats about the circuit definition being valid. (The circuit definition has defined an invalid codeword domain if its zero, the offset derivation shouldn't allow construction of zero domain offsets)

@Pratyush
Copy link
Member Author

I think @tsunrise's code require offset to be a variable, so we have to enforce non-zeroness at some point.

@ValarDragon
Copy link
Member

Oh I see. If necessary as a temporary defense in depth for correctness seems like an alright fix then.

What I'd rather see is we assert this on the DomainVar itself (that its offset and generator are non-zero). Basically in the constructor for DomainVar, include an argument for the inputs being guaranteed to be non-zero. If false, then do the non-zero checks once there.

@Pratyush
Copy link
Member Author

Pratyush commented Jul 13, 2021

What I'd rather see is we assert this on the DomainVar itself (that its offset and generator are non-zero). Basically in the constructor for DomainVar, include an argument for the inputs being guaranteed to be non-zero. If false, then do the non-zero checks once there.

Yeah, that's what I changed it to do:

pub fn new(gen: F, dimension: u64, offset: FpVar<F>) -> Result<Self, SynthesisError> {

@ValarDragon
Copy link
Member

I meant explicitly including an argument to not get a constraint created. Currently it seems like a constraint is always created if offset is not a constant?

@Pratyush
Copy link
Member Author

Pratyush commented Jul 13, 2021

Ah so like a new_unchecked method? For the time being I'm fine with keeping the new method and using that, because I assume the domain is constructed only a few times (< 10?) in the entire circuit

@ValarDragon
Copy link
Member

Its constructed once per query per round, so ~200 times.

@Pratyush
Copy link
Member Author

I see, with a different offset each time?

@ValarDragon
Copy link
Member

ValarDragon commented Jul 13, 2021

Yeah. The offset is based on the query coset

@Pratyush
Copy link
Member Author

I think I addressed all comments, except for the new_unchecked for DomainVar. I think for the time being it's fine to use new, as it only adds a couple hundred constraints, which would be dominated by the rest of the circuit.

Technically, this is a breaking change due to the changes to the DomainVar API, but since the only consumer of that is ark-ldt, I believe, I think it's fine to do that.

(Maybe we should have "in-flux" features hidden behind a unstable feature flag?)

@Pratyush Pratyush merged commit b6e7e94 into master Jul 15, 2021
@Pratyush Pratyush deleted the add-mul-inverse-unchecked branch July 15, 2021 23:39
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.

4 participants