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 110 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
8 changes: 6 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
76 changes: 76 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,80 @@ impl<'de> serde::Deserialize<'de> for SecretKey {
#[derive(Clone)]
pub struct Secp256K1Signature([u8; 65]);

impl Secp256K1Signature {
fn check_v(&self) -> Result<u8, crate::errors::ParseSignatureError> {
match self.0[64] {
27 | 28 => Ok(self.0[64] - 27),
_ => Err(crate::errors::ParseSignatureError::InvalidData {
error_message: "invalid `v` value".to_string(),
}),
}
}
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved

pub fn check_signature_values(&self) -> 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 _v = match self.check_v() {
Ok(v) => v,
Err(_e) => return false,
};
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved

if r.is_zero() || s.is_zero() {
return false;
}

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

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 v = self.check_v()?;

// This can't fail because of the check above. It will fall in range.
let recover_id = secp256k1::RecoveryId::from_i32(i32::from(v)).unwrap();

let recoverable_sig =
secp256k1::RecoverableSignature::from_compact(&SECP256K1, &self.0[0..64], recover_id)
.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[0..64]).map_err(|err| {
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved
crate::errors::ParseSignatureError::InvalidData { error_message: err.to_string() }
})?;

Ok(pk)
}
}

impl From<[u8; 65]> for Secp256K1Signature {
fn from(data: [u8; 65]) -> Self {
Self(data)
Expand Down
2 changes: 1 addition & 1 deletion core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ 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 = []
23 changes: 23 additions & 0 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,14 @@ pub struct ExtCostsConfig {
/// Cost of getting sha256 per byte
pub keccak512_byte: Gas,

/// Cost of getting ripemd160 base
pub ripemd160_base: Gas,
/// Cost of getting ripemd160 per message block
pub ripemd160_block: Gas,

/// Cost of calling ecrecover
pub ecrecover_base: Gas,
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved

/// Cost for calling logging.
pub log_base: Gas,
/// Cost for logging per byte
Expand Down Expand Up @@ -353,6 +361,9 @@ impl Default for ExtCostsConfig {
keccak256_byte: SAFETY_MULTIPLIER * 7157035,
keccak512_base: SAFETY_MULTIPLIER * 1937129412,
keccak512_byte: SAFETY_MULTIPLIER * 12216567,
ripemd160_base: SAFETY_MULTIPLIER * 15136567500, // 10 x sha256_base
ripemd160_block: SAFETY_MULTIPLIER * 80391170 * 8, // 10 x sha256_byte x 8 bytes
ecrecover_base: SAFETY_MULTIPLIER * 75682837500, // 50 x sha256_base
joshuajbouw marked this conversation as resolved.
Show resolved Hide resolved
log_base: SAFETY_MULTIPLIER * 1181104350,
log_byte: SAFETY_MULTIPLIER * 4399597,
storage_write_base: SAFETY_MULTIPLIER * 21398912000,
Expand Down Expand Up @@ -423,6 +434,9 @@ impl ExtCostsConfig {
keccak256_byte: 0,
keccak512_base: 0,
keccak512_byte: 0,
ripemd160_base: 0,
ripemd160_block: 0,
ecrecover_base: 0,
log_base: 0,
log_byte: 0,
storage_write_base: 0,
Expand Down Expand Up @@ -494,6 +508,9 @@ pub enum ExtCosts {
keccak256_byte,
keccak512_base,
keccak512_byte,
ripemd160_base,
ripemd160_block,
ecrecover_base,
log_base,
log_byte,
storage_write_base,
Expand Down Expand Up @@ -618,6 +635,9 @@ impl ExtCosts {
keccak256_byte => config.keccak256_byte,
keccak512_base => config.keccak512_base,
keccak512_byte => config.keccak512_byte,
ripemd160_base => config.ripemd160_base,
ripemd160_block => config.ripemd160_block,
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 +712,9 @@ impl ExtCosts {
"keccak256_byte",
"keccak512_base",
"keccak512_byte",
"ripemd160_base",
"ripemd160_block",
"ecrecover_base",
"log_base",
"log_byte",
"storage_write_base",
Expand Down
Empty file modified runtime/near-test-contracts/res/test_contract_ts.wasm
100755 → 100644
Empty file.
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,13 @@ base64 = "0.13"
borsh = "0.8.1"
bs58 = "0.4"
byteorder = "1.2"
num-integer = "0.1"
birchmd marked this conversation as resolved.
Show resolved Hide resolved
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 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