Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .github/workflows/runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,9 @@ jobs:
working-directory: curdleproofs
run: |
poetry run mypy .
- name: Curdleproofs - Lint with flake8
working-directory: curdleproofs
run: poetry run flake8
- name: Curdleproofs - Test with pytest
working-directory: curdleproofs
run: |
Expand Down
2 changes: 2 additions & 0 deletions curdleproofs/.flake8
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[flake8]
ignore = E501
8 changes: 4 additions & 4 deletions curdleproofs/curdleproofs/__init__.py
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
from .whisk_interface import (
from .whisk_interface import ( # noqa:F401
IsValidWhiskShuffleProof,
IsValidWhiskOpeningProof,
GenerateWhiskShuffleProof,
GenerateWhiskTrackerProof,
WhiskTracker,
)
from .opening import TrackerOpeningProof
from .crs import CurdleproofsCrs
from .curdleproofs import (
from .opening import TrackerOpeningProof # noqa:F401
from .crs import CurdleproofsCrs # noqa:F401
from .curdleproofs import ( # noqa:F401
N_BLINDERS,
CurdleProofsProof,
VerifierInput,
Expand Down
16 changes: 3 additions & 13 deletions curdleproofs/curdleproofs/commitment.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,15 @@
import json
import random
from typing import Any, Dict, Tuple, Type, TypeVar
from curdleproofs.crs import CurdleproofsCrs
from typing import Type, TypeVar
from curdleproofs.util import (
PointProjective,
Fr,
field_to_bytes,
get_random_point,
point_projective_from_json,
point_projective_to_json,
point_projective_to_bytes,
BufReader,
g1_to_bytes,
)
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
Z1,
eq,
)

Expand Down Expand Up @@ -73,13 +63,13 @@ def from_json(cls: Type[T_GroupCommitment], json) -> T_GroupCommitment:
T_1=point_projective_from_json(json["T_1"]),
T_2=point_projective_from_json(json["T_2"]),
)

def to_bytes(self) -> bytes:
return b''.join([
g1_to_bytes(self.T_1),
g1_to_bytes(self.T_2),
])

@classmethod
def from_bytes(cls: Type[T_GroupCommitment], b: BufReader) -> T_GroupCommitment:
return cls(
Expand Down
20 changes: 6 additions & 14 deletions curdleproofs/curdleproofs/crs.py
Original file line number Diff line number Diff line change
@@ -1,26 +1,18 @@
from functools import reduce
import json
from random import randint
from typing import List, Type, TypeVar
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
Z1,
Z1
)
from curdleproofs.util import (
PointProjective,
affine_to_projective,
get_random_point,
point_projective_from_json,
point_projective_to_json,
BufReader,
g1_to_bytes,
)
from py_ecc.bls.g2_primitives import G1_to_pubkey, pubkey_to_G1
from eth_typing import BLSPubkey

T_CurdleproofsCrs = TypeVar("T_CurdleproofsCrs", bound="CurdleproofsCrs")

Expand Down Expand Up @@ -55,13 +47,13 @@ def new(
@classmethod
def from_random_points(cls: Type[T_CurdleproofsCrs], ell: int, n_blinders: int, points: List[PointProjective]) -> T_CurdleproofsCrs:
vec_G = points[0:ell]
vec_H = points[ell:ell+n_blinders]
vec_H = points[ell:ell + n_blinders]
return cls(
vec_G=vec_G,
vec_H=vec_H,
H=points[ell+n_blinders + 0],
G_t=points[ell+n_blinders + 1],
G_u=points[ell+n_blinders + 2],
H=points[ell + n_blinders + 0],
G_t=points[ell + n_blinders + 1],
G_u=points[ell + n_blinders + 2],
G_sum=reduce(add, vec_G, Z1),
H_sum=reduce(add, vec_H, Z1),
)
Expand Down Expand Up @@ -101,7 +93,7 @@ def to_bytes(self) -> bytes:
g1_to_bytes(self.G_sum),
g1_to_bytes(self.H_sum),
])

