This repository has been archived by the owner on Nov 6, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1.7k
remove null signatures #11335
Merged
Merged
remove null signatures #11335
Changes from 5 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
3300e1e
tx: clean up legacy eip-86 based null signature
ordian 84602a9
tx: add a test for null signature rejection
ordian 746debe
tx: revert json txn changes
ordian 62adaa8
fix evmbin bench build
ordian 1dde478
tx: put UNSIGNED_SENDER behind 'test-helpers' feature
ordian 1023c8e
Revert "tx: put UNSIGNED_SENDER behind 'test-helpers' feature"
ordian 35d2b26
tx: add comment for null_sign
ordian be29f03
even more cleanup
ordian 739c3da
Revert "even more cleanup"
ordian File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,7 +31,8 @@ use transaction::error; | |
type Bytes = Vec<u8>; | ||
type BlockNumber = u64; | ||
|
||
/// Fake address for unsigned transactions as defined by EIP-86. | ||
/// Fake address for unsigned transactions as defined by Legacy EIP-86. | ||
#[cfg(any(test, feature = "test-helpers"))] | ||
pub const UNSIGNED_SENDER: Address = H160([0xff; 20]); | ||
|
||
/// System sender address for internal state updates. | ||
|
@@ -138,6 +139,7 @@ impl Transaction { | |
} | ||
} | ||
|
||
#[cfg(any(test, feature = "test-helpers"))] | ||
impl From<ethjson::transaction::Transaction> for SignedTransaction { | ||
fn from(t: ethjson::transaction::Transaction) -> Self { | ||
let to: Option<ethjson::hash::Address> = t.to.into(); | ||
|
@@ -237,7 +239,8 @@ impl Transaction { | |
} | ||
} | ||
|
||
/// Add EIP-86 compatible empty signature. | ||
/// Legacy EIP-86 compatible empty signature. | ||
#[cfg(any(test, feature = "test-helpers"))] | ||
pub fn null_sign(self, chain_id: u64) -> SignedTransaction { | ||
ordian marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SignedTransaction { | ||
transaction: UnverifiedTransaction { | ||
|
@@ -295,7 +298,7 @@ impl rlp::Decodable for UnverifiedTransaction { | |
v: d.val_at(6)?, | ||
r: d.val_at(7)?, | ||
s: d.val_at(8)?, | ||
hash: hash, | ||
hash, | ||
}) | ||
} | ||
} | ||
|
@@ -369,7 +372,7 @@ impl UnverifiedTransaction { | |
/// Checks whether the signature has a low 's' value. | ||
pub fn check_low_s(&self) -> Result<(), parity_crypto::publickey::Error> { | ||
if !self.signature().is_low_s() { | ||
Err(parity_crypto::publickey::Error::InvalidSignature.into()) | ||
Err(parity_crypto::publickey::Error::InvalidSignature) | ||
} else { | ||
Ok(()) | ||
} | ||
|
@@ -386,17 +389,12 @@ impl UnverifiedTransaction { | |
} | ||
|
||
/// Verify basic signature params. Does not attempt sender recovery. | ||
pub fn verify_basic(&self, check_low_s: bool, chain_id: Option<u64>, allow_empty_signature: bool) -> Result<(), error::Error> { | ||
if check_low_s && !(allow_empty_signature && self.is_unsigned()) { | ||
self.check_low_s()?; | ||
} | ||
// Disallow unsigned transactions in case EIP-86 is disabled. | ||
if !allow_empty_signature && self.is_unsigned() { | ||
pub fn verify_basic(&self, check_low_s: bool, chain_id: Option<u64>) -> Result<(), error::Error> { | ||
if self.is_unsigned() { | ||
return Err(parity_crypto::publickey::Error::InvalidSignature.into()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should we have a |
||
} | ||
// EIP-86: Transactions of this form MUST have gasprice = 0, nonce = 0, value = 0, and do NOT increment the nonce of account 0. | ||
if allow_empty_signature && self.is_unsigned() && !(self.gas_price.is_zero() && self.value.is_zero() && self.nonce.is_zero()) { | ||
return Err(parity_crypto::publickey::Error::InvalidSignature.into()) | ||
if check_low_s { | ||
self.check_low_s()?; | ||
} | ||
match (self.chain_id(), chain_id) { | ||
(None, _) => {}, | ||
|
@@ -441,20 +439,15 @@ impl SignedTransaction { | |
/// Try to verify transaction and recover sender. | ||
pub fn new(transaction: UnverifiedTransaction) -> Result<Self, parity_crypto::publickey::Error> { | ||
if transaction.is_unsigned() { | ||
Ok(SignedTransaction { | ||
transaction: transaction, | ||
sender: UNSIGNED_SENDER, | ||
dvdplm marked this conversation as resolved.
Show resolved
Hide resolved
|
||
public: None, | ||
}) | ||
} else { | ||
let public = transaction.recover_public()?; | ||
let sender = public_to_address(&public); | ||
Ok(SignedTransaction { | ||
transaction: transaction, | ||
sender: sender, | ||
public: Some(public), | ||
}) | ||
return Err(parity_crypto::publickey::Error::InvalidSignature); | ||
} | ||
let public = transaction.recover_public()?; | ||
let sender = public_to_address(&public); | ||
Ok(SignedTransaction { | ||
transaction, | ||
sender, | ||
public: Some(public), | ||
}) | ||
} | ||
|
||
/// Returns transaction sender. | ||
|
@@ -645,6 +638,24 @@ mod tests { | |
assert_eq!(t.chain_id(), None); | ||
} | ||
|
||
#[test] | ||
fn should_reject_null_signature() { | ||
let t = Transaction { | ||
nonce: U256::zero(), | ||
gas_price: U256::from(10000000000u64), | ||
gas: U256::from(21000), | ||
action: Action::Call(Address::from_str("d46e8dd67c5d32be8058bb8eb970870f07244567").unwrap()), | ||
value: U256::from(1), | ||
data: vec![] | ||
}.null_sign(1); | ||
|
||
let res = SignedTransaction::new(t.transaction); | ||
match res { | ||
Err(parity_crypto::publickey::Error::InvalidSignature) => {} | ||
_ => panic!("null signature should be rejected"), | ||
} | ||
} | ||
|
||
#[test] | ||
fn should_recover_from_chain_specific_signing() { | ||
use parity_crypto::publickey::{Random, Generator}; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not remove this entirely?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What to do with
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Option<>
fromcontract_address
- I suppose it will always be set toSome
.keep_unsigned_nonce
parameter from schedule, it's always set tofalse
anyway.fn is_unsigned
methods from all*Transaction
structs.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just checked and it seems 1. needs to stay, as it's being used by
block-reward
calls inside the engine, so let's leave it as is. So I guess we can keep the constant, but try to remove everything else.