Rename sig variables to signature

We'll avoid introducing three-letter terms to free up the namespace
for three-letter acronyms.

But recognize the term "sigverify", a verb, to verify a digital
signature.
This commit is contained in:
Greg Fitzgerald 2018-08-09 09:26:21 -06:00
parent 9d436fc5f8
commit 4a980568ac
10 changed files with 75 additions and 75 deletions

View File

@ -9,7 +9,7 @@ use solana::packet::{to_packets, PacketRecycler};
use solana::sigverify;
use solana::transaction::test_tx;
fn bench_sig_verify(bencher: &mut Bencher) {
fn bench_sigverify(bencher: &mut Bencher) {
let tx = test_tx();
// generate packet vector
@ -23,8 +23,8 @@ fn bench_sig_verify(bencher: &mut Bencher) {
}
fn bench(criterion: &mut Criterion) {
criterion.bench_function("bench_sig_verify", |bencher| {
bench_sig_verify(bencher);
criterion.bench_function("bench_sigverify", |bencher| {
bench_sigverify(bencher);
});
}

View File

@ -136,11 +136,11 @@ impl Bank {
}
/// Store the given signature. The bank will reject any transaction with the same signature.
fn reserve_signature(signatures: &mut HashSet<Signature>, sig: &Signature) -> Result<()> {
if let Some(sig) = signatures.get(sig) {
return Err(BankError::DuplicateSignature(*sig));
fn reserve_signature(signatures: &mut HashSet<Signature>, signature: &Signature) -> Result<()> {
if let Some(signature) = signatures.get(signature) {
return Err(BankError::DuplicateSignature(*signature));
}
signatures.insert(*sig);
signatures.insert(*signature);
Ok(())
}
@ -233,7 +233,7 @@ impl Bank {
}
let bal = option.unwrap();
self.reserve_signature_with_last_id(&tx.sig, &tx.last_id)?;
self.reserve_signature_with_last_id(&tx.signature, &tx.last_id)?;
if let Instruction::NewContract(contract) = &tx.instruction {
if contract.tokens < 0 {
@ -241,7 +241,7 @@ impl Bank {
}
if *bal < contract.tokens {
self.forget_signature_with_last_id(&tx.sig, &tx.last_id);
self.forget_signature_with_last_id(&tx.signature, &tx.last_id);
return Err(BankError::InsufficientFunds(tx.from));
} else if *bal == contract.tokens {
purge = true;
@ -271,14 +271,14 @@ impl Bank {
.pending
.write()
.expect("'pending' write lock in apply_credits");
pending.insert(tx.sig, plan);
pending.insert(tx.signature, plan);
}
}
Instruction::ApplyTimestamp(dt) => {
let _ = self.apply_timestamp(tx.from, *dt);
}
Instruction::ApplySignature(tx_sig) => {
let _ = self.apply_signature(tx.from, *tx_sig);
Instruction::ApplySignature(signature) => {
let _ = self.apply_signature(tx.from, *signature);
}
Instruction::NewVote(_vote) => {
trace!("GOT VOTE! last_id={:?}", &tx.last_id.as_ref()[..8]);
@ -470,12 +470,12 @@ impl Bank {
/// Process a Witness Signature. Any payment plans waiting on this signature
/// will progress one step.
fn apply_signature(&self, from: Pubkey, tx_sig: Signature) -> Result<()> {
fn apply_signature(&self, from: Pubkey, signature: Signature) -> Result<()> {
if let Occupied(mut e) = self
.pending
.write()
.expect("write() in apply_signature")
.entry(tx_sig)
.entry(signature)
{
e.get_mut().apply_witness(&Witness::Signature, &from);
if let Some(payment) = e.get().final_payment() {
@ -524,8 +524,8 @@ impl Bank {
last_id: Hash,
) -> Result<Signature> {
let tx = Transaction::new(keypair, to, n, last_id);
let sig = tx.sig;
self.process_transaction(&tx).map(|_| sig)
let signature = tx.signature;
self.process_transaction(&tx).map(|_| signature)
}
/// Create, sign, and process a postdated Transaction from `keypair`
@ -540,8 +540,8 @@ impl Bank {
last_id: Hash,
) -> Result<Signature> {
let tx = Transaction::new_on_date(keypair, to, dt, n, last_id);
let sig = tx.sig;
self.process_transaction(&tx).map(|_| sig)
let signature = tx.signature;
self.process_transaction(&tx).map(|_| signature)
}
pub fn get_balance(&self, pubkey: &Pubkey) -> i64 {
@ -692,7 +692,7 @@ mod tests {
let bank = Bank::new(&mint);
let pubkey = Keypair::new().pubkey();
let dt = Utc::now();
let sig = bank
let signature = bank
.transfer_on_date(1, &mint.keypair(), pubkey, dt, mint.last_id())
.unwrap();
@ -707,14 +707,14 @@ mod tests {
assert_eq!(bank.get_balance(&pubkey), 0);
// Now, cancel the trancaction. Mint gets her funds back, pubkey never sees them.
bank.apply_signature(mint.pubkey(), sig).unwrap();
bank.apply_signature(mint.pubkey(), signature).unwrap();
assert_eq!(bank.get_balance(&mint.pubkey()), 1);
assert_eq!(bank.get_balance(&pubkey), 0);
// Assert cancel doesn't cause count to go backward.
assert_eq!(bank.transaction_count(), 1);
bank.apply_signature(mint.pubkey(), sig).unwrap(); // <-- Attack! Attempt to cancel completed transaction.
bank.apply_signature(mint.pubkey(), signature).unwrap(); // <-- Attack! Attempt to cancel completed transaction.
assert_ne!(bank.get_balance(&mint.pubkey()), 2);
}
@ -722,14 +722,14 @@ mod tests {
fn test_duplicate_transaction_signature() {
let mint = Mint::new(1);
let bank = Bank::new(&mint);
let sig = Signature::default();
let signature = Signature::default();
assert!(
bank.reserve_signature_with_last_id(&sig, &mint.last_id())
bank.reserve_signature_with_last_id(&signature, &mint.last_id())
.is_ok()
);
assert_eq!(
bank.reserve_signature_with_last_id(&sig, &mint.last_id()),
Err(BankError::DuplicateSignature(sig))
bank.reserve_signature_with_last_id(&signature, &mint.last_id()),
Err(BankError::DuplicateSignature(signature))
);
}
@ -737,12 +737,12 @@ mod tests {
fn test_forget_signature() {
let mint = Mint::new(1);
let bank = Bank::new(&mint);
let sig = Signature::default();
bank.reserve_signature_with_last_id(&sig, &mint.last_id())
let signature = Signature::default();
bank.reserve_signature_with_last_id(&signature, &mint.last_id())
.unwrap();
bank.forget_signature_with_last_id(&sig, &mint.last_id());
bank.forget_signature_with_last_id(&signature, &mint.last_id());
assert!(
bank.reserve_signature_with_last_id(&sig, &mint.last_id())
bank.reserve_signature_with_last_id(&signature, &mint.last_id())
.is_ok()
);
}
@ -751,24 +751,24 @@ mod tests {
fn test_has_signature() {
let mint = Mint::new(1);
let bank = Bank::new(&mint);
let sig = Signature::default();
bank.reserve_signature_with_last_id(&sig, &mint.last_id())
let signature = Signature::default();
bank.reserve_signature_with_last_id(&signature, &mint.last_id())
.expect("reserve signature");
assert!(bank.has_signature(&sig));
assert!(bank.has_signature(&signature));
}
#[test]
fn test_reject_old_last_id() {
let mint = Mint::new(1);
let bank = Bank::new(&mint);
let sig = Signature::default();
let signature = Signature::default();
for i in 0..MAX_ENTRY_IDS {
let last_id = hash(&serialize(&i).unwrap()); // Unique hash
bank.register_entry_id(&last_id);
}
// Assert we're no longer able to use the oldest entry ID.
assert_eq!(
bank.reserve_signature_with_last_id(&sig, &mint.last_id()),
bank.reserve_signature_with_last_id(&signature, &mint.last_id()),
Err(BankError::LastIdNotFound(mint.last_id()))
);
}

View File

@ -122,11 +122,11 @@ fn send_barrier_transaction(barrier_client: &mut ThinClient, last_id: &mut Hash,
}
*last_id = barrier_client.get_last_id();
let sig = barrier_client
let signature = barrier_client
.transfer(0, &id, id.pubkey(), last_id)
.expect("Unable to send barrier transaction");
let confirmatiom = barrier_client.poll_for_signature(&sig);
let confirmatiom = barrier_client.poll_for_signature(&signature);
let duration_ms = duration_as_ms(&transfer_start.elapsed());
if confirmatiom.is_ok() {
println!("barrier transaction confirmed in {}ms", duration_ms);

View File

@ -191,13 +191,13 @@ fn parse_args() -> Result<WalletConfig, Box<error::Error>> {
Ok(WalletCommand::Pay(tokens, to))
}
("confirm", Some(confirm_matches)) => {
let sig_vec = bs58::decode(confirm_matches.value_of("signature").unwrap())
let signatures = bs58::decode(confirm_matches.value_of("signature").unwrap())
.into_vec()
.expect("base58-encoded signature");
if sig_vec.len() == std::mem::size_of::<Signature>() {
let sig = Signature::new(&sig_vec);
Ok(WalletCommand::Confirm(sig))
if signatures.len() == std::mem::size_of::<Signature>() {
let signature = Signature::new(&signatures);
Ok(WalletCommand::Confirm(signature))
} else {
eprintln!("{}", confirm_matches.usage());
Err(WalletError::BadParameter("Invalid signature".to_string()))
@ -276,12 +276,12 @@ fn process_command(
// If client has positive balance, spend tokens in {balance} number of transactions
WalletCommand::Pay(tokens, to) => {
let last_id = client.get_last_id();
let sig = client.transfer(tokens, &config.id, to, &last_id)?;
println!("{}", sig);
let signature = client.transfer(tokens, &config.id, to, &last_id)?;
println!("{}", signature);
}
// Confirm the last client transaction by signature
WalletCommand::Confirm(sig) => {
if client.check_signature(&sig) {
WalletCommand::Confirm(signature) => {
if client.check_signature(&signature) {
println!("Confirmed");
} else {
println!("Not found");

View File

@ -902,7 +902,7 @@ impl Crdt {
) {
trace!("got updates {}", data.len());
// TODO we need to punish/spam resist here
// sig verify the whole update and slash anyone who sends a bad update
// sigverify the whole update and slash anyone who sends a bad update
let mut insert_total = 0;
for v in data {
insert_total += self.insert(&v);

View File

@ -173,7 +173,7 @@ impl Entry {
fn add_transaction_data(hash_data: &mut Vec<u8>, tx: &Transaction) {
hash_data.push(0u8);
hash_data.extend_from_slice(&tx.sig.as_ref());
hash_data.extend_from_slice(&tx.signature.as_ref());
}
/// Creates the hash `num_hashes` after `start_hash`. If the transaction contains

View File

@ -48,11 +48,11 @@ impl Signature {
pub fn new(signature_slice: &[u8]) -> Self {
Signature(GenericArray::clone_from_slice(&signature_slice))
}
pub fn verify(&self, pubkey_bytes: &[u8], msg_bytes: &[u8]) -> bool {
pub fn verify(&self, pubkey_bytes: &[u8], message_bytes: &[u8]) -> bool {
let pubkey = Input::from(pubkey_bytes);
let msg = Input::from(msg_bytes);
let sig = Input::from(self.0.as_slice());
signature::verify(&signature::ED25519, pubkey, msg, sig).is_ok()
let message = Input::from(message_bytes);
let signature = Input::from(self.0.as_slice());
signature::verify(&signature::ED25519, pubkey, message, signature).is_ok()
}
}

View File

@ -138,7 +138,7 @@ pub fn ed25519_verify(batches: &[SharedPackets]) -> Vec<Vec<u8>> {
let count = batch_size(batches);
// micro-benchmarks show GPU time for smallest batch around 15-20ms
// and CPU speed for 64-128 sig verifies around 10-20ms. 64 is a nice
// and CPU speed for 64-128 sigverifies around 10-20ms. 64 is a nice
// power-of-two number around that accounting for the fact that the CPU
// may be busy doing other things while being a real fullnode
// TODO: dynamically adjust this crossover
@ -174,8 +174,8 @@ pub fn ed25519_verify(batches: &[SharedPackets]) -> Vec<Vec<u8>> {
trace!("Starting verify num packets: {}", num);
trace!("elem len: {}", elems.len() as u32);
trace!("packet sizeof: {}", size_of::<Packet>() as u32);
trace!("pub key: {}", (TX_OFFSET + PUB_KEY_OFFSET) as u32);
trace!("sig offset: {}", (TX_OFFSET + SIG_OFFSET) as u32);
trace!("pubkey: {}", (TX_OFFSET + PUB_KEY_OFFSET) as u32);
trace!("signature offset: {}", (TX_OFFSET + SIG_OFFSET) as u32);
trace!("sign data: {}", (TX_OFFSET + SIGNED_DATA_OFFSET) as u32);
trace!("len offset: {}", PACKET_DATA_SIZE as u32);
unsafe {

View File

@ -92,7 +92,7 @@ impl ThinClient {
let data = serialize(&tx).expect("serialize Transaction in pub fn transfer_signed");
self.transactions_socket
.send_to(&data, &self.transactions_addr)?;
Ok(tx.sig)
Ok(tx.signature)
}
/// Creates, signs, and processes a Transaction. Useful for writing unit-tests.
@ -227,9 +227,9 @@ impl ThinClient {
}
/// Poll the server to confirm a transaction.
pub fn poll_for_signature(&mut self, sig: &Signature) -> io::Result<()> {
pub fn poll_for_signature(&mut self, signature: &Signature) -> io::Result<()> {
let now = Instant::now();
while !self.check_signature(sig) {
while !self.check_signature(signature) {
if now.elapsed().as_secs() > 1 {
// TODO: Return a better error.
return Err(io::Error::new(io::ErrorKind::Other, "signature not found"));
@ -241,9 +241,9 @@ impl ThinClient {
/// Check a signature in the bank. This method blocks
/// until the server sends a response.
pub fn check_signature(&mut self, sig: &Signature) -> bool {
pub fn check_signature(&mut self, signature: &Signature) -> bool {
trace!("check_signature");
let req = Request::GetSignature { signature: *sig };
let req = Request::GetSignature { signature: *signature };
let data = serialize(&req).expect("serialize GetSignature in pub fn check_signature");
let now = Instant::now();
let mut done = false;
@ -342,10 +342,10 @@ mod tests {
transactions_socket,
);
let last_id = client.get_last_id();
let sig = client
let signature = client
.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
.unwrap();
client.poll_for_signature(&sig).unwrap();
client.poll_for_signature(&signature).unwrap();
let balance = client.get_balance(&bob_pubkey);
assert_eq!(balance.unwrap(), 500);
exit.store(true, Ordering::Relaxed);
@ -405,8 +405,8 @@ mod tests {
contract.tokens = 502;
contract.plan = Plan::Budget(Budget::new_payment(502, bob_pubkey));
}
let sig = client.transfer_signed(&tr2).unwrap();
client.poll_for_signature(&sig).unwrap();
let signature = client.transfer_signed(&tr2).unwrap();
client.poll_for_signature(&signature).unwrap();
let balance = client.get_balance(&bob_pubkey);
assert_eq!(balance.unwrap(), 500);
@ -452,12 +452,12 @@ mod tests {
transactions_socket,
);
let last_id = client.get_last_id();
let sig = client
let signature = client
.transfer(500, &alice.keypair(), bob_pubkey, &last_id)
.unwrap();
sleep(Duration::from_millis(100));
assert!(client.check_signature(&sig));
assert!(client.check_signature(&signature));
exit.store(true, Ordering::Relaxed);
server.join().unwrap();

View File

@ -79,7 +79,7 @@ pub enum Instruction {
#[derive(Serialize, Deserialize, Debug, PartialEq, Eq, Clone)]
pub struct Transaction {
/// A digital signature of `instruction`, `last_id` and `fee`, signed by `Pubkey`.
pub sig: Signature,
pub signature: Signature,
/// The `Pubkey` of the entity that signed the transaction data.
pub from: Pubkey,
@ -104,7 +104,7 @@ impl Transaction {
) -> Self {
let from = from_keypair.pubkey();
let mut tx = Transaction {
sig: Signature::default(),
signature: Signature::default(),
instruction,
last_id,
from,
@ -144,8 +144,8 @@ impl Transaction {
}
/// Create and sign a new Witness Signature. Used for unit-testing.
pub fn new_signature(from_keypair: &Keypair, tx_sig: Signature, last_id: Hash) -> Self {
let instruction = Instruction::ApplySignature(tx_sig);
pub fn new_signature(from_keypair: &Keypair, signature: Signature, last_id: Hash) -> Self {
let instruction = Instruction::ApplySignature(signature);
Self::new_from_instruction(from_keypair, instruction, last_id, 0)
}
@ -186,13 +186,13 @@ impl Transaction {
/// Sign this transaction.
pub fn sign(&mut self, keypair: &Keypair) {
let sign_data = self.get_sign_data();
self.sig = Signature::new(keypair.sign(&sign_data).as_ref());
self.signature = Signature::new(keypair.sign(&sign_data).as_ref());
}
/// Verify only the transaction signature.
pub fn verify_sig(&self) -> bool {
pub fn verify_signature(&self) -> bool {
warn!("transaction signature verification called");
self.sig.verify(&self.from.as_ref(), &self.get_sign_data())
self.signature.verify(&self.from.as_ref(), &self.get_sign_data())
}
/// Verify only the payment plan.
@ -271,7 +271,7 @@ mod tests {
instruction,
from: Default::default(),
last_id: Default::default(),
sig: Default::default(),
signature: Default::default(),
fee: 0,
};
let buf = serialize(&claim0).unwrap();
@ -292,7 +292,7 @@ mod tests {
}
}
assert!(tx.verify_plan());
assert!(!tx.verify_sig());
assert!(!tx.verify_signature());
}
#[test]
@ -309,7 +309,7 @@ mod tests {
}
}
assert!(tx.verify_plan());
assert!(!tx.verify_sig());
assert!(!tx.verify_signature());
}
#[test]
fn test_layout() {
@ -317,7 +317,7 @@ mod tests {
let sign_data = tx.get_sign_data();
let tx_bytes = serialize(&tx).unwrap();
assert_matches!(memfind(&tx_bytes, &sign_data), Some(SIGNED_DATA_OFFSET));
assert_matches!(memfind(&tx_bytes, &tx.sig.as_ref()), Some(SIG_OFFSET));
assert_matches!(memfind(&tx_bytes, &tx.signature.as_ref()), Some(SIG_OFFSET));
assert_matches!(memfind(&tx_bytes, &tx.from.as_ref()), Some(PUB_KEY_OFFSET));
}