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

R1cs nark pcd #1

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

R1cs nark pcd #1

wants to merge 4 commits into from

Conversation

Will-Lin4
Copy link
Owner

Dummy PR

pub(crate) type MainAffine<E> = <E as CurveCycle>::E1;
pub(crate) type HelpAffine<E> = <E as CurveCycle>::E2;

pub(crate) type MainField<E> = <<E as CurveCycle>::E2 as AffineCurve>::BaseField;

Choose a reason for hiding this comment

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

Suggested change
pub(crate) type MainField<E> = <<E as CurveCycle>::E2 as AffineCurve>::BaseField;
pub(crate) type MainField<E> = <<E as CurveCycle>::E1 as AffineCurve>::ScalarField;

Copy link
Owner Author

@Will-Lin4 Will-Lin4 May 29, 2021

Choose a reason for hiding this comment

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

For some reason, applying this change causes the library to not compile. An example of an error is: the trait ark_ff::PrimeField is not implemented for <<E as CurveCycle>::E2 as AffineCurve>::BaseField. It isn't clear to me why it isn't detecting it as a PrimeField. Maybe it is just substituting the BaseField in without doing anything else due to https://github.com/arkworks-rs/algebra/blob/dae430780082b8ebd3e092f08759c8e274d47e56/ec/src/lib.rs#L336-L338?

Comment on lines +77 to +79
let cs = ConstraintSystem::<HelpField<E>>::new_ref();
let _hash = FpVar::new_input(cs.clone(), || Ok(HelpField::<E>::zero())).unwrap();
return cs.num_instance_variables();

Choose a reason for hiding this comment

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

If we know we're only ever allocating one variable, we can hard code the result of cs.num_instance_variables(). If that can change, we should instead invoke the appropriate code (eg: SpongeOutout::new_input(cs.clone(), || Ok(dummy_output))).

Copy link
Owner Author

Choose a reason for hiding this comment

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

I agree that we should invoke the appropriate code rather than directly using the HelpField.

However, wouldn't it be a poor choice to break the abstraction of the ConstraintSystem by hard coding the expected number of instance variables? If I am remembering correctly, one implementation detail of ConstraintSystem is that it adds a one when initializing the instance variables. However, such detail isn't very relevant to this library (we only care that we are using the outputs of CS) and if that implementation detail ever changes (would it?), then it may introduce some difficult to find bugs.

Considering this point, would we still want to hard code the number of instance variables?

let main_circuit_input_len = MainCircuit::<E, PC, P>::public_input_size();
let (main_input_instances, main_old_accumulator_instances) = if base_case {
(
vec![InputInstance::zero(main_circuit_input_len, MAKE_ZK); P::PRIOR_MSG_LEN],

Choose a reason for hiding this comment

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

Maybe we should make this also placeholder, instead of zero?

Copy link
Owner Author

Choose a reason for hiding this comment

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

I have opened a PR in accumulation to apply this change (arkworks-rs/accumulation#34).

* Allocation
*/

let claimed_input_hash_var = FpVar::new_input(ns!(cs, "alloc_claimed_input_hash"), || {

Choose a reason for hiding this comment

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

We can avoid the _var suffix; we aren't using claimed_input_hash anywhere afterwards, right? Similarly for the other cases.

Copy link
Owner Author

@Will-Lin4 Will-Lin4 May 29, 2021

Choose a reason for hiding this comment

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

claimed_input_hash_var and other variables have their native counterparts, so I think having _var is necessary.

let claimed_input_hash: HelpField<E> =

let HelpCircuit {
main_avk,
main_accumulation_input_instances: main_input_instances,
main_old_accumulator_instances,
main_new_accumulator_instance,
mut main_accumulation_proof,
_config_phantom,
_predicate_phantom,
} = self;

Ok(claimed_input_hash)
})?;

let base_case_var = Boolean::new_witness(ns!(cs, "alloc_base_case_bit"), || Ok(base_case))?;
Copy link

@Pratyush Pratyush May 28, 2021

Choose a reason for hiding this comment

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

This should be allocated as a input, otherwise the prover can always set it to true, forcing the accumulation part to be ignored.

EDIT: unless this is checked via the hash, which it isn't right now.

Copy link
Owner Author

Choose a reason for hiding this comment

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

If we allocate base_case_var as an input, the prover in the next recursive step would need to know whether the prior step was a base case for the accumulation right? Currently, I don't think the PCD library gives the prover this information. Would we need to modify the API to include such detail or is there any other way of passing such information around?

Comment on lines +42 to +45
type MainCurveVar: CurveVar<MainProjective<E>, HelpField<E>> + AbsorbableGadget<HelpField<E>>;

/// The curve var for the help affine.
type HelpCurveVar: CurveVar<HelpProjective<E>, MainField<E>> + AbsorbableGadget<MainField<E>>;

Choose a reason for hiding this comment

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

Maybe you can extract this into a CurveCycleGadget trait, similar to CurveCycle?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Would putting this relation into a gadget/var be appropriate? The constraint fields are different. Gadgets and vars usually specify a single constraint field right?

@rozbb
Copy link

rozbb commented Jan 16, 2022

Hi all, what is the status of this PR? I'm trying to play with some IVC stuff and I'd like to see the feasibility of this scheme for our idea. Currently this branch doesn't compile. The errors are coming from the ark-poly-commit dependency.

@Will-Lin4
Copy link
Owner Author

Hi all, what is the status of this PR? I'm trying to play with some IVC stuff and I'd like to see the feasibility of this scheme for our idea. Currently this branch doesn't compile. The errors are coming from the ark-poly-commit dependency.

Hello! I am not currently developing for this repository. This branch depended on an older version of ark-poly-commit, which is likely the reason the branch is not compiling.

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.

3 participants