Reject unexpected binding sig during transaction write

This commit is contained in:
Jack Grigg 2018-11-30 00:51:05 +00:00
parent 61ce4dd3d6
commit 9b06205ed6
No known key found for this signature in database
GPG Key ID: 1B8D649257DB0829
5 changed files with 43 additions and 1 deletions

1
Cargo.lock generated
View File

@ -708,6 +708,7 @@ dependencies = [
"byteorder 1.2.2 (registry+https://github.com/rust-lang/crates.io-index)",
"lazy_static 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)",
"pairing 0.14.2",
"rand 0.4.2 (registry+https://github.com/rust-lang/crates.io-index)",
"sapling-crypto 0.0.1",
]

View File

@ -9,6 +9,7 @@ authors = [
byteorder = "1"
lazy_static = "1"
pairing = { path = "../pairing" }
rand = "0.4"
sapling-crypto = { path = "../sapling-crypto" }
[dependencies.blake2-rfc]

View File

@ -4,6 +4,7 @@ extern crate lazy_static;
extern crate blake2_rfc;
extern crate byteorder;
extern crate pairing;
extern crate rand;
extern crate sapling_crypto;
use sapling_crypto::jubjub::JubjubBls12;

View File

@ -211,6 +211,11 @@ impl Transaction {
))
}
}
} else if self.binding_sig.is_some() {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"Binding signature should not be present",
));
}
Ok(())

View File

@ -1,8 +1,13 @@
use pairing::bls12_381::Bls12;
use rand::{thread_rng, Rng};
use sapling_crypto::{jubjub::FixedGenerators, redjubjub::PrivateKey};
use super::{
components::{Amount, Script},
sighash::signature_hash,
Transaction,
Transaction, TransactionData,
};
use JUBJUB;
#[test]
fn tx_read_write() {
@ -151,6 +156,35 @@ fn tx_read_write() {
assert_eq!(&data[..], &encoded[..]);
}
#[test]
fn tx_write_rejects_unexpected_binding_sig() {
// Succeeds without a binding signature
{
let tx = TransactionData::new().freeze();
let mut encoded = Vec::new();
assert!(tx.write(&mut encoded).is_ok());
}
// Fails with an unexpected binding signature
{
let rng = &mut thread_rng();
let sk = PrivateKey::<Bls12>(rng.gen());
let sig = sk.sign(
b"Foo bar",
rng,
FixedGenerators::SpendingKeyGenerator,
&JUBJUB,
);
let mut tx = TransactionData::new();
tx.binding_sig = Some(sig);
let tx = tx.freeze();
let mut encoded = Vec::new();
assert!(tx.write(&mut encoded).is_err());
}
}
#[test]
fn zip_0143() {
struct TestVector {