Skip to content

Commit

Permalink
Merge pull request #23 from axic/fix/bn-le
Browse files Browse the repository at this point in the history
Fix U128 and U256 initialization endianness
  • Loading branch information
axic authored May 15, 2019
2 parents 029e822 + 909c7d5 commit 1801a0f
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,15 +82,15 @@ impl vm::Ext for EwasmExt {
fn origin_balance(&self) -> Result<U256> {
// NOTE: used by SLEFDESTRUCT for gas metering (not used here now since we don't charge gas)
let origin = ewasm_api::tx_origin();
Ok(U256::from(U128::from(
ewasm_api::external_balance(&origin).bytes,
Ok(U256::from(U128::from_little_endian(
&ewasm_api::external_balance(&origin).bytes,
)))
}

/// Returns address balance.
fn balance(&self, address: &Address) -> Result<U256> {
Ok(U256::from(U128::from(
ewasm_api::external_balance(&Bytes20 { bytes: address.0 }).bytes,
Ok(U256::from(U128::from_little_endian(
&ewasm_api::external_balance(&Bytes20 { bytes: address.0 }).bytes,
)))
}

Expand Down Expand Up @@ -319,7 +319,7 @@ pub extern "C" fn main() {
params.address = params.code_address;
params.sender = Address::from(ewasm_api::caller().bytes);
params.origin = Address::from(ewasm_api::tx_origin().bytes);
params.gas_price = U256::from(U128::from(ewasm_api::tx_gas_price().bytes));
params.gas_price = U256::from(U128::from_little_endian(&ewasm_api::tx_gas_price().bytes));
// NOTE: there is no tx_gas_limit in the EEI
params.gas = U256::from(startgas);
params.data = Some(ewasm_api::calldata_acquire());
Expand All @@ -332,7 +332,7 @@ pub extern "C" fn main() {
// Set block environment information
// TODO: do this via lazy loading
ext.info.author = Address::from(ewasm_api::block_coinbase().bytes);
ext.info.difficulty = U256::from(ewasm_api::block_difficulty().bytes);
ext.info.difficulty = U256::from_little_endian(&ewasm_api::block_difficulty().bytes);
ext.info.number = ewasm_api::block_number();
ext.info.timestamp = ewasm_api::block_timestamp();
ext.info.gas_limit = U256::from(ewasm_api::block_gas_limit());
Expand Down

0 comments on commit 1801a0f

Please sign in to comment.