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

Compact groth16 arguments #288

Merged
merged 3 commits into from
Oct 7, 2020
Merged

Conversation

dtebbs
Copy link
Contributor

@dtebbs dtebbs commented Sep 21, 2020

Compact the proof and vk into single arrays of evm words. Saves gas and reduces the number of parameters required in applictions where vk and proof must be passed as arguments.

Depends on #287

@dtebbs dtebbs changed the title Compact groth16 arguments (depends on #287) WIP: Compact groth16 arguments (depends on #287) Sep 21, 2020
@dtebbs dtebbs force-pushed the compact-groth16-arguments branch 2 times, most recently from 6635dee to e10f7bc Compare September 21, 2020 15:14
@dtebbs dtebbs changed the title WIP: Compact groth16 arguments (depends on #287) Compact groth16 arguments (depends on #287) Sep 21, 2020
@dtebbs dtebbs force-pushed the compact-groth16-arguments branch 2 times, most recently from abd9b93 to e00294f Compare September 28, 2020 12:27
@dtebbs dtebbs force-pushed the negate-groth16-b branch 2 times, most recently from 65e912f to 13f5d4f Compare September 29, 2020 15:16
@AntoineRondelet AntoineRondelet changed the base branch from negate-groth16-b to develop October 2, 2020 15:54
@dtebbs dtebbs changed the title Compact groth16 arguments (depends on #287) Compact groth16 arguments Oct 2, 2020
client/zeth/core/contracts.py Outdated Show resolved Hide resolved
// uint256[2] Alpha,
// uint256[4] Beta,
// uint256[4] Delta,
// uint256[] ABC_coords
Copy link
Contributor

Choose a reason for hiding this comment

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

Side note: Now that we support several curves (i.e. bn/bls) may be worth to clarify these comments. This contract is tailored for bn254, and won't work with any other groups. So May be worth specifying under with circumstances your comment above holds (i.e. ALT_BN128 set in cpp code config) or simply rephrase to make this generic, e.g.:

// Constructor. The form of vk is:
//     alpha = vk[:2*N]
//     beta = vk[2*N:6*N]
//     delta = vk[6*N:10*N]
//     ABC_coords = vk[10*N:]
//  where:
//     - q is the characteristic of the base field of the pairing group used
//     - N = 2*\ceil{bitLen(q)/256} (# EVM words necessary to represent elements of Fq)

Copy link
Contributor

Choose a reason for hiding this comment

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

Side note2: Making the constructor below generic shouldn't be really hard, but troubles may start with functions below, so that may be better to have different contracts to avoid any complexity related to generalization (and so my comment above may not apply anymore if the group name appears in the contract name)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I've added a comment at the top to explain that this all assumes alt-bn128.

Making the constructor below generic shouldn't be really hard, but troubles may start with functions below, so that may be better to have different contracts to avoid any complexity related to generalization

Yes, good idea to rename, especially once we support another curve. It will be interesting to see just how much of the contract can be made generic. But to make it properly generic without some kind of templating I think we'd probably need to pass several extra parameters (to specify the size of field and curve elements, the value of `g2, etc) and extra logic at runtime to deal with proofs and verification keys in dynamic arrays.

It would be nicer to split the verification part into it's own library. I seem to remember hit issues with this in the past, but it's working in zecale so we may be able to replicate what happens there.

uint256[2] memory c_p,
uint256[2] memory h,
uint256[2] memory k,
uint256[18] memory proof_data,
Copy link
Contributor

Choose a reason for hiding this comment

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

Name is inconsistent with argument name in verifyTx for Groth16

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Renamed the groth16 version from proof to proof_data. (In the pghr13 case this function fills out an actual Proof structure, which is naturally named proof. The groth16 version is optimized to pull directy from the memory buffer.)

@AntoineRondelet
Copy link
Contributor

LGTM

@AntoineRondelet AntoineRondelet merged commit 1adfdb6 into develop Oct 7, 2020
@AntoineRondelet AntoineRondelet deleted the compact-groth16-arguments branch October 9, 2020 10:28
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.

None yet

2 participants