Skip to content

Commit

Permalink
change reward slashing rate to 100% (MystenLabs#10453)
Browse files Browse the repository at this point in the history
## Description 

Gated behind a new protocol version.

## Test Plan 

Added a test.

---
If your changes are not user-facing and not a breaking change, you can
skip the following section. Otherwise, please indicate what changed, and
then add to the Release Notes section as highlighted during the release
process.

### Type of Change (Check all that apply)

- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [x] breaking change for FNs (FN binary must upgrade)
- [x] breaking change for validators or node operators (must upgrade
binaries)
- [ ] breaking change for on-chain data layout
- [ ] necessitate either a data wipe or data migration

### Release notes
  • Loading branch information
emmazzz authored Apr 5, 2023
1 parent facda36 commit ae610c8
Show file tree
Hide file tree
Showing 4 changed files with 214 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ expression: genesis_config
validator_config_info: ~
parameters:
chain_start_timestamp_ms: 0
protocol_version: 3
protocol_version: 4
allow_insertion_of_extra_objects: true
epoch_duration_ms: 86400000
stake_subsidy_start_epoch: 0
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,47 @@ module sui_system::rewards_distribution_tests {
test_scenario::end(scenario_val);
}

#[test]
fun test_entire_rewards_slashing() {
set_up_sui_system_state();
let scenario_val = test_scenario::begin(VALIDATOR_ADDR_1);
let scenario = &mut scenario_val;

advance_epoch(scenario);

stake_with(STAKER_ADDR_1, VALIDATOR_ADDR_1, 100, scenario);
stake_with(STAKER_ADDR_2, VALIDATOR_ADDR_2, 100, scenario);

advance_epoch(scenario);

// validator_2 is reported by 3 other validators, so 75% of total stake.
report_validator(VALIDATOR_ADDR_1, VALIDATOR_ADDR_2, scenario);
report_validator(VALIDATOR_ADDR_3, VALIDATOR_ADDR_2, scenario);
report_validator(VALIDATOR_ADDR_4, VALIDATOR_ADDR_2, scenario);


// 3600 SUI of total rewards, 100% reward slashing.
// So validator_2 is the only one whose rewards should get slashed.
advance_epoch_with_reward_amounts_and_slashing_rates(
0, 3600, 10_000, scenario
);

// Without reward slashing, the validator's stakes should be [100+450, 200+600, 300+900, 400+900]
// after the last epoch advancement.
// The entire rewards of validator 2's staking pool are slashed, which is 900 SUI.
// so the unslashed validators each get their share of additional rewards, which is 300.
assert_validator_self_stake_amounts(validator_addrs(), vector[(550 + 150) * MIST_PER_SUI, 200 * MIST_PER_SUI, (1200 + 300) * MIST_PER_SUI, (1300 + 300) * MIST_PER_SUI], scenario);

// Unstake so we can check the stake rewards as well.
unstake(STAKER_ADDR_1, 0, scenario);
unstake(STAKER_ADDR_2, 0, scenario);

// Same analysis as above. Staker 1 has 150 additional SUI, and since all of staker 2's rewards are slashed she only gets back her principal.
assert!(total_sui_balance(STAKER_ADDR_1, scenario) == (550 + 150) * MIST_PER_SUI, 0);
assert!(total_sui_balance(STAKER_ADDR_2, scenario) == 100 * MIST_PER_SUI, 0);
test_scenario::end(scenario_val);
}

#[test]
fun test_rewards_slashing_with_storage_fund() {
set_up_sui_system_state();
Expand Down
9 changes: 8 additions & 1 deletion crates/sui-protocol-config/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ use tracing::{info, warn};

/// The minimum and maximum protocol versions supported by this build.
const MIN_PROTOCOL_VERSION: u64 = 1;
const MAX_PROTOCOL_VERSION: u64 = 3;
const MAX_PROTOCOL_VERSION: u64 = 4;

// Record history of protocol version allocations here:
//
Expand All @@ -19,6 +19,7 @@ const MAX_PROTOCOL_VERSION: u64 = 3;
// Version 3: gas model v2, including all sui conservation fixes. Fix for loaded child object
// changes, enable package upgrades, add limits on `max_size_written_objects`,
// `max_size_written_objects_system_tx`
// Version 4: New reward slashing rate.

#[derive(
Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord, JsonSchema,
Expand Down Expand Up @@ -1541,6 +1542,12 @@ impl ProtocolConfig {
cfg.feature_flags.package_upgrades = true;
cfg
}
4 => {
let mut cfg = Self::get_for_version_impl(version - 1);
// Change reward slashing rate to 100%.
cfg.reward_slashing_rate = Some(10000);
cfg
}
// Use this template when making changes:
//
// // modify an existing constant.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
---
source: crates/sui-protocol-config/src/lib.rs
expression: "ProtocolConfig::get_for_version(cur)"
---
version: 4
feature_flags:
package_upgrades: true
advance_epoch_start_time_in_safe_mode: true
loaded_child_objects_fixed: true
max_tx_size_bytes: 131072
max_input_objects: 2048
max_size_written_objects: 5000000
max_size_written_objects_system_tx: 50000000
max_serialized_tx_effects_size_bytes: 524288
max_serialized_tx_effects_size_bytes_system_tx: 8388608
max_gas_payment_objects: 256
max_modules_in_publish: 128
max_arguments: 512
max_type_arguments: 16
max_type_argument_depth: 16
max_pure_argument_size: 16384
max_programmable_tx_commands: 1024
move_binary_format_version: 6
max_move_object_size: 256000
max_move_package_size: 102400
max_tx_gas: 50000000000
max_loop_depth: 5
max_generic_instantiation_length: 32
max_function_parameters: 128
max_basic_blocks: 1024
max_value_stack_size: 1024
max_type_nodes: 256
max_push_size: 10000
max_struct_definitions: 200
max_function_definitions: 1000
max_fields_in_struct: 32
max_dependency_depth: 100
max_num_event_emit: 256
max_num_new_move_object_ids: 2048
max_num_new_move_object_ids_system_tx: 32768
max_num_deleted_move_object_ids: 2048
max_num_deleted_move_object_ids_system_tx: 32768
max_num_transferred_move_object_ids: 2048
max_num_transferred_move_object_ids_system_tx: 32768
max_event_emit_size: 256000
max_move_vector_len: 262144
max_back_edges_per_function: 10000
max_back_edges_per_module: 10000
max_verifier_meter_ticks_per_function: 6000000
max_meter_ticks_per_module: 6000000
object_runtime_max_num_cached_objects: 1000
object_runtime_max_num_cached_objects_system_tx: 16000
object_runtime_max_num_store_entries: 1000
object_runtime_max_num_store_entries_system_tx: 16000
base_tx_cost_fixed: 2000
package_publish_cost_fixed: 1000
base_tx_cost_per_byte: 0
package_publish_cost_per_byte: 80
obj_access_cost_read_per_byte: 15
obj_access_cost_mutate_per_byte: 40
obj_access_cost_delete_per_byte: 40
obj_access_cost_verify_per_byte: 200
gas_model_version: 2
obj_data_cost_refundable: 100
obj_metadata_cost_non_refundable: 50
storage_rebate_rate: 9900
storage_fund_reinvest_rate: 500
reward_slashing_rate: 10000
storage_gas_price: 76
max_transactions_per_checkpoint: 10000
max_checkpoint_size_bytes: 31457280
buffer_stake_for_protocol_upgrade_bps: 0
address_from_bytes_cost_base: 52
address_to_u256_cost_base: 52
address_from_u256_cost_base: 52
dynamic_field_hash_type_and_key_cost_base: 100
dynamic_field_hash_type_and_key_type_cost_per_byte: 2
dynamic_field_hash_type_and_key_value_cost_per_byte: 2
dynamic_field_hash_type_and_key_type_tag_cost_per_byte: 2
dynamic_field_add_child_object_cost_base: 100
dynamic_field_add_child_object_type_cost_per_byte: 10
dynamic_field_add_child_object_value_cost_per_byte: 10
dynamic_field_add_child_object_struct_tag_cost_per_byte: 10
dynamic_field_borrow_child_object_cost_base: 100
dynamic_field_borrow_child_object_child_ref_cost_per_byte: 10
dynamic_field_borrow_child_object_type_cost_per_byte: 10
dynamic_field_remove_child_object_cost_base: 100
dynamic_field_remove_child_object_child_cost_per_byte: 2
dynamic_field_remove_child_object_type_cost_per_byte: 2
dynamic_field_has_child_object_cost_base: 100
dynamic_field_has_child_object_with_ty_cost_base: 100
dynamic_field_has_child_object_with_ty_type_cost_per_byte: 2
dynamic_field_has_child_object_with_ty_type_tag_cost_per_byte: 2
event_emit_cost_base: 52
event_emit_value_size_derivation_cost_per_byte: 2
event_emit_tag_size_derivation_cost_per_byte: 5
event_emit_output_cost_per_byte: 10
object_borrow_uid_cost_base: 52
object_delete_impl_cost_base: 52
object_record_new_uid_cost_base: 52
transfer_transfer_internal_cost_base: 52
transfer_freeze_object_cost_base: 52
transfer_share_object_cost_base: 52
tx_context_derive_id_cost_base: 52
types_is_one_time_witness_cost_base: 52
types_is_one_time_witness_type_tag_cost_per_byte: 2
types_is_one_time_witness_type_cost_per_byte: 2
validator_validate_metadata_cost_base: 52
validator_validate_metadata_data_cost_per_byte: 2
crypto_invalid_arguments_cost: 100
bls12381_bls12381_min_sig_verify_cost_base: 52
bls12381_bls12381_min_sig_verify_msg_cost_per_byte: 2
bls12381_bls12381_min_sig_verify_msg_cost_per_block: 2
bls12381_bls12381_min_pk_verify_cost_base: 52
bls12381_bls12381_min_pk_verify_msg_cost_per_byte: 2
bls12381_bls12381_min_pk_verify_msg_cost_per_block: 2
ecdsa_k1_ecrecover_keccak256_cost_base: 52
ecdsa_k1_ecrecover_keccak256_msg_cost_per_byte: 2
ecdsa_k1_ecrecover_keccak256_msg_cost_per_block: 2
ecdsa_k1_ecrecover_sha256_cost_base: 52
ecdsa_k1_ecrecover_sha256_msg_cost_per_byte: 2
ecdsa_k1_ecrecover_sha256_msg_cost_per_block: 2
ecdsa_k1_decompress_pubkey_cost_base: 52
ecdsa_k1_secp256k1_verify_keccak256_cost_base: 52
ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_byte: 2
ecdsa_k1_secp256k1_verify_keccak256_msg_cost_per_block: 2
ecdsa_k1_secp256k1_verify_sha256_cost_base: 52
ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_byte: 2
ecdsa_k1_secp256k1_verify_sha256_msg_cost_per_block: 2
ecdsa_r1_ecrecover_keccak256_cost_base: 52
ecdsa_r1_ecrecover_keccak256_msg_cost_per_byte: 2
ecdsa_r1_ecrecover_keccak256_msg_cost_per_block: 2
ecdsa_r1_ecrecover_sha256_cost_base: 52
ecdsa_r1_ecrecover_sha256_msg_cost_per_byte: 2
ecdsa_r1_ecrecover_sha256_msg_cost_per_block: 2
ecdsa_r1_secp256r1_verify_keccak256_cost_base: 52
ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_byte: 2
ecdsa_r1_secp256r1_verify_keccak256_msg_cost_per_block: 2
ecdsa_r1_secp256r1_verify_sha256_cost_base: 52
ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_byte: 2
ecdsa_r1_secp256r1_verify_sha256_msg_cost_per_block: 2
ecvrf_ecvrf_verify_cost_base: 52
ecvrf_ecvrf_verify_alpha_string_cost_per_byte: 2
ecvrf_ecvrf_verify_alpha_string_cost_per_block: 2
ed25519_ed25519_verify_cost_base: 52
ed25519_ed25519_verify_msg_cost_per_byte: 2
ed25519_ed25519_verify_msg_cost_per_block: 2
groth16_prepare_verifying_key_bls12381_cost_base: 52
groth16_prepare_verifying_key_bn254_cost_base: 52
groth16_verify_groth16_proof_internal_bls12381_cost_base: 52
groth16_verify_groth16_proof_internal_bls12381_cost_per_public_input: 2
groth16_verify_groth16_proof_internal_bn254_cost_base: 52
groth16_verify_groth16_proof_internal_bn254_cost_per_public_input: 2
groth16_verify_groth16_proof_internal_public_input_cost_per_byte: 2
hash_blake2b256_cost_base: 52
hash_blake2b256_data_cost_per_byte: 2
hash_blake2b256_data_cost_per_block: 2
hash_keccak256_cost_base: 52
hash_keccak256_data_cost_per_byte: 2
hash_keccak256_data_cost_per_block: 2
hmac_hmac_sha3_256_cost_base: 52
hmac_hmac_sha3_256_input_cost_per_byte: 2
hmac_hmac_sha3_256_input_cost_per_block: 2

0 comments on commit ae610c8

Please sign in to comment.