@classmethod
def from_bytes(cls: Type[T_CurdleproofsCrs], b: BufReader, ell: int, n_blinders: int) -> T_CurdleproofsCrs:
return cls(
Expand Down
17 changes: 2 additions & 15 deletions curdleproofs/curdleproofs/curdleproofs.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,33 @@
import json
from math import log2
import random
from curdleproofs.crs import CurdleproofsCrs
from curdleproofs.ipa import generate_blinders
from curdleproofs.util import (
affine_to_projective,
point_affine_to_bytes,
point_projective_from_json,
point_projective_to_bytes,
point_projective_to_json,
points_projective_to_bytes,
get_random_point,
BufReader,
g1_to_bytes,
)
from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript
from typing import List, Optional, Tuple, Type, TypeVar
from typing import List, Tuple, Type, TypeVar
from curdleproofs.util import (
PointProjective,
Fr,
field_to_bytes,
invert,
get_permutation,
)
from curdleproofs.msm_accumulator import MSMAccumulator, compute_MSM
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
neg,
Z1,
is_inf,
FQ,
)
from curdleproofs.same_perm import SamePermutationProof
from curdleproofs.same_msm import SameMSMProof
from curdleproofs.same_scalar import SameScalarProof
from curdleproofs.commitment import GroupCommitment
from py_ecc.bls.g2_primitives import G1_to_pubkey, pubkey_to_G1
from eth_typing import BLSPubkey

N_BLINDERS = 4

Expand Down Expand Up @@ -303,7 +290,7 @@ def from_json(cls: Type[T_CurdleProofsProof], json) -> T_CurdleProofsProof:
same_scalar_proof=SameScalarProof.from_json(json["same_scalar_proof"]),
same_msm_proof=SameMSMProof.from_json(json["same_msm_proof"]),
)

def to_bytes(self) -> bytes:
return b''.join([
g1_to_bytes(self.A),
Expand Down
14 changes: 1 addition & 13 deletions curdleproofs/curdleproofs/grand_prod.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,10 @@
from functools import reduce
import json
import operator
import random
from curdleproofs.crs import CurdleproofsCrs
from curdleproofs.ipa import IPA, generate_blinders, inner_product
from curdleproofs.util import (
field_from_json,
field_to_json,
invert,
point_projective_from_json,
point_projective_to_bytes,
get_random_point,
point_projective_to_json,
BufReader,
g1_to_bytes,
Expand All @@ -22,18 +16,13 @@
PointProjective,
Fr,
field_to_bytes,
affine_to_projective,
)
from curdleproofs.msm_accumulator import MSMAccumulator, compute_MSM
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
neg,
eq,
Z1,
)

T_GrandProductProof = TypeVar("T_GrandProductProof", bound="GrandProductProof")
Expand All @@ -59,7 +48,6 @@ def new(
) -> Tuple[Optional[T_GrandProductProof], Optional[str]]:
n_blinders = len(vec_b_blinders)
ell = len(crs_G_vec)
n = ell + n_blinders

transcript.append(b"gprod_step1", point_projective_to_bytes(B))
transcript.append(b"gprod_step1", field_to_bytes(gprod_result))
Expand Down Expand Up @@ -224,7 +212,7 @@ def from_json(cls: Type[T_GrandProductProof], json) -> T_GrandProductProof:
r_p=field_from_json(json["r_p"], Fr),
ipa_proof=IPA.from_json(json["ipa_proof"]),
)

def to_bytes(self) -> bytes:
return b''.join([
g1_to_bytes(self.C),
Expand Down
16 changes: 2 additions & 14 deletions curdleproofs/curdleproofs/ipa.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,10 @@
import json
from math import log2
import random
from curdleproofs.crs import CurdleproofsCrs
from curdleproofs.util import (
affine_to_projective,
field_from_json,
field_to_json,
point_affine_to_bytes,
point_projective_from_json,
point_projective_to_bytes,
point_projective_to_json,
points_affine_to_bytes,
points_projective_to_bytes,
get_random_point,
BufReader,
g1_to_bytes,
fr_to_bytes,
Expand All @@ -32,12 +24,8 @@
)
from curdleproofs.msm_accumulator import MSMAccumulator, compute_MSM
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
neg,
)


Expand Down Expand Up @@ -289,7 +277,7 @@ def from_json(cls: Type[T_IPA], json) -> T_IPA:
c_final=field_from_json(json["c_final"], Fr),
d_final=field_from_json(json["d_final"], Fr),
)

