forked from Consensys/gnark
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unmarshal.go
88 lines (74 loc) · 2.28 KB
/
unmarshal.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
package plonk
import (
"github.com/consensys/gnark-crypto/ecc/bn254"
"github.com/consensys/gnark-crypto/ecc/bn254/fr"
)
func UnmarshalSolidity(s []byte, nbCommits int) Proof {
var proof Proof
offset := 0
point_size := 64
fr_size := 32
proof.BatchedProof.ClaimedValues = make([]fr.Element, 7+nbCommits)
proof.Bsb22Commitments = make([]bn254.G1Affine, nbCommits)
// uint256 l_com_x;
// uint256 l_com_y;
// uint256 r_com_x;
// uint256 r_com_y;
// uint256 o_com_x;
// uint256 o_com_y;
for i := 0; i < 3; i++ {
proof.LRO[i].Unmarshal(s[offset : offset+point_size])
offset += point_size
}
// uint256 h_0_x;
// uint256 h_0_y;
// uint256 h_1_x;
// uint256 h_1_y;
// uint256 h_2_x;
// uint256 h_2_y;
for i := 0; i < 3; i++ {
proof.H[i].Unmarshal(s[offset : offset+point_size])
offset += point_size
}
// uint256 l_at_zeta;
// uint256 r_at_zeta;
// uint256 o_at_zeta;
// uint256 s1_at_zeta;
// uint256 s2_at_zeta;
for i := 2; i < 7; i++ {
proof.BatchedProof.ClaimedValues[i].SetBytes(s[offset : offset+fr_size])
offset += fr_size
}
// uint256 grand_product_commitment_x;
// uint256 grand_product_commitment_y;
proof.Z.Unmarshal(s[offset : offset+point_size])
offset += point_size
// uint256 grand_product_at_zeta_omega;
proof.ZShiftedOpening.ClaimedValue.SetBytes(s[offset : offset+fr_size])
offset += fr_size
// uint256 quotient_polynomial_at_zeta;
// uint256 linearization_polynomial_at_zeta;
proof.BatchedProof.ClaimedValues[0].SetBytes(s[offset : offset+fr_size])
offset += fr_size
proof.BatchedProof.ClaimedValues[1].SetBytes(s[offset : offset+fr_size])
offset += fr_size
// uint256 opening_at_zeta_proof_x;
// uint256 opening_at_zeta_proof_y;
proof.BatchedProof.H.Unmarshal(s[offset : offset+point_size])
offset += point_size
// uint256 opening_at_zeta_omega_proof_x;
// uint256 opening_at_zeta_omega_proof_y;
proof.ZShiftedOpening.H.Unmarshal(s[offset : offset+point_size])
offset += point_size
// uint256[] selector_commit_api_at_zeta;
// uint256[] wire_committed_commitments;
for i := 0; i < nbCommits; i++ {
proof.BatchedProof.ClaimedValues[7+i].SetBytes(s[offset : offset+fr_size])
offset += fr_size
}
for i := 0; i < nbCommits; i++ {
proof.Bsb22Commitments[i].Unmarshal(s[offset : offset+point_size])
offset += point_size
}
return proof
}