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

stabilizing ed25519_verify host function #8098

Merged
merged 7 commits into from
Jan 24, 2023
Merged
Show file tree
Hide file tree
Changes from 5 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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
## [unreleased]

### Protocol Changes
* Stabilize `ed25519_verify` feature: introducing a host function to verify
ed25519 signatures efficiently.
[#8098](https://github.com/near/nearcore/pull/8098)
blasrodri marked this conversation as resolved.
Show resolved Hide resolved

### Non-protocol Changes
* `/debug` page now has client_config linked. You can also check your client_config directly at /debug/client_config
Expand Down
3 changes: 1 addition & 2 deletions core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,5 @@ insta.workspace = true

[features]
default = []
protocol_feature_ed25519_verify = []
protocol_feature_nep366_delegate_action = []
nightly = ["protocol_feature_ed25519_verify", "protocol_feature_nep366_delegate_action"]
nightly = ["protocol_feature_nep366_delegate_action"]
6 changes: 0 additions & 6 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -302,9 +302,7 @@ impl ExtCostsConfig {
ExtCosts::keccak512_base => SAFETY_MULTIPLIER * 1937129412,
ExtCosts::keccak512_byte => SAFETY_MULTIPLIER * 12216567,
ExtCosts::ripemd160_base => SAFETY_MULTIPLIER * 284558362,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ExtCosts::ed25519_verify_base => SAFETY_MULTIPLIER * 1513656750,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ExtCosts::ed25519_verify_byte => SAFETY_MULTIPLIER * 7157035,
ExtCosts::ripemd160_block => SAFETY_MULTIPLIER * 226702528,
ExtCosts::ecrecover_base => SAFETY_MULTIPLIER * 1121789875000,
Expand Down Expand Up @@ -436,9 +434,7 @@ pub enum ExtCosts {
alt_bn128_pairing_check_element = 56,
alt_bn128_g1_sum_base = 57,
alt_bn128_g1_sum_element = 58,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ed25519_verify_base = 59,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ed25519_verify_byte = 60,
}

Expand Down Expand Up @@ -508,9 +504,7 @@ impl ExtCosts {
ExtCosts::ripemd160_base => Parameter::WasmRipemd160Base,
ExtCosts::ripemd160_block => Parameter::WasmRipemd160Block,
ExtCosts::ecrecover_base => Parameter::WasmEcrecoverBase,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ExtCosts::ed25519_verify_base => Parameter::WasmEd25519VerifyBase,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ExtCosts::ed25519_verify_byte => Parameter::WasmEd25519VerifyByte,
ExtCosts::log_base => Parameter::WasmLogBase,
ExtCosts::log_byte => Parameter::WasmLogByte,
Expand Down
2 changes: 1 addition & 1 deletion core/primitives-core/src/profile/profile_v2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ pub struct ProfileDataV2 {
struct DataArray(Box<[u64; Self::LEN]>);

impl DataArray {
const LEN: usize = if cfg!(feature = "protocol_feature_ed25519_verify") { 72 } else { 70 };
const LEN: usize = 72;
}

impl ProfileDataV2 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ utf16_decoding_byte -> 14 [0% host]
sha256_base -> 15 [0% host]
sha256_byte -> 16 [0% host]
keccak256_base -> 17 [0% host]
keccak256_byte -> 18 [1% host]
keccak256_byte -> 18 [0% host]
keccak512_base -> 19 [1% host]
keccak512_byte -> 20 [1% host]
ripemd160_base -> 21 [1% host]
Expand All @@ -39,8 +39,8 @@ storage_read_key_byte -> 31 [1% host]
storage_read_value_byte -> 32 [1% host]
storage_remove_base -> 33 [1% host]
storage_remove_key_byte -> 34 [1% host]
storage_remove_ret_value_byte -> 35 [2% host]
storage_has_key_base -> 36 [2% host]
storage_remove_ret_value_byte -> 35 [1% host]
storage_has_key_base -> 36 [1% host]
storage_has_key_byte -> 37 [2% host]
storage_iter_create_prefix_base -> 38 [2% host]
storage_iter_create_prefix_byte -> 39 [2% host]
Expand All @@ -56,13 +56,15 @@ promise_and_base -> 48 [2% host]
promise_and_per_promise -> 49 [2% host]
promise_return -> 50 [2% host]
validator_stake_base -> 51 [2% host]
validator_total_stake_base -> 52 [3% host]
alt_bn128_g1_multiexp_base -> 53 [3% host]
alt_bn128_g1_multiexp_element -> 54 [3% host]
validator_total_stake_base -> 52 [2% host]
alt_bn128_g1_multiexp_base -> 53 [2% host]
alt_bn128_g1_multiexp_element -> 54 [2% host]
alt_bn128_pairing_check_base -> 55 [3% host]
alt_bn128_pairing_check_element -> 56 [3% host]
alt_bn128_g1_sum_base -> 57 [3% host]
alt_bn128_g1_sum_element -> 58 [3% host]
ed25519_verify_base -> 59 [3% host]
ed25519_verify_byte -> 60 [3% host]
------ Actions --------
create_account -> 1000
delete_account -> 1001
Expand Down
4 changes: 0 additions & 4 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,6 @@ dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_fix_staking_threshold = []
protocol_feature_fix_contract_loading_cost = []
protocol_feature_reject_blocks_with_outdated_protocol_version = []
protocol_feature_ed25519_verify = [
"near-primitives-core/protocol_feature_ed25519_verify"
]
protocol_feature_zero_balance_account = []
protocol_feature_nep366_delegate_action = [
"near-primitives-core/protocol_feature_nep366_delegate_action"
Expand All @@ -60,7 +57,6 @@ nightly = [
"protocol_feature_fix_staking_threshold",
"protocol_feature_fix_contract_loading_cost",
"protocol_feature_reject_blocks_with_outdated_protocol_version",
"protocol_feature_ed25519_verify",
"protocol_feature_nep366_delegate_action",
"protocol_feature_zero_balance_account"
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 3365369625000,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 3365369625000,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 3365369625000,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 3365369625000,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: config_view
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 210000000000,
"ed25519_verify_byte": 9000000,
"ecrecover_base": 278821988457,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,16 @@ expression: view
"cost": "ECRECOVER_BASE",
"gas_used": "23"
},
{
"cost_category": "WASM_HOST_COST",
"cost": "ED25519_VERIFY_BASE",
"gas_used": "0"
},
{
"cost_category": "WASM_HOST_COST",
"cost": "ED25519_VERIFY_BYTE",
"gas_used": "0"
},
{
"cost_category": "WASM_HOST_COST",
"cost": "KECCAK256_BASE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,16 @@ expression: view
"cost": "ECRECOVER_BASE",
"gas_used": "23"
},
{
"cost_category": "WASM_HOST_COST",
"cost": "ED25519_VERIFY_BASE",
"gas_used": "59"
},
{
"cost_category": "WASM_HOST_COST",
"cost": "ED25519_VERIFY_BYTE",
"gas_used": "60"
},
{
"cost_category": "WASM_HOST_COST",
"cost": "KECCAK256_BASE",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,8 @@ expression: "&view"
"keccak512_byte": 36649701,
"ripemd160_base": 853675086,
"ripemd160_block": 680107584,
"ed25519_verify_base": 4540970250,
"ed25519_verify_byte": 21471105,
"ecrecover_base": 3365369625000,
"log_base": 3543313050,
"log_byte": 13198791,
Expand Down
2 changes: 0 additions & 2 deletions core/primitives/src/version.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,6 @@ pub enum ProtocolFeature {
/// Charge for contract loading before it happens.
#[cfg(feature = "protocol_feature_fix_contract_loading_cost")]
FixContractLoadingCost,
#[cfg(feature = "protocol_feature_ed25519_verify")]
Ed25519Verify,
#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
RejectBlocksWithOutdatedProtocolVersions,
Expand Down Expand Up @@ -235,7 +234,6 @@ impl ProtocolFeature {
ProtocolFeature::FixStakingThreshold => 126,
#[cfg(feature = "protocol_feature_fix_contract_loading_cost")]
ProtocolFeature::FixContractLoadingCost => 129,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ProtocolFeature::Ed25519Verify => 131,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, this will need a lower protocol number now so that it is included in the stable version. Please move it up to the stable features and update the number accordingly.

Note that we have already bumped the protocol version to 58 in #8360, so you can just set the version to 58 and don't have to bump again.

#[cfg(feature = "protocol_feature_reject_blocks_with_outdated_protocol_version")]
ProtocolFeature::RejectBlocksWithOutdatedProtocolVersions => 132,
Expand Down
6 changes: 0 additions & 6 deletions core/primitives/src/views.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2377,10 +2377,8 @@ pub struct ExtCostsConfigView {
pub ripemd160_block: Gas,

/// Cost of getting ed25519 base
#[cfg(feature = "protocol_feature_ed25519_verify")]
pub ed25519_verify_base: Gas,
/// Cost of getting ed25519 per byte
#[cfg(feature = "protocol_feature_ed25519_verify")]
pub ed25519_verify_byte: Gas,

/// Cost of calling ecrecover
Expand Down Expand Up @@ -2511,9 +2509,7 @@ impl From<near_primitives_core::config::ExtCostsConfig> for ExtCostsConfigView {
keccak512_byte: config.cost(ExtCosts::keccak512_byte),
ripemd160_base: config.cost(ExtCosts::ripemd160_base),
ripemd160_block: config.cost(ExtCosts::ripemd160_block),
#[cfg(feature = "protocol_feature_ed25519_verify")]
ed25519_verify_base: config.cost(ExtCosts::ed25519_verify_base),
#[cfg(feature = "protocol_feature_ed25519_verify")]
ed25519_verify_byte: config.cost(ExtCosts::ed25519_verify_byte),
ecrecover_base: config.cost(ExtCosts::ecrecover_base),
log_base: config.cost(ExtCosts::log_base),
Expand Down Expand Up @@ -2584,9 +2580,7 @@ impl From<ExtCostsConfigView> for near_primitives_core::config::ExtCostsConfig {
ExtCosts::keccak512_byte => view.keccak512_byte,
ExtCosts::ripemd160_base => view.ripemd160_base,
ExtCosts::ripemd160_block => view.ripemd160_block,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ExtCosts::ed25519_verify_base => view.ed25519_verify_base,
#[cfg(feature = "protocol_feature_ed25519_verify")]
ExtCosts::ed25519_verify_byte => view.ed25519_verify_byte,
ExtCosts::ecrecover_base => view.ecrecover_base,
ExtCosts::log_base => view.log_base,
Expand Down
3 changes: 1 addition & 2 deletions runtime/near-test-contracts/estimator-contract/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -21,5 +21,4 @@ panic = "abort"
members = []

[features]
protocol_feature_ed25519_verify = []
nightly = ["protocol_feature_ed25519_verify"]
nightly = []
3 changes: 0 additions & 3 deletions runtime/near-test-contracts/estimator-contract/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,6 @@ extern "C" {
malleability_flag: u64,
register_id: u64,
) -> u64;
#[cfg(feature = "protocol_feature_ed25519_verify")]
fn ed25519_verify(
sig_len: u64,
sig_ptr: u64,
Expand Down Expand Up @@ -481,7 +480,6 @@ pub unsafe fn ecrecover_10k() {
/// `ed25519_verify_base` computation is more expensive than register writing so
/// we are okay overcharging it.
#[no_mangle]
#[cfg(feature = "protocol_feature_ed25519_verify")]
pub unsafe fn ed25519_verify_32b_500() {
// private key: OReNDSAXOnl-U6Wki95ut01ehQW_9wcAF_utjzRNreg
// public key: M4QwJx4Sogjr0KcMI_gsvt-lEU6tgd9GWmgejE_JYlA
Expand Down Expand Up @@ -520,7 +518,6 @@ pub unsafe fn ed25519_verify_32b_500() {

/// Function to measure `ed25519_verify_bytes`.
#[no_mangle]
#[cfg(feature = "protocol_feature_ed25519_verify")]
pub unsafe fn ed25519_verify_16kib_64() {
// 16kB bytes message
let message = [b'a'; 16384];
Expand Down
3 changes: 0 additions & 3 deletions runtime/near-vm-logic/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,9 +42,6 @@ default = []
protocol_feature_fix_contract_loading_cost = [
"near-primitives/protocol_feature_fix_contract_loading_cost",
]
protocol_feature_ed25519_verify = [
"near-primitives/protocol_feature_ed25519_verify"
]
protocol_feature_flat_state = []

io_trace = ["tracing"]
Expand Down
1 change: 0 additions & 1 deletion runtime/near-vm-logic/src/logic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,6 @@ impl<'a> VMLogic<'a> {
/// `input_cost(num_bytes_signature) + input_cost(num_bytes_message) +
/// input_cost(num_bytes_public_key) + ed25519_verify_base +
/// ed25519_verify_byte * num_bytes_message`
#[cfg(feature = "protocol_feature_ed25519_verify")]
pub fn ed25519_verify(
&mut self,
signature_len: u64,
Expand Down
Loading