Commit 739c3da1 authored by Andronik Ordian's avatar Andronik Ordian

Revert "even more cleanup"

This reverts commit be29f032.
parent be29f032
Pipeline #71812 passed with stages
in 21 minutes and 5 seconds
......@@ -851,7 +851,7 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
return Err(ExecutionError::NotEnoughBaseGas { required: base_gas_required, got: t.gas });
}
if check_nonce && schedule.kill_dust != CleanDustMode::Off && !self.state.exists(&sender)? {
if !t.is_unsigned() && check_nonce && schedule.kill_dust != CleanDustMode::Off && !self.state.exists(&sender)? {
return Err(ExecutionError::SenderMustExist);
}
......@@ -884,8 +884,10 @@ impl<'a, B: 'a + StateBackend> Executive<'a, B> {
let mut substate = Substate::new();
self.state.inc_nonce(&sender)?;
// NOTE: there can be no invalid transactions from this point.
if !schedule.keep_unsigned_nonce || !t.is_unsigned() {
self.state.inc_nonce(&sender)?;
}
self.state.sub_balance(
&sender,
&U256::try_from(gas_cost).expect("Total cost (value + gas_cost) is lower than max allowed balance (U256); gas_cost has to fit U256; qed"),
......
......@@ -259,9 +259,9 @@ impl<'a, T: 'a, V: 'a, B: 'a> Ext for Externalities<'a, T, V, B>
};
if !self.static_flag {
if params.sender != UNSIGNED_SENDER {
if !self.schedule.keep_unsigned_nonce || params.sender != UNSIGNED_SENDER {
if let Err(e) = self.state.inc_nonce(&self.origin_info.address) {
warn!(target: "ext", "Database corruption encountered: {:?}", e);
debug!(target: "ext", "Database corruption encountered: {:?}", e);
return Ok(ContractCreateResult::Failed)
}
}
......
......@@ -316,6 +316,11 @@ impl UnverifiedTransaction {
self
}
/// Checks if the signature is empty.
pub fn is_unsigned(&self) -> bool {
self.r.is_zero() && self.s.is_zero()
}
/// Returns transaction receiver, if any
pub fn receiver(&self) -> Option<Address> {
match self.unsigned.action {
......@@ -352,6 +357,7 @@ impl UnverifiedTransaction {
/// The chain ID, or `None` if this is a global transaction.
pub fn chain_id(&self) -> Option<u64> {
match self.v {
v if self.is_unsigned() => Some(v),
v if v >= 35 => Some((v - 35) / 2),
_ => None,
}
......@@ -385,6 +391,9 @@ impl UnverifiedTransaction {
/// Verify basic signature params. Does not attempt sender recovery.
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());
}
if check_low_s {
self.check_low_s()?;
}
......@@ -430,6 +439,9 @@ impl From<SignedTransaction> for UnverifiedTransaction {
impl SignedTransaction {
/// Try to verify transaction and recover sender.
pub fn new(transaction: UnverifiedTransaction) -> Result<Self, parity_crypto::publickey::Error> {
if transaction.is_unsigned() {
return Err(parity_crypto::publickey::Error::InvalidSignature);
}
let public = transaction.recover_public()?;
let sender = public_to_address(&public);
Ok(SignedTransaction {
......@@ -449,6 +461,11 @@ impl SignedTransaction {
self.public
}
/// Checks is signature is empty.
pub fn is_unsigned(&self) -> bool {
self.transaction.is_unsigned()
}
/// Deconstructs this transaction back into `UnverifiedTransaction`
pub fn deconstruct(self) -> (UnverifiedTransaction, Address, Option<Public>) {
(self.transaction, self.sender, self.public)
......@@ -477,6 +494,9 @@ impl LocalizedTransaction {
if let Some(sender) = self.cached_sender {
return sender;
}
if self.is_unsigned() {
return UNSIGNED_SENDER.clone();
}
let sender = public_to_address(&self.recover_public()
.expect("LocalizedTransaction is always constructed from transaction from blockchain; Blockchain only stores verified transactions; qed"));
self.cached_sender = Some(sender);
......
......@@ -134,6 +134,8 @@ pub struct Schedule {
pub eip1283: bool,
/// Enable EIP-1706 rules
pub eip1706: bool,
/// VM execution does not increase null signed address nonce if this field is true.
pub keep_unsigned_nonce: bool,
/// Latest VM version for contract creation transaction.
pub latest_version: U256,
/// All supported non-legacy VM versions.
......@@ -274,6 +276,7 @@ impl Schedule {
kill_dust: CleanDustMode::Off,
eip1283: false,
eip1706: false,
keep_unsigned_nonce: false,
latest_version: U256::zero(),
versions: HashMap::new(),
wasm: None,
......@@ -364,6 +367,7 @@ impl Schedule {
kill_dust: CleanDustMode::Off,
eip1283: false,
eip1706: false,
keep_unsigned_nonce: false,
latest_version: U256::zero(),
versions: HashMap::new(),
wasm: None,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment