Remove optional 'from' field

This commit is contained in:
Greg Fitzgerald
2018-03-03 20:41:05 -07:00
parent ce60b960c0
commit 7cf0d55546
5 changed files with 10 additions and 10 deletions

View File

@ -87,7 +87,7 @@ impl Accountant {
} }
let event = Event::Transaction { let event = Event::Transaction {
from: Some(from), from,
to, to,
data, data,
sig, sig,

View File

@ -45,7 +45,7 @@ fn main() {
let now = Instant::now(); let now = Instant::now();
for &(k, s) in &sigs { for &(k, s) in &sigs {
let e = Event::Transaction { let e = Event::Transaction {
from: Some(alice_pubkey), from: alice_pubkey,
to: k, to: k,
data: one, data: one,
sig: s, sig: s,

View File

@ -30,7 +30,7 @@ pub type Signature = GenericArray<u8, U64>;
pub enum Event<T> { pub enum Event<T> {
Tick, Tick,
Transaction { Transaction {
from: Option<PublicKey>, from: PublicKey,
to: PublicKey, to: PublicKey,
data: T, data: T,
sig: Signature, sig: Signature,
@ -40,7 +40,7 @@ pub enum Event<T> {
impl<T> Event<T> { impl<T> Event<T> {
pub fn new_claim(to: PublicKey, data: T, sig: Signature) -> Self { pub fn new_claim(to: PublicKey, data: T, sig: Signature) -> Self {
Event::Transaction { Event::Transaction {
from: Some(to), from: to,
to, to,
data, data,
sig, sig,
@ -75,7 +75,7 @@ pub fn sign_transaction_data<T: Serialize>(
keypair: &Ed25519KeyPair, keypair: &Ed25519KeyPair,
to: &PublicKey, to: &PublicKey,
) -> Signature { ) -> Signature {
let from = &Some(get_pubkey(keypair)); let from = &get_pubkey(keypair);
sign_serialized(&(from, to, data), keypair) sign_serialized(&(from, to, data), keypair)
} }
@ -111,7 +111,7 @@ pub fn verify_event<T: Serialize>(event: &Event<T>) -> bool {
} = *event } = *event
{ {
let sign_data = serialize(&(&from, &to, &data)).unwrap(); let sign_data = serialize(&(&from, &to, &data)).unwrap();
if !verify_signature(&from.unwrap_or(to), &sign_data, &sig) { if !verify_signature(&from, &sign_data, &sig) {
return false; return false;
} }
} }

View File

@ -22,7 +22,7 @@ impl Creator {
} }
pub fn create_transaction(&self, keypair: &Ed25519KeyPair) -> Event<u64> { pub fn create_transaction(&self, keypair: &Ed25519KeyPair) -> Event<u64> {
let from = Some(get_pubkey(keypair)); let from = get_pubkey(keypair);
let to = self.pubkey; let to = self.pubkey;
let data = self.tokens; let data = self.tokens;
let sig = sign_transaction_data(&data, keypair, &to); let sig = sign_transaction_data(&data, keypair, &to);

View File

@ -255,7 +255,7 @@ mod tests {
let pubkey1 = get_pubkey(&keypair1); let pubkey1 = get_pubkey(&keypair1);
let data = hash(b"hello, world"); let data = hash(b"hello, world");
let event0 = Event::Transaction { let event0 = Event::Transaction {
from: Some(get_pubkey(&keypair0)), from: get_pubkey(&keypair0),
to: pubkey1, to: pubkey1,
data, data,
sig: sign_transaction_data(&data, &keypair0, &pubkey1), sig: sign_transaction_data(&data, &keypair0, &pubkey1),
@ -272,7 +272,7 @@ mod tests {
let pubkey1 = get_pubkey(&keypair1); let pubkey1 = get_pubkey(&keypair1);
let data = hash(b"hello, world"); let data = hash(b"hello, world");
let event0 = Event::Transaction { let event0 = Event::Transaction {
from: Some(get_pubkey(&keypair0)), from: get_pubkey(&keypair0),
to: pubkey1, to: pubkey1,
data: hash(b"goodbye cruel world"), // <-- attack! data: hash(b"goodbye cruel world"), // <-- attack!
sig: sign_transaction_data(&data, &keypair0, &pubkey1), sig: sign_transaction_data(&data, &keypair0, &pubkey1),
@ -290,7 +290,7 @@ mod tests {
let pubkey1 = get_pubkey(&keypair1); let pubkey1 = get_pubkey(&keypair1);
let data = hash(b"hello, world"); let data = hash(b"hello, world");
let event0 = Event::Transaction { let event0 = Event::Transaction {
from: Some(get_pubkey(&keypair0)), from: get_pubkey(&keypair0),
to: get_pubkey(&thief_keypair), // <-- attack! to: get_pubkey(&thief_keypair), // <-- attack!
data: hash(b"goodbye cruel world"), data: hash(b"goodbye cruel world"),
sig: sign_transaction_data(&data, &keypair0, &pubkey1), sig: sign_transaction_data(&data, &keypair0, &pubkey1),