Skip to content

Commit da14634

Browse files
yeastplumesuemto
authored andcommitted
(hopefully) fix random crashes + nightly + beta tests
1 parent e76908d commit da14634

File tree

1 file changed

+30
-30
lines changed

1 file changed

+30
-30
lines changed

src/pedersen.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -737,23 +737,20 @@ impl Secp256k1 {
737737
let blind_vec = map_vec!(blind_vec, |p| p.0.as_ptr());
738738
let n_bits = 64;
739739

740-
let (extra_data_len, extra_data) = match extra_data_in {
740+
let (extra_data_len, extra_data) = match extra_data_in.as_ref() {
741741
Some(d) => (d.len(), d.as_ptr()),
742742
None => (0, ptr::null()),
743743
};
744744

745-
let message_out = match message.clone() {
746-
Some(mut m) => {
745+
let mut message = message;
746+
let message_ptr = match message.as_mut() {
747+
Some(m) => {
747748
while m.len() < constants::BULLET_PROOF_MSG_SIZE {
748749
m.push(0u8);
749750
}
750751
m.truncate(constants::BULLET_PROOF_MSG_SIZE);
751-
m
752-
}
753-
None => ProofMessage::from_bytes(&[0u8; constants::BULLET_PROOF_MSG_SIZE]),
754-
};
755-
let message_ptr = match message {
756-
Some(_) => message_out.as_ptr(),
752+
m.as_ptr()
753+
},
757754
None => ptr::null(),
758755
};
759756

@@ -826,23 +823,20 @@ impl Secp256k1 {
826823
let blind_vec = map_vec!(blind_vec, |p| p.0.as_ptr());
827824
let n_bits = 64;
828825

829-
let (extra_data_len, extra_data) = match extra_data_in {
826+
let (extra_data_len, extra_data) = match extra_data_in.as_ref() {
830827
Some(d) => (d.len(), d.as_ptr()),
831828
None => (0, ptr::null()),
832829
};
833830

834-
let message_out = match message.clone() {
835-
Some(mut m) => {
831+
let mut message = message;
832+
let message_ptr = match message.as_mut() {
833+
Some(m) => {
836834
while m.len() < constants::BULLET_PROOF_MSG_SIZE {
837835
m.push(0u8);
838836
}
839837
m.truncate(constants::BULLET_PROOF_MSG_SIZE);
840-
m
841-
}
842-
None => ProofMessage::from_bytes(&[0u8; constants::BULLET_PROOF_MSG_SIZE]),
843-
};
844-
let message_ptr = match message {
845-
Some(_) => message_out.as_ptr(),
838+
m.as_ptr()
839+
},
846840
None => ptr::null(),
847841
};
848842

@@ -861,10 +855,12 @@ impl Secp256k1 {
861855
t_two_ptr = is_zero_pubkey!(retnone => t_two);
862856
};
863857

864-
let commits = if commits.len() > 0 {
865-
let commit_vec = map_vec!(commits, |c| self.commit_parse(c.0).unwrap());
866-
let commit_vec = map_vec!(commit_vec, |c| c.as_ptr());
867-
commit_vec.as_ptr()
858+
let commit_vec;
859+
let commit_ptr_vec;
860+
let commit_ptr_vec_ptr = if commits.len() > 0 {
861+
commit_vec = map_vec!(commits, |c| self.commit_parse(c.0).unwrap());
862+
commit_ptr_vec = map_vec!(commit_vec, |c| c.as_ptr());
863+
commit_ptr_vec.as_ptr()
868864
} else {
869865
ptr::null()
870866
};
@@ -896,7 +892,7 @@ impl Secp256k1 {
896892
&value,
897893
ptr::null(), // min_values: NULL for all-zeroes minimum values to prove ranges above
898894
blind_vec.as_ptr(),
899-
commits,
895+
commit_ptr_vec_ptr,
900896
1,
901897
constants::GENERATOR_H.as_ptr(),
902898
n_bits as size_t,
@@ -931,8 +927,12 @@ impl Secp256k1 {
931927
) -> Result<ProofRange, Error> {
932928
let n_bits = 64;
933929

930+
let extra_data;
934931
let (extra_data_len, extra_data) = match extra_data_in {
935-
Some(d) => (d.len(), d.as_ptr()),
932+
Some(d) => {
933+
extra_data = d;
934+
(extra_data.len(), extra_data.as_ptr())
935+
},
936936
None => (0, ptr::null()),
937937
};
938938

@@ -1006,13 +1006,13 @@ impl Secp256k1 {
10061006
};
10071007

10081008
// converting vec of vecs to expected pointer
1009-
let (extra_data_vec, extra_data_lengths) = {
1010-
if extra_data_in.is_some() {
1011-
let ed = extra_data_in.unwrap();
1009+
let (extra_data_vec, extra_data_lengths) = match extra_data_in.as_ref() {
1010+
Some(ed) => {
10121011
let extra_data_vec = map_vec!(ed, |d| d.as_ptr());
10131012
let extra_data_lengths = map_vec![ed, |d| d.len()];
10141013
(extra_data_vec, extra_data_lengths)
1015-
} else {
1014+
}
1015+
None => {
10161016
let extra_data_vec = vec![ptr::null(); proof_vec.len()];
10171017
let extra_data_lengths = vec![0; proof_vec.len()];
10181018
(extra_data_vec, extra_data_lengths)
@@ -1059,7 +1059,7 @@ impl Secp256k1 {
10591059
extra_data_in: Option<Vec<u8>>,
10601060
proof: RangeProof,
10611061
) -> Result<ProofInfo, Error> {
1062-
let (extra_data_len, extra_data) = match extra_data_in {
1062+
let (extra_data_len, extra_data) = match extra_data_in.as_ref() {
10631063
Some(d) => (d.len(), d.as_ptr()),
10641064
None => (0, ptr::null()),
10651065
};
@@ -1349,7 +1349,7 @@ mod tests {
13491349
}
13501350

13511351
#[test]
1352-
fn test_bullet_proof() {
1352+
fn test_bullet_proof_single() {
13531353
// Test Bulletproofs without message
13541354
let secp = Secp256k1::with_caps(ContextFlag::Commit);
13551355
let blinding = SecretKey::new(&secp, &mut thread_rng());

0 commit comments

Comments
 (0)