Skip to content

Commit

Permalink
Fixes marshalling of zk_ecip_hint values as big-endian byte arrays
Browse files Browse the repository at this point in the history
  • Loading branch information
raugfer committed Aug 19, 2024
1 parent 80c579e commit 52899cb
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 8 deletions.
6 changes: 5 additions & 1 deletion hydra/garaga/hints/ecip.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,12 @@ def zk_ecip_hint(
if ec_group_class == G1Point and use_rust:
pts = []
c_id = Bs[0].curve_id
if c_id == CurveID.BLS12_381:
nb = 48
else:
nb = 32
for pt in Bs:
pts.extend([pt.x, pt.y])
pts.extend([pt.x.to_bytes(nb, "big"), pt.y.to_bytes(nb, "big")])
field_type = get_field_type_from_ec_point(Bs[0])
field = get_base_field(c_id.value, field_type)

Expand Down
12 changes: 6 additions & 6 deletions tools/garaga_rs/src/ecip/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use num_bigint::{BigInt, BigUint, ToBigInt};
use super::curve::CurveParamsProvider;

pub fn zk_ecip_hint(
list_values: Vec<BigUint>,
list_values: Vec<Vec<u8>>,
list_scalars: Vec<BigUint>,
curve_id: usize,
) -> Result<[Vec<String>; 5], String> {
Expand All @@ -25,7 +25,7 @@ pub fn zk_ecip_hint(
let list_felts: Vec<FieldElement<BN254PrimeField>> = list_values
.into_iter()
.map(|x| {
FieldElement::<BN254PrimeField>::from_bytes_be(&x.to_bytes_be()).map_err(|e| {
FieldElement::<BN254PrimeField>::from_bytes_be(&x).map_err(|e| {
format!(
"Byte conversion error: {:?}",
e
Expand All @@ -46,7 +46,7 @@ pub fn zk_ecip_hint(
let list_felts: Vec<FieldElement<BLS12381PrimeField>> = list_values
.into_iter()
.map(|x| {
FieldElement::<BLS12381PrimeField>::from_bytes_be(&x.to_bytes_be()).map_err(|e| {
FieldElement::<BLS12381PrimeField>::from_bytes_be(&x).map_err(|e| {
format!(
"Byte conversion error: {:?}",
e
Expand All @@ -67,7 +67,7 @@ pub fn zk_ecip_hint(
let list_felts: Vec<FieldElement<SECP256K1PrimeField>> = list_values
.into_iter()
.map(|x| {
FieldElement::<SECP256K1PrimeField>::from_bytes_be(&x.to_bytes_be()).map_err(|e| {
FieldElement::<SECP256K1PrimeField>::from_bytes_be(&x).map_err(|e| {
format!(
"Byte conversion error: {:?}",
e
Expand All @@ -88,7 +88,7 @@ pub fn zk_ecip_hint(
let list_felts: Vec<FieldElement<SECP256R1PrimeField>> = list_values
.into_iter()
.map(|x| {
FieldElement::<SECP256R1PrimeField>::from_bytes_be(&x.to_bytes_be()).map_err(|e| {
FieldElement::<SECP256R1PrimeField>::from_bytes_be(&x).map_err(|e| {
format!(
"Byte conversion error: {:?}",
e
Expand All @@ -109,7 +109,7 @@ pub fn zk_ecip_hint(
let list_felts: Vec<FieldElement<X25519PrimeField>> = list_values
.into_iter()
.map(|x| {
FieldElement::<X25519PrimeField>::from_bytes_be(&x.to_bytes_be()).map_err(|e| {
FieldElement::<X25519PrimeField>::from_bytes_be(&x).map_err(|e| {
format!(
"Byte conversion error: {:?}",
e
Expand Down
2 changes: 1 addition & 1 deletion tools/garaga_rs/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub fn zk_ecip_hint(
let list_values = py_list_1
.into_iter()
.map(|x| x.extract())
.collect::<Result<Vec<BigUint>, _>>()?;
.collect::<Result<Vec<Vec<u8>>, _>>()?;

let list_scalars = py_list_2
.into_iter()
Expand Down

0 comments on commit 52899cb

Please sign in to comment.