Skip to content

Commit

Permalink
Add RingVRF padding points
Browse files Browse the repository at this point in the history
Zero'd out bandersnatch public keys need to be replaced with padding
points that actually exist on the curve.
  • Loading branch information
greywolve committed Nov 12, 2024
1 parent dc67bfa commit 3d50300
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
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

0 comments on commit 3d50300

Please sign in to comment.