Skip to content
This repository has been archived by the owner on Nov 6, 2020. It is now read-only.

Commit

Permalink
Backporting #6686 and #6691 (#6712)
Browse files Browse the repository at this point in the history
* v1.7.4

* Fixed potential exp len overflow (#6686)

* Fix warp sync blockers detection
  • Loading branch information
arkpar authored Oct 11, 2017
1 parent 9afd100 commit a21db69
Show file tree
Hide file tree
Showing 8 changed files with 72 additions and 49 deletions.
50 changes: 25 additions & 25 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[package]
description = "Parity Ethereum client"
name = "parity"
version = "1.7.3"
version = "1.7.4"
license = "GPL-3.0"
authors = ["Parity Technologies <[email protected]>"]
build = "build.rs"
Expand Down
34 changes: 25 additions & 9 deletions ethcore/src/builtin.rs
Original file line number Diff line number Diff line change
Expand Up @@ -98,18 +98,17 @@ impl Pricer for ModexpPricer {
let exp_len = read_len();
let mod_len = read_len();

if mod_len.is_zero() && base_len.is_zero() {
return U256::zero()
}

let max_len = U256::from(u32::max_value() / 2);
if base_len > max_len || mod_len > max_len {
if base_len > max_len || mod_len > max_len || exp_len > max_len {
return U256::max_value();
}
let (base_len, exp_len, mod_len) = (base_len.low_u64(), exp_len.low_u64(), mod_len.low_u64());

let base_len = base_len.low_u64();
let exp_len = exp_len.low_u64();
let mod_len = mod_len.low_u64();
let m = max(mod_len, base_len);
if m == 0 {
return U256::zero();
}
// read fist 32-byte word of the exponent.
let exp_low = if base_len + 96 >= input.len() as u64 { U256::zero() } else {
let mut buf = [0; 32];
Expand All @@ -130,8 +129,7 @@ impl ModexpPricer {
let bit_index = if exp_low.is_zero() { 0 } else { (255 - exp_low.leading_zeros()) as u64 };
if len <= 32 {
bit_index
}
else {
} else {
8 * (len - 32) + bit_index
}
}
Expand Down Expand Up @@ -712,6 +710,24 @@ mod tests {
native: ethereum_builtin("modexp"),
activate_at: 0,
};

// test for potential exp len overflow
{
let input = FromHex::from_hex("\
00000000000000000000000000000000000000000000000000000000000000ff\
2a1e530000000000000000000000000000000000000000000000000000000000\
0000000000000000000000000000000000000000000000000000000000000000"
).unwrap();

let mut output = vec![0u8; 32];
let expected = FromHex::from_hex("0000000000000000000000000000000000000000000000000000000000000000").unwrap();
let expected_cost = U256::max_value();

f.execute(&input[..], &mut BytesRef::Fixed(&mut output[..])).expect("Builtin should fail");
assert_eq!(output, expected);
assert_eq!(f.cost(&input[..]), expected_cost.into());
}

// fermat's little theorem example.
{
let input = FromHex::from_hex("\
Expand Down
2 changes: 1 addition & 1 deletion mac/Parity.pkgproj
Original file line number Diff line number Diff line change
Expand Up @@ -462,7 +462,7 @@
<key>OVERWRITE_PERMISSIONS</key>
<false/>
<key>VERSION</key>
<string>1.7.3</string>
<string>1.7.4</string>
</dict>
<key>UUID</key>
<string>2DCD5B81-7BAF-4DA1-9251-6274B089FD36</string>
Expand Down
2 changes: 1 addition & 1 deletion nsis/installer.nsi
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
!define DESCRIPTION "Fast, light, robust Ethereum implementation"
!define VERSIONMAJOR 1
!define VERSIONMINOR 7
!define VERSIONBUILD 3
!define VERSIONBUILD 4
!define ARGS "--warp"
!define FIRST_START_ARGS "ui --warp --mode=passive"

Expand Down
12 changes: 2 additions & 10 deletions parity/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ use std::cmp::max;
use std::str::FromStr;
use cli::{Args, ArgsError};
use util::{Hashable, H256, U256, Bytes, version_data, Address};
use util::journaldb::Algorithm;
use util::Colour;
use ethsync::{NetworkConfiguration, is_valid_node_url, AllowIP};
use ethcore::ethstore::ethkey::{Secret, Public};
Expand All @@ -37,7 +36,7 @@ use parity_rpc::NetworkSettings;
use cache::CacheConfig;
use helpers::{to_duration, to_mode, to_block_id, to_u256, to_pending_set, to_price, replace_home, replace_home_and_local,
geth_ipc_path, parity_ipc_path, to_bootnodes, to_addresses, to_address, to_gas_limit, to_queue_strategy};
use params::{SpecType, ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras, Pruning, Switch};
use params::{SpecType, ResealPolicy, AccountsConfig, GasPricerConfig, MinerExtras};
use ethcore_logger::Config as LogConfig;
use dir::{self, Directories, default_hypervisor_path, default_local_path, default_data_path};
use dapps::Configuration as DappsConfiguration;
Expand Down Expand Up @@ -123,15 +122,8 @@ impl Configuration {
let fat_db = self.args.flag_fat_db.parse()?;
let compaction = self.args.flag_db_compaction.parse()?;
let wal = !self.args.flag_fast_and_loose;
match self.args.flag_warp {
// Logging is not initialized yet, so we print directly to stderr
Some(true) if fat_db == Switch::On => writeln!(&mut stderr(), "Warning: Warp Sync is disabled because Fat DB is turned on").expect("Error writing to stderr"),
Some(true) if tracing == Switch::On => writeln!(&mut stderr(), "Warning: Warp Sync is disabled because tracing is turned on").expect("Error writing to stderr"),
Some(true) if pruning == Pruning::Specific(Algorithm::Archive) => writeln!(&mut stderr(), "Warning: Warp Sync is disabled because pruning mode is set to archive").expect("Error writing to stderr"),
_ => {},
};
let public_node = self.args.flag_public_node;
let warp_sync = !self.args.flag_no_warp && fat_db != Switch::On && tracing != Switch::On && pruning != Pruning::Specific(Algorithm::Archive);
let warp_sync = !self.args.flag_no_warp;
let geth_compatibility = self.args.flag_geth;
let mut dapps_conf = self.dapps_config();
let ipfs_conf = self.ipfs_config();
Expand Down
17 changes: 16 additions & 1 deletion parity/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ use parity_reactor::EventLoop;
use parity_rpc::{NetworkSettings, informant, is_major_importing};
use updater::{UpdatePolicy, Updater};
use util::{Colour, version, Mutex, Condvar};
use util::journaldb::Algorithm;

use params::{
SpecType, Pruning, AccountsConfig, GasPricerConfig, MinerExtras, Switch,
Expand Down Expand Up @@ -474,7 +475,21 @@ pub fn execute(cmd: RunCmd, can_restart: bool, logger: Arc<RotatingLogger>) -> R
}

sync_config.fork_block = spec.fork_block();
sync_config.warp_sync = spec.engine.supports_warp() && cmd.warp_sync;
let mut warp_sync = cmd.warp_sync;
if warp_sync {
// Logging is not initialized yet, so we print directly to stderr
if fat_db {
warn!("Warning: Warp Sync is disabled because Fat DB is turned on.");
warp_sync = false;
} else if tracing {
warn!("Warning: Warp Sync is disabled because tracing is turned on.");
warp_sync = false;
} else if algorithm != Algorithm::OverlayRecent {
warn!("Warning: Warp Sync is disabled because of non-default pruning mode.");
warp_sync = false;
}
}
sync_config.warp_sync = spec.engine.supports_warp() && warp_sync;
sync_config.download_old_blocks = cmd.download_old_blocks;
sync_config.serve_light = cmd.serve_light;

Expand Down
2 changes: 1 addition & 1 deletion util/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description = "Ethcore utility library"
homepage = "http://parity.io"
license = "GPL-3.0"
name = "ethcore-util"
version = "1.7.3"
version = "1.7.4"
authors = ["Parity Technologies <[email protected]>"]
build = "build.rs"

Expand Down

0 comments on commit a21db69

Please sign in to comment.