Skip to content

Commit 2081af3

Browse files
Fix noir vote calldata parsing
1 parent 34e14b2 commit 2081af3

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

internal/service/api/handlers/vote_v3.go

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ type NoirVoteCalldata struct {
2929
ProposalID *big.Int
3030
Vote []*big.Int
3131
UserData biopassportvoting.BaseVotingUserData
32-
ZkPoints noirvoting.AQueryProofExecutorProofPoints
32+
ProofBytes []byte
3333
}
3434

3535
func VoteV3(w http.ResponseWriter, r *http.Request) {
@@ -179,45 +179,51 @@ func parseNoirCallData(data []byte) (NoirVoteCalldata, error) {
179179
return config, fmt.Errorf("failed to unpack noir calldata: %v", err)
180180
}
181181

182-
if len(decoded) != 6 {
183-
return config, fmt.Errorf("unexpected argument count, expected 6 got %d", len(decoded))
182+
if len(decoded) != 4 {
183+
return config, fmt.Errorf("unexpected argument count, expected 4 got %d", len(decoded))
184184
}
185185

186186
config.RegistrationRoot = decoded[0].([32]byte)
187187
config.CurrentDate = decoded[1].(*big.Int)
188-
config.ProposalID = decoded[2].(*big.Int)
189-
config.Vote = decoded[3].([]*big.Int)
190-
userDataRaw := decoded[4]
191-
192-
userDataStruct, ok := userDataRaw.(struct {
193-
Nullifier *big.Int `json:"nullifier"`
194-
Citizenship *big.Int `json:"citizenship"`
195-
IdentityCreationTimestamp *big.Int `json:"identityCreationTimestamp"`
188+
userDataEncoded := decoded[2].([]byte)
189+
config.ProofBytes = decoded[3].([]byte)
190+
191+
uint256Type, _ := abi.NewType("uint256", "", nil)
192+
uint256ArrayType, _ := abi.NewType("uint256[]", "", nil)
193+
tupleType, _ := abi.NewType("tuple", "", []abi.ArgumentMarshaling{
194+
{Name: "nullifier", Type: "uint256"},
195+
{Name: "citizenship", Type: "uint256"},
196+
{Name: "timestampUpperbound", Type: "uint256"},
196197
})
197-
if !ok {
198-
return config, fmt.Errorf("failed to cast userData_ to expected struct, got %T", userDataRaw)
198+
199+
userDataArguments := abi.Arguments{
200+
{Type: uint256Type},
201+
{Type: uint256ArrayType},
202+
{Type: tupleType},
199203
}
200204

201-
config.UserData = biopassportvoting.BaseVotingUserData{
202-
Nullifier: userDataStruct.Nullifier,
203-
Citizenship: userDataStruct.Citizenship,
204-
IdentityCreationTimestamp: userDataStruct.IdentityCreationTimestamp,
205+
userDataDecoded, err := userDataArguments.Unpack(userDataEncoded)
206+
if err != nil {
207+
return config, fmt.Errorf("failed to unpack userDataEncoded: %v", err)
205208
}
206209

207-
zkPointsRaw := decoded[5]
208-
zkPointsStruct, ok := zkPointsRaw.(struct {
209-
A [2]*big.Int `json:"a"`
210-
B [2][2]*big.Int `json:"b"`
211-
C [2]*big.Int `json:"c"`
212-
})
213-
if !ok {
214-
return config, fmt.Errorf("failed to cast zkPoints_ to expected struct, got %T", zkPointsRaw)
210+
if len(userDataDecoded) != 3 {
211+
return config, fmt.Errorf("invalid userDataEncoded structure")
215212
}
216213

217-
config.ZkPoints = noirvoting.AQueryProofExecutorProofPoints{
218-
A: zkPointsStruct.A,
219-
B: zkPointsStruct.B,
220-
C: zkPointsStruct.C,
214+
config.ProposalID = userDataDecoded[0].(*big.Int)
215+
config.Vote = userDataDecoded[1].([]*big.Int)
216+
217+
userDataTuple := userDataDecoded[2].(struct {
218+
Nullifier *big.Int `json:"nullifier"`
219+
Citizenship *big.Int `json:"citizenship"`
220+
TimestampUpperbound *big.Int `json:"timestampUpperbound"`
221+
})
222+
223+
config.UserData = biopassportvoting.BaseVotingUserData{
224+
Nullifier: userDataTuple.Nullifier,
225+
Citizenship: userDataTuple.Citizenship,
226+
IdentityCreationTimestamp: userDataTuple.TimestampUpperbound,
221227
}
222228

223229
return config, nil

0 commit comments

Comments
 (0)