Skip to content

Commit

Permalink
Merge branch 'master' into fix-2071
Browse files Browse the repository at this point in the history
  • Loading branch information
ilblackdragon committed Feb 6, 2020
2 parents 1e8bafa + d8c9f6a commit 217cf87
Show file tree
Hide file tree
Showing 15 changed files with 322 additions and 6 deletions.
76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at social@nearprotocol.com. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
28 changes: 25 additions & 3 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 chain/client/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ rand = "0.7"
serde = { version = "1.0", features = ["derive"] }
serde_derive = "1.0"
serde_json = "1.0"
sysinfo = "0.10"
sysinfo = "0.10.5"
cached = "0.11.0"
lazy_static = "1.4"
borsh = "0.2.10"
Expand Down
3 changes: 2 additions & 1 deletion chain/client/src/info.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ use actix::Addr;
use ansi_term::Color::{Blue, Cyan, Green, White, Yellow};
use log::info;
use serde_json::json;
use sysinfo::{get_current_pid, Pid, ProcessExt, System, SystemExt};
use sysinfo::{get_current_pid, set_open_files_limit, Pid, ProcessExt, System, SystemExt};

use near_chain::Tip;
use near_network::types::{NetworkInfo, PeerId};
Expand Down Expand Up @@ -40,6 +40,7 @@ impl InfoHelper {
telemetry_actor: Addr<TelemetryActor>,
block_producer: Option<BlockProducer>,
) -> Self {
set_open_files_limit(0);
InfoHelper {
started: Instant::now(),
num_blocks_processed: 0,
Expand Down
6 changes: 5 additions & 1 deletion near/res/testnet.json

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

1 change: 1 addition & 0 deletions runtime/near-vm-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,3 +59,4 @@ path = "tests/test_iterators.rs"

[target.'cfg(not(target_arch = "wasm32"))'.dependencies]
sha2 = "0.8"
sha3 = "0.8"
26 changes: 26 additions & 0 deletions runtime/near-vm-logic/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -128,6 +128,16 @@ pub struct ExtCostsConfig {
/// Cost of getting sha256 per byte
pub sha256_byte: Gas,

/// Cost of getting sha256 base
pub keccak256_base: Gas,
/// Cost of getting sha256 per byte
pub keccak256_byte: Gas,

/// Cost of getting sha256 base
pub keccak512_base: Gas,
/// Cost of getting sha256 per byte
pub keccak512_byte: Gas,

/// Cost for calling logging.
pub log_base: Gas,
/// Cost for logging per byte
Expand Down Expand Up @@ -215,6 +225,10 @@ impl Default for ExtCostsConfig {
utf16_decoding_byte: 9095538,
sha256_base: 710092630,
sha256_byte: 5536829,
keccak256_base: 710092630,
keccak256_byte: 5536829,
keccak512_base: 710092630 * 2,
keccak512_byte: 5536829 * 2,
log_base: 0,
log_byte: 0,
storage_write_base: 21058769282,
Expand Down Expand Up @@ -263,6 +277,10 @@ impl ExtCostsConfig {
utf16_decoding_byte: 0,
sha256_base: 0,
sha256_byte: 0,
keccak256_base: 0,
keccak256_byte: 0,
keccak512_base: 0,
keccak512_byte: 0,
log_base: 0,
log_byte: 0,
storage_write_base: 0,
Expand Down Expand Up @@ -312,6 +330,10 @@ pub enum ExtCosts {
utf16_decoding_byte,
sha256_base,
sha256_byte,
keccak256_base,
keccak256_byte,
keccak512_base,
keccak512_byte,
log_base,
log_byte,
storage_write_base,
Expand Down Expand Up @@ -359,6 +381,10 @@ impl ExtCosts {
utf16_decoding_byte => config.utf16_decoding_byte,
sha256_base => config.sha256_base,
sha256_byte => config.sha256_byte,
keccak256_base => config.keccak256_base,
keccak256_byte => config.keccak256_byte,
keccak512_base => config.keccak512_base,
keccak512_byte => config.keccak512_byte,
log_base => config.log_base,
log_byte => config.log_byte,
storage_write_base => config.storage_write_base,
Expand Down
44 changes: 44 additions & 0 deletions runtime/near-vm-logic/src/dependencies.rs
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,50 @@ pub trait External {
/// ```
fn sha256(&self, data: &[u8]) -> Result<Vec<u8>>;

/// Computes keccak256 hash
///
/// # Arguments
///
/// * `data` - data to hash
///
/// # Example
/// ```
/// # use near_vm_logic::mocks::mock_external::MockedExternal;
/// # use near_vm_logic::External;
///
/// # let mut external = MockedExternal::new();
/// let result = external.keccak256(b"tesdsst").unwrap();
/// assert_eq!(&result, &[
/// 174, 42, 184, 134, 113, 104, 230, 180, 244, 77, 240, 72, 199, 42, 110, 178, 6, 168,
/// 121, 77, 27, 183, 153, 108, 197, 171, 78, 61, 186, 133, 193, 182
/// ]);
///
/// ```
fn keccak256(&self, data: &[u8]) -> Result<Vec<u8>>;

/// Computes keccak512 hash
///
/// # Arguments
///
/// * `data` - data to hash
///
/// # Example
/// ```
/// # use near_vm_logic::mocks::mock_external::MockedExternal;
/// # use near_vm_logic::External;
///
/// # let mut external = MockedExternal::new();
/// let result = external.keccak512(b"tesdsst").unwrap();
/// assert_eq!(&result, &[
/// 133, 196, 48, 30, 203, 238, 194, 158, 186, 246, 118, 238, 42, 158, 212, 27, 178, 72,
/// 90, 229, 98, 108, 195, 221, 222, 161, 96, 219, 252, 99, 2, 48, 224, 15, 95, 220, 35,
/// 209, 27, 250, 43, 168, 250, 10, 21, 25, 97, 135, 235, 61, 5, 142, 182, 85, 36, 179,
/// 23, 126, 161, 14, 21, 118, 180, 231
/// ].to_vec());
///
/// ```
fn keccak512(&self, data: &[u8]) -> Result<Vec<u8>>;

/// Returns amount of touched trie nodes by storage operations
fn get_touched_nodes_count(&self) -> u64;

Expand Down
36 changes: 36 additions & 0 deletions runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -645,6 +645,42 @@ impl<'a> VMLogic<'a> {
self.internal_write_register(register_id, value_hash)
}

/// Hashes the random sequence of bytes using keccak256 and returns it into `register_id`.
///
/// # Errors
///
/// If `value_len + value_ptr` points outside the memory or the registers use more memory than
/// the limit with `MemoryAccessViolation`.
///
/// # Cost
///
/// `base + write_register_base + write_register_byte * num_bytes + keccak256_base + keccak256_byte * num_bytes`
pub fn keccak256(&mut self, value_len: u64, value_ptr: u64, register_id: u64) -> Result<()> {
self.gas_counter.pay_base(keccak256_base)?;
let value = self.get_vec_from_memory_or_register(value_ptr, value_len)?;
self.gas_counter.pay_per_byte(keccak256_byte, value.len() as u64)?;
let value_hash = self.ext.keccak256(&value)?;
self.internal_write_register(register_id, value_hash)
}

/// Hashes the random sequence of bytes using keccak512 and returns it into `register_id`.
///
/// # Errors
///
/// If `value_len + value_ptr` points outside the memory or the registers use more memory than
/// the limit with `MemoryAccessViolation`.
///
/// # Cost
///
/// `base + write_register_base + write_register_byte * num_bytes + keccak512_base + keccak512_byte * num_bytes`
pub fn keccak512(&mut self, value_len: u64, value_ptr: u64, register_id: u64) -> Result<()> {
self.gas_counter.pay_base(keccak512_base)?;
let value = self.get_vec_from_memory_or_register(value_ptr, value_len)?;
self.gas_counter.pay_per_byte(keccak512_byte, value.len() as u64)?;
let value_hash = self.ext.keccak512(&value)?;
self.internal_write_register(register_id, value_hash)
}

/// Called by gas metering injected into Wasm. Counts both towards `burnt_gas` and `used_gas`.
///
/// # Errors
Expand Down
Loading

0 comments on commit 217cf87

Please sign in to comment.