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

Math API ecrecover and ripemd160 extension #4380

Merged
merged 163 commits into from
Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from 125 commits
Commits
Show all changes
163 commits
Select commit Hold shift + click to select a range
4101d54
feat: Extend the Math API with EVM precompiles.
artob Feb 12, 2021
f1129da
feat: Add Math API stubs for ECRecover. (#3921)
artob Feb 17, 2021
55291ee
test: Add RIPEMD-160 and BLAKE2b to the params estimator.
artob Feb 17, 2021
e4aedd6
fix: Improve error output from the params estimator.
artob Feb 17, 2021
4b145d1
test: Add ECRecover stubs to the params estimator.
artob Feb 18, 2021
f8461f7
fix: Widen ecrecover() parameter type to pass CI checks.
artob Feb 18, 2021
becf003
feat(chain): Bump the protocol version.
artob Feb 18, 2021
4950ad3
feat(runtime): Implement ECRecover in the Math API. (#3921)
artob Feb 19, 2021
a5bbe0b
docs: Document the ecrecover() function.
artob Feb 19, 2021
2f88193
fix(chain): Guard protocol upgrade behind EVM feature.
artob Feb 19, 2021
e97e6c6
add crypto feature gates
joshuajbouw Mar 10, 2021
acb1440
fix nightly compile
joshuajbouw Mar 11, 2021
773d818
cargo fmt
joshuajbouw Mar 11, 2021
bdc0495
fix two ripemd160 missing feature gates
joshuajbouw Mar 11, 2021
b55fa0f
rename crypto_extras feature to protocol_feature equivalents
joshuajbouw Mar 12, 2021
e6c389f
change repo to our git
joshuajbouw Mar 19, 2021
fd0022a
put everything under protocol_feature_evm
joshuajbouw Mar 19, 2021
c1d77f0
point to alternative blake2 branch temporarily
joshuajbouw Mar 19, 2021
f7ec5b1
Add blake2b f function
joshuajbouw Mar 19, 2021
598b0c5
add blake2b_f to config
joshuajbouw Mar 23, 2021
16a32c8
post rebase fixes
joshuajbouw Mar 23, 2021
e2b5e59
wrap all ext_costs in evm feature
joshuajbouw Mar 23, 2021
ca3e329
add blake_2b_f to runtime estimator
joshuajbouw Mar 23, 2021
188b9b8
cargo fmt
joshuajbouw Mar 23, 2021
b0236f5
add new hash algos to feature
joshuajbouw Mar 24, 2021
8945af7
add vm-logic test for blake2b_f
joshuajbouw Mar 24, 2021
78ec861
fix derive formatting
joshuajbouw Mar 24, 2021
075e6be
use same blake2 library
joshuajbouw Mar 24, 2021
d53a580
change blake F tests to test 1 round
joshuajbouw Mar 24, 2021
8da8c49
fix blake f test
joshuajbouw Mar 24, 2021
9f3358c
cleanup calls_helper
joshuajbouw Mar 24, 2021
5ac0d32
add missing feature gated fields from ExtCostsConfig
joshuajbouw Mar 25, 2021
1c9ba91
add blake2b_f compression docs
joshuajbouw Mar 26, 2021
6872025
remove unused `blake2b_f_byte` as sizes are fixed
joshuajbouw Mar 26, 2021
6704cad
add missing blake2b_f to imports
joshuajbouw Mar 26, 2021
36bbc37
runtime estimator mod docs
joshuajbouw Mar 26, 2021
e971fe3
Add near-blake2 lib to near-crypto
joshuajbouw May 19, 2021
10f356f
fix test imports
joshuajbouw May 20, 2021
0fca391
add more pub methods to blake2
joshuajbouw May 21, 2021
83a1d11
add blake2 state success tests
joshuajbouw May 21, 2021
bdc0904
cargo fmt
joshuajbouw May 21, 2021
7dbcfdb
Add initial blake2 logic to vm
joshuajbouw May 21, 2021
ee2d0f6
Fix ecrecover
birchmd Apr 30, 2021
ebf64bc
Change blake2 `update` to `update_inner`
joshuajbouw May 21, 2021
bffa864
Update params estimator
joshuajbouw May 21, 2021
bce76f3
Remove duplicate evm feature
joshuajbouw May 21, 2021
6b5d85c
Merge branch 'master' into evm-math-api
joshuajbouw May 21, 2021
ac9982d
Remove pattern
joshuajbouw May 21, 2021
55dda77
Fix some compilation errors
birchmd May 21, 2021
77f1b2a
Fix runtime-params-estimator compile
birchmd May 21, 2021
d461c3b
Fix tests
joshuajbouw May 24, 2021
6207f4b
Reduce blake2s param estimator rounds from 12 to 10
joshuajbouw May 25, 2021
3b4c098
Add protocol_feature_evm feature to standalone runner
joshuajbouw May 25, 2021
6851665
Merge branch 'master' into evm-math-api
joshuajbouw May 26, 2021
355b997
Merge branch 'master' into evm-math-api
joshuajbouw May 27, 2021
9d84a33
Add estimated gas values
joshuajbouw May 27, 2021
6a57744
Merge remote-tracking branch 'upstream/evm-math-api' into evm-math-api
joshuajbouw May 27, 2021
e0cddbb
Update estimated gas value note
joshuajbouw May 27, 2021
15e9ecc
cargo fmt
joshuajbouw May 27, 2021
6c21c78
Update c2-chacha
joshuajbouw May 27, 2021
4483cd4
Remove nightly features from lib blake2
joshuajbouw May 27, 2021
4a1c26e
Add blake2 pass tests
joshuajbouw May 27, 2021
bcc7dd2
Fix up ecrecover test
joshuajbouw May 27, 2021
2f7cd2f
Fix blake2s args
joshuajbouw May 27, 2021
1dc1090
Merge branch 'master' into evm-math-api
joshuajbouw May 31, 2021
9a9fd8a
Merge remote-tracking branch 'upstream/master' into evm-math-api
joshuajbouw Jun 2, 2021
844da2e
Remove blake2 lib
joshuajbouw Jun 2, 2021
9f13b1e
Update documentation for blake2
joshuajbouw Jun 2, 2021
76e2a2e
Pin comment for blake2 lib
joshuajbouw Jun 2, 2021
ec72a48
Fix with_state
joshuajbouw Jun 4, 2021
276523e
Merge remote-tracking branch 'upstream/master' into evm-math-api
joshuajbouw Jun 11, 2021
e395b1c
Return a bool for ecrecover, not abort
joshuajbouw Jun 11, 2021
fe76336
Fix VarBlake2b -> VarBlake2s
joshuajbouw Jun 11, 2021
bda2e42
Add errors to RPC errors schema
joshuajbouw Jun 11, 2021
cf61d15
Add bool return to wrapped imports
joshuajbouw Jun 11, 2021
b61e89d
Merge remote-tracking branch 'upstream/master' into evm-math-api
joshuajbouw Jun 11, 2021
c59b121
Merge branch 'master' into evm-math-api
joshuajbouw Jun 14, 2021
23cd417
Take t0 and t1 for blake2b
joshuajbouw Jun 14, 2021
48fb8dd
Charge ripemd160 by blocks, not bytes
joshuajbouw Jun 14, 2021
f985379
Correctly send both t0 and t1 to blake2
joshuajbouw Jun 15, 2021
93240c6
Remove too many rounds error
joshuajbouw Jun 15, 2021
764f4a1
Remove any near-blake2 errors
joshuajbouw Jun 15, 2021
8be6dac
Remove hash data overflow error
joshuajbouw Jun 15, 2021
b58d765
Rename Blake2InvalidStateLength -> Blake2StateLengthExceeded
joshuajbouw Jun 15, 2021
1410e6d
Small ecrecover clarifications
joshuajbouw Jun 19, 2021
0210eab
Return public key in ecrecover
joshuajbouw Jun 19, 2021
4f82dc9
Correct blake2 message block math
joshuajbouw Jun 19, 2021
c79cd20
Correct ripemd160 message block math
joshuajbouw Jun 19, 2021
98ae102
Read blake2s as u32 not u64
joshuajbouw Jun 19, 2021
6db1324
Remove `state_len` and blake2 len error
joshuajbouw Jun 19, 2021
ed8b9c8
Add `saturating_mul` to blake2 math
joshuajbouw Jun 19, 2021
fa448b1
Don't allocate an extra vec on blake2
joshuajbouw Jun 19, 2021
72273d2
Merge branch 'master' into evm-math-api
joshuajbouw Jun 19, 2021
60a426b
Remove unused import
joshuajbouw Jun 19, 2021
c1eba41
Fix args in wrapped imports
joshuajbouw Jun 19, 2021
881aaee
Fix blake2s test
joshuajbouw Jun 19, 2021
db7f3aa
Merge branch 'evm-math-api' into feat/evm/math-extension
joshuajbouw Jun 20, 2021
08d50cb
Remove blake2 and added protocol_feature_evm conditional comps
joshuajbouw Jun 20, 2021
2d1ae30
Remove optional from crypto imports in logic
joshuajbouw Jun 20, 2021
951e767
Revert from near-blake2 to upstream blake2
joshuajbouw Jun 20, 2021
9a3f924
Drop libsecp256k1 crate in favour of near-crypto
joshuajbouw Jun 20, 2021
7f3114b
Improve code quality by using U256
joshuajbouw Jun 20, 2021
434145b
Pass hash_bytes as ref
joshuajbouw Jun 21, 2021
9c28150
Revert "Pass hash_bytes as ref"
joshuajbouw Jun 21, 2021
7f1c296
matklad nit
joshuajbouw Jun 21, 2021
8c9341f
Fix ecrecover exports arg sig
joshuajbouw Jun 21, 2021
0acaa67
Move when malleability check happens
joshuajbouw Jun 21, 2021
8bb840b
Remove last check in signature values
joshuajbouw Jun 21, 2021
bea8361
Don't use `v` in a check, now unused
joshuajbouw Jun 21, 2021
211db82
Update description of ripemd160 with correct cost
joshuajbouw Jun 21, 2021
f6d566a
Use u32 for malleability_flag
birchmd Jun 23, 2021
3f08a35
Introduce protocol_feature_math_extension
birchmd Jun 23, 2021
4ceab99
Use our own div_ceil implementation
birchmd Jun 23, 2021
884d714
Include protocol_feature_math_extension in runtime-params-estimator/n…
birchmd Jun 23, 2021
402fa8f
Nightly protocol version bump
birchmd Jun 23, 2021
b778a93
Merge branch 'master' into feat/evm/math-extension
birchmd Jun 23, 2021
aa1b8c5
Simplify message_blocks computation
birchmd Jun 23, 2021
1ec6416
Remove unused div_ceil function
birchmd Jun 23, 2021
b572bdc
Ignore first byte of result
joshuajbouw Jun 24, 2021
a7ee788
Remove uneeded return at end of function
joshuajbouw Jun 24, 2021
1f2a314
Remove check_v and add in option to skip reject upper range
joshuajbouw Jun 24, 2021
1405c91
Use `get_vec_from_memory_or_register` over `memory_get_into`
joshuajbouw Jun 24, 2021
8c3de8a
Remove unused
joshuajbouw Jun 24, 2021
3c4144b
Separate `v`, change args to `u64`
joshuajbouw Jun 24, 2021
395ad53
Remove redundant check
joshuajbouw Jun 24, 2021
b0d02f5
Merge branch 'master' into feat/evm/math-extension
joshuajbouw Jun 24, 2021
20252a1
64th byte, not 65
joshuajbouw Jun 24, 2021
2e4742e
Fix test
joshuajbouw Jun 24, 2021
88fd6aa
Update doc cost
joshuajbouw Jun 24, 2021
9d58f32
Fix estimator
joshuajbouw Jun 24, 2021
2fe75e8
Small fixes
joshuajbouw Jun 24, 2021
fe31431
Add missing feature `protocol_feature_math_extension` from neard
joshuajbouw Jun 24, 2021
d937efb
Merge branch 'master' into feat/evm/math-extension
joshuajbouw Jun 24, 2021
7ca7285
Add near-primitives to math extension params estimator
joshuajbouw Jun 24, 2021
d9684df
Fix byte length
joshuajbouw Jun 24, 2021
1211d9c
Fix Cargo.toml
Jun 24, 2021
5c722b2
Nit. Typos
Jun 24, 2021
b17bddb
Nit. param estimator is missing feature dependency
Jun 24, 2021
4710683
Add feature support for build.sh of test-contract
Jun 25, 2021
7b06eb7
Merge branch 'master' into feat/evm/math-extension
joshuajbouw Jun 25, 2021
585a973
Merge branch 'master' into feat/evm/math-extension
joshuajbouw Jun 25, 2021
e5f7468
Add consts for SECP256K1 malleability values
joshuajbouw Jun 25, 2021
e6d926b
Merge remote-tracking branch 'origin/feat/evm/math-extension' into fe…
joshuajbouw Jun 25, 2021
2091bfa
Remove map err, change to unwrap
joshuajbouw Jun 25, 2021
bdc9066
Change v check to something more simple
joshuajbouw Jun 25, 2021
5e76c8b
Always do signature check
joshuajbouw Jun 25, 2021
ca62541
Merge remote-tracking branch 'upstream/master' into feat/evm/math-ext…
joshuajbouw Jun 25, 2021
38fc362
Check one s bound
joshuajbouw Jun 25, 2021
43aa88b
Allow for specifying a register
joshuajbouw Jun 25, 2021
ac53dcb
Remove math extension feature from primitives core
joshuajbouw Jun 25, 2021
2c4a48b
Nit. Convering byte to bool
Jun 26, 2021
210ee55
Add measuring support.
olonho Jun 26, 2021
f25fe99
Revert "Remove math extension feature from primitives core"
joshuajbouw Jun 25, 2021
429f18b
Const SECP256K1 half + 1
joshuajbouw Jun 29, 2021
3f449d5
Merge remote-tracking branch 'upstream/master' into feat/evm/math-ext…
joshuajbouw Jun 29, 2021
a7868e8
Revert "Add measuring support."
joshuajbouw Jun 29, 2021
23f91e8
Update gas costs with correct values
joshuajbouw Jun 29, 2021
77e25de
Nit. Method signature typo causing runtime failure
Jun 29, 2021
037289f
Fix fee. It seems like a copy-paste typo
Jun 29, 2021
d09099e
Undo the wrong fix
Jun 29, 2021
73380e1
Add malleability_flag check as requested in https://github.com/near/n…
Jun 29, 2021
07ca301
Merge branch 'master' into feat/evm/math-extension
bowenwang1996 Jun 30, 2021
14b9869
syntax fix
bowenwang1996 Jun 30, 2021
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
7 changes: 5 additions & 2 deletions Cargo.lock

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

1 change: 1 addition & 0 deletions core/crypto/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ c2-chacha = "0.3"
curve25519-dalek = "3"
derive_more = "0.99.9"
ed25519-dalek = "1"
ethereum-types = "0.11.0"
lazy_static = "1.4"
libc = "0.2"
parity-secp256k1 = "0.7"
Expand Down
3 changes: 2 additions & 1 deletion core/crypto/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
pub use errors::{ParseKeyError, ParseKeyTypeError, ParseSignatureError};
pub use key_file::KeyFile;
pub use signature::{
ED25519PublicKey, KeyType, PublicKey, Secp256K1PublicKey, SecretKey, Signature,
ED25519PublicKey, KeyType, PublicKey, Secp256K1PublicKey, Secp256K1Signature, SecretKey,
Signature,
};
pub use signer::{EmptySigner, InMemorySigner, Signer};

Expand Down
58 changes: 58 additions & 0 deletions core/crypto/src/signature.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@ use std::str::FromStr;

use borsh::{BorshDeserialize, BorshSerialize};
use ed25519_dalek::ed25519::signature::{Signature as _, Signer as _, Verifier as _};
use ethereum_types::U256;
use lazy_static::lazy_static;
use rand_core::OsRng;
use secp256k1::Message;
use serde::{Deserialize, Serialize};

lazy_static! {
Expand Down Expand Up @@ -556,6 +558,62 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
#[derive(Clone)]
pub struct Secp256K1Signature([u8; 65]);

impl Secp256K1Signature {
pub fn check_signature_values(&self, reject_upper: bool) -> bool {
let mut r_bytes = [0u8; 32];
r_bytes.copy_from_slice(&self.0[0..32]);
let r = U256::from(r_bytes);

let mut s_bytes = [0u8; 32];
s_bytes.copy_from_slice(&self.0[32..64]);
let s = U256::from(s_bytes);

let secp256k1_n = U256::from([
0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff,
0xff, 0xfe, 0xba, 0xae, 0xdc, 0xe6, 0xaf, 0x48, 0xa0, 0x3b, 0xbf, 0xd2, 0x5e, 0x8c,
0xd0, 0x36, 0x41, 0x41,
]);
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved

if reject_upper {
let secp256k1_half_n = secp256k1_n / U256::from(2);
// Reject upper range of s values (ECDSA malleability)
if s > secp256k1_half_n {
return false;
}
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved
}

r < secp256k1_n && s < secp256k1_n
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved
}

pub fn recover(
&self,
msg: [u8; 32],
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved
) -> Result<Secp256K1PublicKey, crate::errors::ParseSignatureError> {
let recoverable_sig = secp256k1::RecoverableSignature::from_compact(
&SECP256K1,
&self.0[0..64],
secp256k1::RecoveryId::from_i32(i32::from(signature.0[64])).unwrap(),
)
.map_err(|err| crate::errors::ParseSignatureError::InvalidData {
error_message: err.to_string(),
})?;
let msg = Message::from(msg);

let res = SECP256K1
.recover(&msg, &recoverable_sig)
.map_err(|err| crate::errors::ParseSignatureError::InvalidData {
error_message: err.to_string(),
})?
.serialize_vec(&SECP256K1, false);

let pk = Secp256K1PublicKey::try_from(&res[1..65]).map_err(|err| {
crate::errors::ParseSignatureError::InvalidData { error_message: err.to_string() }
})?;
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved

Ok(pk)
}
}

impl From<[u8; 65]> for Secp256K1Signature {
fn from(data: [u8; 65]) -> Self {
Self(data)
Expand Down
3 changes: 2 additions & 1 deletion core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ lazy_static = "1.4"

[features]
default = []
protocol_feature_add_account_versions = []
protocol_feature_evm = []
protocol_feature_add_account_versions = []
protocol_feature_alt_bn128 = []
protocol_feature_tx_size_limit = []
protocol_feature_math_extension = []
38 changes: 38 additions & 0 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,17 @@ pub struct ExtCostsConfig {
/// Cost of getting sha256 per byte
pub keccak512_byte: Gas,

#[cfg(feature = "protocol_feature_math_extension")]
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved
/// Cost of getting ripemd160 base
pub ripemd160_base: Gas,
#[cfg(feature = "protocol_feature_math_extension")]
/// Cost of getting ripemd160 per message block
pub ripemd160_block: Gas,

#[cfg(feature = "protocol_feature_math_extension")]
/// Cost of calling ecrecover
pub ecrecover_base: Gas,

/// Cost for calling logging.
pub log_base: Gas,
/// Cost for logging per byte
Expand Down Expand Up @@ -353,6 +364,12 @@ impl Default for ExtCostsConfig {
keccak256_byte: SAFETY_MULTIPLIER * 7157035,
keccak512_base: SAFETY_MULTIPLIER * 1937129412,
keccak512_byte: SAFETY_MULTIPLIER * 12216567,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base: SAFETY_MULTIPLIER * 15136567500, // 10 x sha256_base
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block: SAFETY_MULTIPLIER * 80391170 * 8, // 10 x sha256_byte x 8 bytes
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base: SAFETY_MULTIPLIER * 75682837500, // 50 x sha256_base
log_base: SAFETY_MULTIPLIER * 1181104350,
log_byte: SAFETY_MULTIPLIER * 4399597,
storage_write_base: SAFETY_MULTIPLIER * 21398912000,
Expand Down Expand Up @@ -423,6 +440,12 @@ impl ExtCostsConfig {
keccak256_byte: 0,
keccak512_base: 0,
keccak512_byte: 0,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base: 0,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block: 0,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base: 0,
log_base: 0,
log_byte: 0,
storage_write_base: 0,
Expand Down Expand Up @@ -494,6 +517,12 @@ pub enum ExtCosts {
keccak256_byte,
keccak512_base,
keccak512_byte,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base,
log_base,
log_byte,
storage_write_base,
Expand Down Expand Up @@ -618,6 +647,12 @@ impl ExtCosts {
keccak256_byte => config.keccak256_byte,
keccak512_base => config.keccak512_base,
keccak512_byte => config.keccak512_byte,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_base => config.ripemd160_base,
#[cfg(feature = "protocol_feature_math_extension")]
ripemd160_block => config.ripemd160_block,
#[cfg(feature = "protocol_feature_math_extension")]
ecrecover_base => config.ecrecover_base,
log_base => config.log_base,
log_byte => config.log_byte,
storage_write_base => config.storage_write_base,
Expand Down Expand Up @@ -692,6 +727,9 @@ impl ExtCosts {
"keccak256_byte",
"keccak512_base",
"keccak512_byte",
"ripemd160_base",
"ripemd160_block",
"ecrecover_base",
"log_base",
"log_byte",
"storage_write_base",
Expand Down
3 changes: 2 additions & 1 deletion core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,8 @@ protocol_feature_allow_create_account_on_delete = []
protocol_feature_fix_storage_usage = []
protocol_feature_restore_receipts_after_fix = []
protocol_feature_cap_max_gas_price = []
nightly_protocol_features = ["nightly_protocol", "protocol_feature_evm", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_add_account_versions", "protocol_feature_tx_size_limit", "protocol_feature_allow_create_account_on_delete", "protocol_feature_fix_storage_usage", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price"]
protocol_feature_math_extension = ["near-primitives-core/protocol_feature_math_extension"]
nightly_protocol_features = ["nightly_protocol", "protocol_feature_evm", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_add_account_versions", "protocol_feature_tx_size_limit", "protocol_feature_allow_create_account_on_delete", "protocol_feature_fix_storage_usage", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price", "protocol_feature_math_extension"]
nightly_protocol = []

[dev-dependencies]
Expand Down
6 changes: 5 additions & 1 deletion core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,8 @@ pub enum ProtocolFeature {
RestoreReceiptsAfterFix,
#[cfg(feature = "protocol_feature_cap_max_gas_price")]
CapMaxGasPrice,
#[cfg(feature = "protocol_feature_math_extension")]
MathExtension,
}

/// Current latest stable version of the protocol.
Expand All @@ -117,7 +119,7 @@ pub const PROTOCOL_VERSION: ProtocolVersion = 45;

/// Current latest nightly version of the protocol.
#[cfg(feature = "nightly_protocol")]
pub const PROTOCOL_VERSION: ProtocolVersion = 113;
pub const PROTOCOL_VERSION: ProtocolVersion = 114;

impl ProtocolFeature {
pub const fn protocol_version(self) -> ProtocolVersion {
Expand Down Expand Up @@ -149,6 +151,8 @@ impl ProtocolFeature {
ProtocolFeature::RestoreReceiptsAfterFix => 112,
#[cfg(feature = "protocol_feature_cap_max_gas_price")]
ProtocolFeature::CapMaxGasPrice => 113,
#[cfg(feature = "protocol_feature_math_extension")]
ProtocolFeature::MathExtension => 114,
}
}
}
Expand Down
3 changes: 2 additions & 1 deletion nearcore/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,10 +69,11 @@ protocol_feature_add_account_versions = ["near-primitives/protocol_feature_add_a
protocol_feature_tx_size_limit = ["near-primitives/protocol_feature_tx_size_limit", "node-runtime/protocol_feature_tx_size_limit"]
protocol_feature_allow_create_account_on_delete = ["node-runtime/protocol_feature_allow_create_account_on_delete"]
protocol_feature_fix_storage_usage = ["near-primitives/protocol_feature_fix_storage_usage", "node-runtime/protocol_feature_fix_storage_usage"]
nightly_protocol_features = ["nightly_protocol", "near-primitives/nightly_protocol_features", "near-client/nightly_protocol_features", "near-epoch-manager/nightly_protocol_features", "near-store/nightly_protocol_features", "protocol_feature_evm", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_add_account_versions", "protocol_feature_tx_size_limit", "protocol_feature_allow_create_account_on_delete", "protocol_feature_fix_storage_usage", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price"]
nightly_protocol_features = ["nightly_protocol", "near-primitives/nightly_protocol_features", "near-client/nightly_protocol_features", "near-epoch-manager/nightly_protocol_features", "near-store/nightly_protocol_features", "protocol_feature_evm", "protocol_feature_block_header_v3", "protocol_feature_alt_bn128", "protocol_feature_add_account_versions", "protocol_feature_tx_size_limit", "protocol_feature_allow_create_account_on_delete", "protocol_feature_fix_storage_usage", "protocol_feature_restore_receipts_after_fix", "protocol_feature_cap_max_gas_price", "protocol_feature_math_extension"]
nightly_protocol = ["near-primitives/nightly_protocol", "near-jsonrpc/nightly_protocol"]
protocol_feature_restore_receipts_after_fix = ["near-primitives/protocol_feature_restore_receipts_after_fix", "near-chain/protocol_feature_restore_receipts_after_fix", "node-runtime/protocol_feature_restore_receipts_after_fix"]
protocol_feature_cap_max_gas_price = ["near-primitives/protocol_feature_cap_max_gas_price", "near-chain/protocol_feature_cap_max_gas_price"]
protocol_feature_math_extension = ["near-primitives/protocol_feature_math_extension"]

# enable this to build neard with wasmer 1.0 runner
# now if none of wasmer0_default, wasmer1_default or wasmtime_default is enabled, wasmer0 would be default
Expand Down
Empty file modified runtime/near-test-contracts/res/test_contract_ts.wasm
100755 → 100644
Empty file.
1 change: 1 addition & 0 deletions runtime/near-vm-errors/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ near-rpc-error-macro = { path = "../../tools/rpctypegen/macro", version = "0.1.0

[features]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_math_extension = []
protocol_feature_alt_bn128 = []

[package.metadata.workspaces]
Expand Down
4 changes: 4 additions & 0 deletions runtime/near-vm-errors/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,8 @@ pub enum HostError {
/// Serialization error for alt_bn128 functions
#[cfg(feature = "protocol_feature_alt_bn128")]
AltBn128SerializationError { msg: String },
#[cfg(feature = "protocol_feature_math_extension")]
InvalidECRecoverVByte { value: u64 },
}

/// Errors specifically from native EVM.
Expand Down Expand Up @@ -498,6 +500,8 @@ impl std::fmt::Display for HostError {
AltBn128DeserializationError { msg } => write!(f, "AltBn128 deserialization error: {}", msg),
#[cfg(feature = "protocol_feature_alt_bn128")]
AltBn128SerializationError { msg } => write!(f, "AltBn128 serialization error: {}", msg),
#[cfg(feature = "protocol_feature_math_extension")]
InvalidECRecoverVByte { value } => write!(f, "V recovery byte 0 through 3 are valid but was provided {}", value),
}
}
}
Expand Down
3 changes: 3 additions & 0 deletions runtime/near-vm-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ base64 = "0.13"
borsh = "0.8.1"
bs58 = "0.4"
byteorder = "1.2"
ripemd160 = "0.9.0"
serde = { version = "1", features = ["derive"] }
sha2 = ">=0.8,<0.10"
sha3 = ">=0.8,<0.10"

near-crypto = { path = "../../core/crypto" }
MaksymZavershynskyi marked this conversation as resolved.
Show resolved Hide resolved
near-primitives = { path = "../../core/primitives" }
near-primitives-core = { path = "../../core/primitives-core", version = "0.1.0" }
near-vm-errors = { path = "../near-vm-errors", version = "3.0.0" }
Expand All @@ -36,6 +38,7 @@ default = []
protocol_feature_evm = ["near-primitives-core/protocol_feature_evm"]
protocol_feature_alt_bn128 = ["bn", "near-primitives-core/protocol_feature_alt_bn128", "near-vm-errors/protocol_feature_alt_bn128"]
protocol_feature_allow_create_account_on_delete = []
protocol_feature_math_extension = ["near-primitives/protocol_feature_math_extension", "near-vm-errors/protocol_feature_math_extension"]

# Use this feature to enable counting of fees and costs applied.
costs_counting = []
Expand Down
10 changes: 5 additions & 5 deletions runtime/near-vm-logic/src/gas_counter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -144,18 +144,18 @@ impl GasCounter {
self.deduct_gas(value, value)
}

/// A helper function to pay per byte gas
pub fn pay_per_byte(&mut self, cost: ExtCosts, num_bytes: u64) -> Result<()> {
let use_gas = num_bytes
/// A helper function to pay a multiple of a cost.
pub fn pay_per(&mut self, cost: ExtCosts, num: u64) -> Result<()> {
let use_gas = num
.checked_mul(cost.value(&self.ext_costs_config))
.ok_or(HostError::IntegerOverflow)?;

self.inc_ext_costs_counter(cost, num_bytes);
self.inc_ext_costs_counter(cost, num);
self.update_profile_host(cost, use_gas);
self.deduct_gas(use_gas, use_gas)
}

/// A helper function to pay base cost gas
/// A helper function to pay base cost gas.
pub fn pay_base(&mut self, cost: ExtCosts) -> Result<()> {
let base_fee = cost.value(&self.ext_costs_config);
self.inc_ext_costs_counter(cost, 1);
Expand Down
Loading