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

feat: stabilize alt_bn128 familiy of host functions #6824

Merged
merged 6 commits into from
Jun 2, 2022
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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

### Protocol Changes

* Introduced protobuf encoding as the new network protocol. Borsh support will be removed in two releases as per normal protocol upgrade policies [#6672](https://github.com/near/nearcore/pull/6672)
* Introduced protobuf encoding as the new network protocol. Borsh support will be removed in two releases as per normal protocol upgrade policies [#6672](https://github.com/near/nearcore/pull/6672).
* Stabilized `alt_bn128_g1_multiexp`, `alt_bn128_g1_sum`, `alt_bn128_pairing_check` host functions [#6813](https://github.com/near/nearcore/pull/6813).

### Non-protocol Changes

Expand Down
4 changes: 2 additions & 2 deletions chain/chain/src/tests/simple_chain.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_display_snapshot!(hash, @"8F4vXPPNevoQXVGdwKAZQfzzxhSyqWp3xJiik4RMUKSk");
} else {
insta::assert_display_snapshot!(hash, @"sFAi6Xq5jWcbRetAkMQ3A44GvfLHSLMnb8SqaRsmWmo");
insta::assert_display_snapshot!(hash, @"6sAno2uEwwQ5yiDscePWY8HWmRJLpGNv39uoff3BCpxT");
}

for i in 1..5 {
Expand Down Expand Up @@ -70,7 +70,7 @@ fn build_chain() {
if cfg!(feature = "nightly") {
insta::assert_display_snapshot!(hash, @"DrW7MsRaFhEdjQcxjqrTXvNmQ1eptgURQ7RUTeZnrBXC");
} else {
insta::assert_display_snapshot!(hash, @"F5srbRRkG5KBzvDzEpDiiJp257SCVUaeFhNeXAddbHGZ");
insta::assert_display_snapshot!(hash, @"Fn9MgjUx6VXhPYNqqDtf2C9kBVveY2vuSLXNLZUNJCqK");
}
}

Expand Down
10 changes: 9 additions & 1 deletion chain/jsonrpc/res/rpc_errors_schema.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
{
"schema": {
"AltBn128InvalidInput": {
"name": "AltBn128InvalidInput",
"subtypes": [],
"props": {
"msg": ""
}
},
"BadUTF16": {
"name": "BadUTF16",
"subtypes": [],
Expand Down Expand Up @@ -139,7 +146,8 @@
"ReturnedValueLengthExceeded",
"ContractSizeExceeded",
"Deprecated",
"ECRecoverError"
"ECRecoverError",
"AltBn128InvalidInput"
],
"props": {}
},
Expand Down
1 change: 0 additions & 1 deletion core/primitives-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ serde_json = "1"

[features]
default = []
protocol_feature_alt_bn128 = []
protocol_feature_routing_exchange_algorithm = []
deepsize_feature = [
"deepsize",
Expand Down
36 changes: 3 additions & 33 deletions core/primitives-core/src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -400,22 +400,16 @@ pub struct ExtCostsConfig {
// # Alt BN128 #
// #############
/// Base cost for multiexp
#[cfg(feature = "protocol_feature_alt_bn128")]
pub alt_bn128_g1_multiexp_base: Gas,
/// byte cost for multiexp
#[cfg(feature = "protocol_feature_alt_bn128")]
/// Per element cost for multiexp
pub alt_bn128_g1_multiexp_element: Gas,
/// Base cost for sum
#[cfg(feature = "protocol_feature_alt_bn128")]
pub alt_bn128_g1_sum_base: Gas,
/// byte cost for sum
#[cfg(feature = "protocol_feature_alt_bn128")]
/// Per element cost for sum
pub alt_bn128_g1_sum_element: Gas,
/// Base cost for pairing check
#[cfg(feature = "protocol_feature_alt_bn128")]
pub alt_bn128_pairing_check_base: Gas,
/// Cost for pairing check per byte
#[cfg(feature = "protocol_feature_alt_bn128")]
/// Per element cost for pairing check
pub alt_bn128_pairing_check_element: Gas,
}

Expand Down Expand Up @@ -488,17 +482,11 @@ impl ExtCostsConfig {
validator_total_stake_base: SAFETY_MULTIPLIER * 303944908800,
_unused1: 0,
_unused2: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_base: 713_000_000_000,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_element: 320_000_000_000,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_base: 9_686_000_000_000,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_element: 5_102_000_000_000,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_base: 3_000_000_000,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_element: 5_000_000_000,
}
}
Expand Down Expand Up @@ -560,17 +548,11 @@ impl ExtCostsConfig {
validator_total_stake_base: 0,
_unused1: 0,
_unused2: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_base: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_element: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_base: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_element: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_base: 0,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_element: 0,
}
}
Expand Down Expand Up @@ -633,17 +615,11 @@ pub enum ExtCosts {
promise_return,
validator_stake_base,
validator_total_stake_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_element,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_element,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_element,
}

Expand Down Expand Up @@ -720,17 +696,11 @@ impl ExtCosts {
promise_return => config.promise_return,
validator_stake_base => config.validator_stake_base,
validator_total_stake_base => config.validator_total_stake_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_base => config.alt_bn128_g1_multiexp_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_multiexp_element => config.alt_bn128_g1_multiexp_element,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_base => config.alt_bn128_pairing_check_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_pairing_check_element => config.alt_bn128_pairing_check_element,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_base => config.alt_bn128_g1_sum_base,
#[cfg(feature = "protocol_feature_alt_bn128")]
alt_bn128_g1_sum_element => config.alt_bn128_g1_sum_element,
}
}
Expand Down
6 changes: 0 additions & 6 deletions core/primitives-core/src/parameter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -264,17 +264,11 @@ impl Parameter {
Parameter::WasmPromiseReturn,
Parameter::WasmValidatorStakeBase,
Parameter::WasmValidatorTotalStakeBase,
#[cfg(feature = "protocol_feature_alt_bn128")]
Parameter::WasmAltBn128G1MultiexpBase,
#[cfg(feature = "protocol_feature_alt_bn128")]
Parameter::WasmAltBn128G1MultiexpElement,
#[cfg(feature = "protocol_feature_alt_bn128")]
Parameter::WasmAltBn128PairingCheckBase,
#[cfg(feature = "protocol_feature_alt_bn128")]
Parameter::WasmAltBn128PairingCheckElement,
#[cfg(feature = "protocol_feature_alt_bn128")]
Parameter::WasmAltBn128G1SumBase,
#[cfg(feature = "protocol_feature_alt_bn128")]
Parameter::WasmAltBn128G1SumElement,
]
.iter()
Expand Down
12 changes: 0 additions & 12 deletions core/primitives-core/src/profile.rs
Original file line number Diff line number Diff line change
Expand Up @@ -246,17 +246,11 @@ impl Cost {
Cost::ExtCost { ext_cost_kind: ExtCosts::validator_stake_base },
Cost::ExtCost { ext_cost_kind: ExtCosts::validator_total_stake_base },
Cost::WasmInstruction,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_multiexp_base },
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_multiexp_element },
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_pairing_check_base },
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_pairing_check_element },
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_sum_base },
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_sum_element },
];

