Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add RingVRF padding points #109

Merged
merged 1 commit into from
Nov 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 20 additions & 2 deletions bandersnatch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,9 +472,18 @@ pub unsafe extern "C" fn new_ring_vrf_verifier(
let public_keys_slice = std::slice::from_raw_parts(public_keys, public_keys_len);
let num_keys = public_keys_len / PUBLIC_KEY_LENGTH;

let padding_point = ring_context().padding_point();
let zero_chunk = [0u8; PUBLIC_KEY_LENGTH];
let ring: Vec<Public> = public_keys_slice
.chunks(PUBLIC_KEY_LENGTH)
.filter_map(|chunk| Public::deserialize_compressed(chunk).ok())
.map(|chunk| {
// Replace any zero'd out public keys with a padding point.
if chunk == zero_chunk {
Public::from(padding_point)
} else {
Public::deserialize_compressed(chunk).unwrap()
}
})
.collect();

if ring.len() != num_keys {
Expand Down Expand Up @@ -655,9 +664,18 @@ pub unsafe extern "C" fn new_ring_vrf_prover(

let num_keys = public_keys_len / PUBLIC_KEY_LENGTH;

let padding_point = ring_context().padding_point();
let zero_chunk = [0u8; PUBLIC_KEY_LENGTH];
let ring: Vec<Public> = public_keys_slice
.chunks(PUBLIC_KEY_LENGTH)
.filter_map(|chunk| Public::deserialize_compressed(chunk).ok())
.map(|chunk| {
// Replace any zero'd out public keys with a padding point.
if chunk == zero_chunk {
Public::from(padding_point)
} else {
Public::deserialize_compressed(chunk).unwrap()
}
})
.collect();

if ring.len() != num_keys {
Expand Down
5 changes: 5 additions & 0 deletions internal/crypto/bandersnatch/bandersnatch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,11 @@ func TestRingSignAndVerify(t *testing.T) {
ring = append(ring, pk)
}

// Including some zero'd out public keys that should be replaced with
// padding points.
ring[4] = crypto.BandersnatchPublicKey{}
ring[5] = crypto.BandersnatchPublicKey{}

var proverIdx uint = 3
proverSk, err := NewPrivateKeyFromSeed(uintToSeed(proverIdx))
require.NoError(t, err)
Expand Down
Loading