def to_bytes(self) -> bytes:
return b''.join([
g1_to_bytes(self.B_c),
Expand All @@ -301,7 +289,7 @@ def to_bytes(self) -> bytes:
fr_to_bytes(self.c_final),
fr_to_bytes(self.d_final),
])

@classmethod
def from_bytes(cls: Type[T_IPA], b: BufReader, n: int) -> T_IPA:
log2_n = log2_int(n)
Expand Down
2 changes: 0 additions & 2 deletions curdleproofs/curdleproofs/msm_accumulator.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
from curdleproofs.util import PointProjective, Fr, affine_to_projective
from typing import Dict, List, Tuple, Union
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
Expand Down
13 changes: 1 addition & 12 deletions curdleproofs/curdleproofs/opening.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import json
from typing import Type, TypeVar
from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript

Expand All @@ -9,28 +8,18 @@
field_to_json,
generate_blinders,
point_projective_from_json,
point_projective_to_bytes,
point_projective_to_json,
points_projective_to_bytes,
BufReader,
g1_to_bytes,
fr_to_bytes,
)
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
neg,
eq,
)
from py_ecc.bls.g2_primitives import (
G1_to_pubkey,
pubkey_to_G1,
)
from py_ecc.bls.hash import i2osp, os2ip
from eth_typing import BLSPubkey

T_TrackerOpeningProof = TypeVar("T_TrackerOpeningProof", bound="TrackerOpeningProof")

Expand Down Expand Up @@ -113,7 +102,7 @@ def to_bytes(self) -> bytes:
g1_to_bytes(self.B),
fr_to_bytes(self.s)
])

@classmethod
def from_bytes(cls: Type[T_TrackerOpeningProof], b: BufReader) -> T_TrackerOpeningProof:
return cls(
Expand Down
20 changes: 3 additions & 17 deletions curdleproofs/curdleproofs/same_msm.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,12 @@
import json
from math import log2
from curdleproofs.crs import CurdleproofsCrs
from curdleproofs.util import (
affine_to_projective,
field_from_json,
field_to_json,
point_affine_to_bytes,
point_projective_from_json,
point_projective_to_bytes,
point_projective_to_json,
points_affine_to_bytes,
points_projective_to_bytes,
get_random_point,
generate_blinders,
get_verification_scalars_bitstring,
g1_from_bytes,
BufReader,
g1_to_bytes,
fr_to_bytes,
Expand All @@ -23,18 +15,12 @@
)
from curdleproofs.curdleproofs_transcript import CurdleproofsTranscript
from typing import List, Optional, Tuple, Type, TypeVar
from curdleproofs.util import PointProjective, Fr, field_to_bytes, invert
from curdleproofs.util import PointProjective, Fr, invert
from curdleproofs.msm_accumulator import MSMAccumulator, compute_MSM
from py_ecc.optimized_bls12_381.optimized_curve import (
curve_order,
G1,
multiply,
normalize,
add,
neg,
)
from py_ecc.bls.g2_primitives import G1_to_pubkey, pubkey_to_G1
from eth_typing import BLSPubkey

T_SameMSMProof = TypeVar("T_SameMSMProof", bound="SameMSMProof")

Expand Down Expand Up @@ -284,7 +270,7 @@ def from_json(cls: Type[T_SameMSMProof], json) -> T_SameMSMProof:
vec_R_U=[point_projective_from_json(R_U) for R_U in json["vec_R_U"]],
x_final=field_from_json(json["x_final"], Fr),
)

def to_bytes(self) -> bytes:
return b''.join([
g1_to_bytes(self.B_a),
Expand All @@ -298,7 +284,7 @@ def to_bytes(self) -> bytes:
g1_list_to_bytes(self.vec_R_U),
fr_to_bytes(self.x_final),
])

@classmethod
def from_bytes(cls: Type[T_SameMSMProof], b: BufReader, n: int) -> T_SameMSMProof:
log2_n = log2_int(n)
Expand Down
Loading