contracts: update G2Point definition
This commit is contained in:
parent
555dd6ef8b
commit
1c04c4d1ff
|
@ -10,13 +10,20 @@ type
|
|||
G1Point* = object
|
||||
x*: UInt256
|
||||
y*: UInt256
|
||||
# A field element F_{p^2} encoded as `real + i * imag`
|
||||
Fp2Element* = object
|
||||
real*: UInt256
|
||||
imag*: UInt256
|
||||
G2Point* = object
|
||||
x*: array[2, UInt256]
|
||||
y*: array[2, UInt256]
|
||||
x*: Fp2Element
|
||||
y*: Fp2Element
|
||||
|
||||
func solidityType*(_: type G1Point): string =
|
||||
solidityType(G1Point.fieldTypes)
|
||||
|
||||
func solidityType*(_: type Fp2Element): string =
|
||||
solidityType(Fp2Element.fieldTypes)
|
||||
|
||||
func solidityType*(_: type G2Point): string =
|
||||
solidityType(G2Point.fieldTypes)
|
||||
|
||||
|
@ -26,6 +33,9 @@ func solidityType*(_: type Groth16Proof): string =
|
|||
func encode*(encoder: var AbiEncoder, point: G1Point) =
|
||||
encoder.write(point.fieldValues)
|
||||
|
||||
func encode*(encoder: var AbiEncoder, element: Fp2Element) =
|
||||
encoder.write(element.fieldValues)
|
||||
|
||||
func encode*(encoder: var AbiEncoder, point: G2Point) =
|
||||
encoder.write(point.fieldValues)
|
||||
|
||||
|
|
|
@ -54,14 +54,14 @@ func toG1*(g: CircomG1): G1Point =
|
|||
|
||||
func toG2*(g: CircomG2): G2Point =
|
||||
G2Point(
|
||||
x: [
|
||||
UInt256.fromBytesLE(g.x[0]),
|
||||
UInt256.fromBytesLE(g.x[1])
|
||||
],
|
||||
y: [
|
||||
UInt256.fromBytesLE(g.y[0]),
|
||||
UInt256.fromBytesLE(g.y[1])
|
||||
])
|
||||
x: Fp2Element(
|
||||
real: UInt256.fromBytesLE(g.x[0]),
|
||||
imag: UInt256.fromBytesLE(g.x[1])
|
||||
),
|
||||
y: Fp2Element(
|
||||
real: UInt256.fromBytesLE(g.y[0]),
|
||||
imag: UInt256.fromBytesLE(g.y[1])
|
||||
))
|
||||
|
||||
func toGroth16Proof*(proof: CircomProof): Groth16Proof =
|
||||
Groth16Proof(
|
||||
|
|
|
@ -78,8 +78,8 @@ proc example(_: type G1Point): G1Point =
|
|||
|
||||
proc example(_: type G2Point): G2Point =
|
||||
G2Point(
|
||||
x: [UInt256.example, UInt256.example],
|
||||
y: [UInt256.example, UInt256.example]
|
||||
x: Fp2Element(real: UInt256.example, imag: UInt256.example),
|
||||
y: Fp2Element(real: UInt256.example, imag: UInt256.example)
|
||||
)
|
||||
|
||||
proc example*(_: type Groth16Proof): Groth16Proof =
|
||||
|
|
Loading…
Reference in New Issue