Expand Down Expand Up @@ -326,17 +320,11 @@ impl Cost {
Cost::ExtCost { ext_cost_kind: ExtCosts::validator_total_stake_base } => 61,
Cost::WasmInstruction => 62,
Cost::ExtCost { ext_cost_kind: ExtCosts::read_cached_trie_node } => 63,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_multiexp_base } => 64,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_multiexp_element } => 65,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_pairing_check_base } => 66,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_pairing_check_element } => 67,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_sum_base } => 68,
#[cfg(feature = "protocol_feature_alt_bn128")]
Cost::ExtCost { ext_cost_kind: ExtCosts::alt_bn128_g1_sum_element } => 69,
}
}
Expand Down
5 changes: 0 additions & 5 deletions core/primitives/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -40,17 +40,12 @@ near-rpc-error-macro = { path = "../../tools/rpctypegen/macro" }

[features]
dump_errors_schema = ["near-rpc-error-macro/dump_errors_schema"]
protocol_feature_alt_bn128 = [
"near-primitives-core/protocol_feature_alt_bn128",
"near-vm-errors/protocol_feature_alt_bn128",
]
protocol_feature_chunk_only_producers = []
protocol_feature_routing_exchange_algorithm = ["near-primitives-core/protocol_feature_routing_exchange_algorithm"]
protocol_feature_access_key_nonce_for_implicit_accounts = []
protocol_feature_fix_staking_threshold = []
nightly = [
"nightly_protocol",
"protocol_feature_alt_bn128",
"protocol_feature_chunk_only_producers",
"protocol_feature_routing_exchange_algorithm",
"protocol_feature_access_key_nonce_for_implicit_accounts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 3856371,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 3856371,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 2207874,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 822756,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 822756,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 822756,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 822756,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 3856371,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 3856371,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 2207874,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,13 @@ expression: store.get_config(*version)
"validator_stake_base": 911834726400,
"validator_total_stake_base": 911834726400,
"contract_compile_base": 0,
"contract_compile_bytes": 0
"contract_compile_bytes": 0,
"alt_bn128_g1_multiexp_base": 713000000000,
"alt_bn128_g1_multiexp_element": 320000000000,
"alt_bn128_g1_sum_base": 3000000000,
"alt_bn128_g1_sum_element": 5000000000,
"alt_bn128_pairing_check_base": 9686000000000,
"alt_bn128_pairing_check_element": 5102000000000
},
"grow_mem_cost": 1,
"regular_op_cost": 822756,
Expand Down
Loading