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

Very basic EVM binary. #1574

Merged
merged 5 commits into from
Jul 11, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions ethcore/src/evm/evm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -95,11 +95,17 @@ impl<'a> Finalize for Result<GasLeft<'a>> {
}
}

/// Cost calculation type. For low-gas usage we calculate costs using usize instead of U256
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for 32-bit usize, this may lead to a consensus issue - u64 should be a lot safer.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why? If it doesn't fit in usize we fallback to U256 - it optimizes for u32 on 32-bit systems and for u64 for 64-bit ones.
Using optimized (whether it's u64 or u32) and non-optimized (u256) version should is not affecting consensus.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahh - fair enough.

pub trait CostType: ops::Mul<Output=Self> + ops::Div<Output=Self> + ops::Add<Output=Self> + ops::Sub<Output=Self> + ops::Shr<usize, Output=Self> + ops::Shl<usize, Output=Self> + cmp::Ord + Sized + From<usize> + Copy {
/// Converts this cost into `U256`
fn as_u256(&self) -> U256;
/// Tries to fit `U256` into this `Cost` type
fn from_u256(val: U256) -> Result<Self>;
/// Convert to usize (may panic)
fn as_usize(&self) -> usize;
/// Add with overflow
fn overflow_add(self, other: Self) -> (Self, bool);
/// Multiple with overflow
fn overflow_mul(self, other: Self) -> (Self, bool);
}

Expand Down
3 changes: 2 additions & 1 deletion ethcore/src/evm/interpreter/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
// You should have received a copy of the GNU General Public License
// along with Parity. If not, see <http://www.gnu.org/licenses/>.

///! Rust VM implementation
//! Rust VM implementation

#[cfg(not(feature = "evm-debug"))]
macro_rules! evm_debug {
Expand Down Expand Up @@ -182,6 +182,7 @@ impl<Cost: CostType> Interpreter<Cost> {
instruction: instruction
});
}

if info.tier == instructions::GasPriceTier::Invalid {
return Err(evm::Error::BadInstruction {
instruction: instruction
Expand Down
4 changes: 2 additions & 2 deletions ethcore/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,18 @@ pub mod pod_state;
pub mod engine;
pub mod migrations;
pub mod miner;
#[macro_use] pub mod evm;
pub mod action_params;

mod blooms;
mod db;
mod common;
mod basic_types;
#[macro_use] mod evm;
mod env_info;
mod pod_account;
mod state;
mod account;
mod account_db;
mod action_params;
mod null_engine;
mod builtin;
mod substate;
Expand Down
Loading