Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some dependencies changes needed for smart contract testing. #1220

Merged
merged 9 commits into from
Aug 28, 2019
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
39 changes: 17 additions & 22 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 core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ edition = "2018"
[dependencies]
regex = "1"
bincode = { version = "1.0", features = ["i128"] }
bs58 = { git = "https://github.com/ilblackdragon/bs58-rs", rev = "46a818c93cd2ba19c2d5d9aefa8e3062ffb98d9b" }
bs58 = "0.2.4"
base64 = "0.10.1"
byteorder = "1.2"
chrono = { version = "0.4.4", features = ["serde"] }
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-runtime-fees/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-runtime-fees"
version = "0.2.0"
version = "0.2.1"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand Down
9 changes: 5 additions & 4 deletions runtime/near-vm-logic/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-vm-logic"
version = "0.2.0"
version = "0.2.3"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -14,9 +14,9 @@ This crate implements the specification of the interface that Near blockchain ex

[dependencies]
bs58 = "0.2.2"
sodiumoxide = "0.2.2"
sodiumoxide = { version = "0.2.2", optional = true }
serde = { version = "1.0", features = ["derive"] }
near-runtime-fees = { path = "../near-runtime-fees", version = "0.2.0" }
near-runtime-fees = { path = "../near-runtime-fees", version = "0.2.1" }

[[test]]
name = "test_registers"
Expand All @@ -25,5 +25,6 @@ required-features = ["mocks"]


[features]
default = []
# Mocks include some unsafe code to workaround lifetimes and therefore are optional.
mocks = []
mocks = ["sodiumoxide"]
2 changes: 2 additions & 0 deletions runtime/near-vm-logic/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,8 @@ pub trait External {
attached_deposit: Balance,
prepaid_gas: Gas,
) -> Result<ReceiptIndex>;

fn sha256(&self, data: &[u8]) -> Result<Vec<u8>>;
}

impl std::fmt::Display for ExternalError {
Expand Down
6 changes: 3 additions & 3 deletions runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -369,10 +369,10 @@ impl<'a> VMLogic<'a> {
/// If `value_len + value_ptr` points outside the memory or the registers use more memory than
/// the limit with `MemoryAccessViolation`.
pub fn sha256(&mut self, value_len: u64, value_ptr: u64, register_id: u64) -> Result<()> {
let Self { memory, registers, config, .. } = self;
let Self { memory, registers, config, ext, .. } = self;
let value = Self::memory_get(*memory, value_ptr, value_len)?;
let value_hash = sodiumoxide::crypto::hash::sha256::hash(&value);
Self::internal_write_register(registers, config, register_id, value_hash.as_ref())
let value_hash = ext.sha256(&value)?;
Self::internal_write_register(registers, config, register_id, &value_hash)
}

// ################
Expand Down
5 changes: 5 additions & 0 deletions runtime/near-vm-logic/src/mocks/mock_external.rs
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,11 @@ impl External for MockedExternal {
self.next_receipt_index += 1;
Ok(res)
}

fn sha256(&self, data: &[u8]) -> Result<Vec<u8>, ExternalError> {
let value_hash = sodiumoxide::crypto::hash::sha256::hash(data);
Ok(value_hash.as_ref().to_vec())
}
}

#[derive(Serialize, Deserialize, Clone)]
Expand Down
6 changes: 3 additions & 3 deletions runtime/near-vm-runner-standalone/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-vm-runner-standalone"
version = "0.2.0"
version = "0.2.4"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -21,5 +21,5 @@ to make sure it has expected behavior once deployed to the blockchain.
[dependencies]
serde_json = "1.0"
clap = "2.33.0"
near-vm-logic = { path = "../near-vm-logic", features = ["mocks"] }
near-vm-runner = { path = "../near-vm-runner" }
near-vm-logic = { path = "../near-vm-logic", features = ["mocks"], version = "0.2.3"}
near-vm-runner = { path = "../near-vm-runner", version = "0.2.4" }
6 changes: 3 additions & 3 deletions runtime/near-vm-runner/Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "near-vm-runner"
version = "0.2.1"
version = "0.2.4"
authors = ["Near Inc <hello@nearprotocol.com>"]
edition = "2018"
license = "Apache-2.0"
Expand All @@ -15,12 +15,12 @@ This crate implements the specification of the interface that Near blockchain ex
[dependencies]
cached = "0.9.0"
wasmer-runtime = { version = "0.5.7", features = ["singlepass"] }
near-vm-logic = { path="../near-vm-logic", version = "0.2.0"}
near-vm-logic = { path="../near-vm-logic", version = "0.2.3"}
pwasm-utils = "0.7.0"
parity-wasm = "0.31.3"

[dev-dependencies]
near-vm-logic = { path="../near-vm-logic", features=["mocks"], version = "0.2.0"}
near-vm-logic = { path="../near-vm-logic", features=["mocks"], version = "0.2.3"}
assert_matches = "1.3.0"
wabt = "0.7.4"
bencher = "0.1.5"
Expand Down
2 changes: 1 addition & 1 deletion runtime/near-vm-runner/src/prepare.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ impl<'a> ContractModule<'a> {
let Self { module, config } = self;
// TODO(#194): Re-enable .with_forbidden_floats() once AssemblyScript is fixed.
let gas_rules = rules::Set::new(config.regular_op_cost, Default::default())
.with_forbidden_floats()
// .with_forbidden_floats()
.with_grow_cost(config.grow_mem_cost);
let module = pwasm_utils::inject_gas_counter(module, &gas_rules)
.map_err(|_| PrepareError::GasInstrumentation)?;
Expand Down
1 change: 1 addition & 0 deletions runtime/runtime/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ rand = "0.6"
rand_xorshift = "0.1"
ethash = "0.3"
ethereum-bigint = "0.2"
sodiumoxide = "0.2.2"

near-primitives = { path = "../../core/primitives" }
near-store = { path = "../../core/store" }
Expand Down
5 changes: 5 additions & 0 deletions runtime/runtime/src/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -190,4 +190,9 @@ impl<'a> External for RuntimeExt<'a> {
self.action_receipts.push((receiver_id, new_receipt));
Ok(new_receipt_index)
}

fn sha256(&self, data: &[u8]) -> Result<Vec<u8>, ExternalError> {
let value_hash = sodiumoxide::crypto::hash::sha256::hash(data);
Ok(value_hash.as_ref().to_vec())
}
}