diff --git a/lib/cairo.ex b/lib/cairo.ex index 0354748..3bd1a53 100644 --- a/lib/cairo.ex +++ b/lib/cairo.ex @@ -38,7 +38,7 @@ defmodule Cairo do to: Cairo.CairoProver, as: :cairo_get_compliance_output - @spec sign(list(list(byte())), list(list(byte()))) :: list(byte()) + @spec sign(list(byte()), list(list(byte()))) :: list(byte()) defdelegate sign(private_key_segments, messages), to: Cairo.CairoProver, as: :cairo_binding_sig_sign diff --git a/native/cairo_prover/src/lib.rs b/native/cairo_prover/src/lib.rs index b983340..ae95bc9 100644 --- a/native/cairo_prover/src/lib.rs +++ b/native/cairo_prover/src/lib.rs @@ -152,11 +152,11 @@ fn cairo_get_compliance_output(public_input: Vec) -> NifResult>> // The private_key_segments are random values used in delta commitments. // The messages are nullifiers and resource commitments in the transaction. #[rustler::nif] -fn cairo_binding_sig_sign(private_key_segments: Vec>, messages: Vec>) -> Vec { +fn cairo_binding_sig_sign(private_key_segments: Vec, messages: Vec>) -> Vec { // Compute private key let private_key = { let result = private_key_segments - .iter() + .chunks(32) .fold(BigInt::zero(), |acc, key_segment| { let key = BigInt::from_bytes_be(num_bigint::Sign::Plus, &key_segment); acc.add(key) diff --git a/test/cairo_binding_signature.exs b/test/cairo_binding_signature.exs index 512889e..bdff799 100644 --- a/test/cairo_binding_signature.exs +++ b/test/cairo_binding_signature.exs @@ -4,12 +4,17 @@ defmodule BindingSignatureTest do doctest Cairo.CairoProver test "cairo_binding_signature_test" do - priv_keys = [Cairo.random_felt(), Cairo.random_felt()] - pub_keys = priv_keys |> Enum.map(fn x -> Cairo.get_public_key(x) end) + priv_key_1 = Cairo.random_felt() + priv_key_2 = Cairo.random_felt() + + pub_keys = + [priv_key_1, priv_key_2] + |> Enum.map(fn x -> Cairo.get_public_key(x) end) + msg = [Cairo.random_felt(), Cairo.random_felt()] # Sign and verify - signature = Cairo.sign(priv_keys, msg) + signature = (priv_key_1 ++ priv_key_2) |> Cairo.sign(msg) assert true = Cairo.sig_verify(pub_keys, msg, signature) end end