diff --git a/crates/sui-core/src/authority.rs b/crates/sui-core/src/authority.rs index 5028fc0e0918c..7cc9d4243628b 100644 --- a/crates/sui-core/src/authority.rs +++ b/crates/sui-core/src/authority.rs @@ -348,7 +348,7 @@ const GAS_LATENCY_RATIO_BUCKETS: &[f64] = &[ 3000.0, 4000.0, 5000.0, 6000.0, 7000.0, 8000.0, 9000.0, 10000.0, 50000.0, 100000.0, 1000000.0, ]; -pub const DEV_INSPECT_GAS_COIN_VALUE: u64 = 1_000_000_000_000; +pub const DEV_INSPECT_GAS_COIN_VALUE: u64 = 1_000_000_000_000_000; impl AuthorityMetrics { pub fn new(registry: &prometheus::Registry) -> AuthorityMetrics { diff --git a/crates/sui-core/src/unit_tests/gas_tests.rs b/crates/sui-core/src/unit_tests/gas_tests.rs index d3ee4f32d0776..a7775e6f6a00f 100644 --- a/crates/sui-core/src/unit_tests/gas_tests.rs +++ b/crates/sui-core/src/unit_tests/gas_tests.rs @@ -28,6 +28,27 @@ static MAX_GAS_BUDGET: Lazy = static MIN_GAS_BUDGET_PRE_RGP: Lazy = Lazy::new(|| ProtocolConfig::get_for_max_version_UNSAFE().base_tx_cost_fixed()); +#[test] +fn test_gas_invariants() { + let max_tx_gas = ProtocolConfig::get_for_max_version_UNSAFE().max_tx_gas(); + assert!( + DEV_INSPECT_GAS_COIN_VALUE >= max_tx_gas, + "DEV_INSPECT_GAS_COIN_VALUE {} cannot be less than max_tx_gas {}", + DEV_INSPECT_GAS_COIN_VALUE, + max_tx_gas + ); + + let max_gas_price = ProtocolConfig::get_for_max_version_UNSAFE().max_gas_price(); + let base_tx_cost_fixed = ProtocolConfig::get_for_max_version_UNSAFE().base_tx_cost_fixed(); + assert!( + max_gas_price * base_tx_cost_fixed <= max_tx_gas, + "max_gas_price {} * base_tx_cost_fixed {} > max_tx_gas {}", + max_gas_price, + base_tx_cost_fixed, + max_tx_gas + ); +} + #[tokio::test] async fn test_tx_less_than_minimum_gas_budget() { // This test creates a transaction that sets a gas_budget less than the minimum diff --git a/crates/sui-protocol-config/src/lib.rs b/crates/sui-protocol-config/src/lib.rs index 1de0575ea5fc4..5ad6d1328ca59 100644 --- a/crates/sui-protocol-config/src/lib.rs +++ b/crates/sui-protocol-config/src/lib.rs @@ -205,6 +205,8 @@ const MAX_PROTOCOL_VERSION: u64 = 72; // Improve gas/wall time efficiency of some Move stdlib vector functions // Version 71: [SIP-45] Enable consensus amplification. // Version 72: Fix issue where `convert_type_argument_error` wasn't being used in all cases. +// Max gas budget moved to 50_000 SUI +// Max gas price moved to 50 SUI #[derive(Copy, Clone, Debug, Hash, Serialize, Deserialize, PartialEq, Eq, PartialOrd, Ord)] pub struct ProtocolVersion(u64); @@ -3130,6 +3132,12 @@ impl ProtocolConfig { } 72 => { cfg.feature_flags.convert_type_argument_error = true; + + // Invariant: max_gas_price * base_tx_cost_fixed <= max_tx_gas + // max gas budget is in MIST and an absolute value 50_000 SUI + cfg.max_tx_gas = Some(50_000_000_000_000); + // max gas price is in MIST and an absolute value 50 SUI + cfg.max_gas_price = Some(50_000_000_000); } // Use this template when making changes: // diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_72.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_72.snap index 7447195a801e3..a95cb08210cbc 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_72.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Mainnet_version_72.snap @@ -100,8 +100,8 @@ binary_friend_decls: 100 max_move_object_size: 256000 max_move_package_size: 102400 max_publish_or_upgrade_per_ptb: 5 -max_tx_gas: 50000000000 -max_gas_price: 100000 +max_tx_gas: 50000000000000 +max_gas_price: 50000000000 max_gas_computation_bucket: 5000000 gas_rounding_step: 1000 max_loop_depth: 5 diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_72.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_72.snap index c32d9ec5b9cc4..8ebc6001c4706 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_72.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__Testnet_version_72.snap @@ -103,8 +103,8 @@ binary_friend_decls: 100 max_move_object_size: 256000 max_move_package_size: 102400 max_publish_or_upgrade_per_ptb: 5 -max_tx_gas: 50000000000 -max_gas_price: 100000 +max_tx_gas: 50000000000000 +max_gas_price: 50000000000 max_gas_computation_bucket: 5000000 gas_rounding_step: 1000 max_loop_depth: 5 diff --git a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_72.snap b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_72.snap index 78edbaaadb37b..6c2fde81daa6d 100644 --- a/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_72.snap +++ b/crates/sui-protocol-config/src/snapshots/sui_protocol_config__test__version_72.snap @@ -109,8 +109,8 @@ binary_friend_decls: 100 max_move_object_size: 256000 max_move_package_size: 102400 max_publish_or_upgrade_per_ptb: 5 -max_tx_gas: 50000000000 -max_gas_price: 100000 +max_tx_gas: 50000000000000 +max_gas_price: 50000000000 max_gas_computation_bucket: 5000000 gas_rounding_step: 1000 max_loop_depth: 5 diff --git a/crates/transaction-fuzzer/src/account_universe/transfer_gen.rs b/crates/transaction-fuzzer/src/account_universe/transfer_gen.rs index b98569b597c85..9bb4ec810ac68 100644 --- a/crates/transaction-fuzzer/src/account_universe/transfer_gen.rs +++ b/crates/transaction-fuzzer/src/account_universe/transfer_gen.rs @@ -470,21 +470,21 @@ impl AUTransactionGen for P2PTransferGenRandomGasRandomPriceRandomSponsorship { }, }), RunInfo { - gas_budget_too_low: true, + gas_budget_too_high: true, .. } => Err(SuiError::UserInputError { - error: UserInputError::GasBudgetTooLow { + error: UserInputError::GasBudgetTooHigh { gas_budget: self.gas, - min_budget: PROTOCOL_CONFIG.base_tx_cost_fixed() * self.gas_price, + max_budget: PROTOCOL_CONFIG.max_tx_gas(), }, }), RunInfo { - gas_budget_too_high: true, + gas_budget_too_low: true, .. } => Err(SuiError::UserInputError { - error: UserInputError::GasBudgetTooHigh { + error: UserInputError::GasBudgetTooLow { gas_budget: self.gas, - max_budget: PROTOCOL_CONFIG.max_tx_gas(), + min_budget: PROTOCOL_CONFIG.base_tx_cost_fixed() * self.gas_price, }, }), RunInfo {