Skip to content

Commit

Permalink
Merge pull request #20 from anoma/xuyang/update_binding_sign
Browse files Browse the repository at this point in the history
update cairo_binding_sig_sign
  • Loading branch information
XuyangSong authored Jul 30, 2024
2 parents 961910b + ccab865 commit 2a1e4ff
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/cairo.ex
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions native/cairo_prover/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -152,11 +152,11 @@ fn cairo_get_compliance_output(public_input: Vec<u8>) -> NifResult<Vec<Vec<u8>>>
// 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<Vec<u8>>, messages: Vec<Vec<u8>>) -> Vec<u8> {
fn cairo_binding_sig_sign(private_key_segments: Vec<u8>, messages: Vec<Vec<u8>>) -> Vec<u8> {
// 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)
Expand Down
11 changes: 8 additions & 3 deletions test/cairo_binding_signature.exs
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2a1e4ff

Please sign in to comment.