Deep dive into Sui’s gas mechanism, including computation costs, storage fees, and economic incentives.
Sui’s gas mechanism is designed to be transparent, predictable, and sustainable. It separates computation costs from storage costs and implements a storage rebate system for long-term sustainability.
pub struct GasCostSummary { /// Cost of computation/execution pub computation_cost: u64, /// Storage cost, it's the sum of all storage cost for all objects created or mutated pub storage_cost: u64, /// The amount of storage cost refunded to the user for all objects deleted or mutated pub storage_rebate: u64, /// The fee for the rebate. The portion of the storage rebate kept by the system pub non_refundable_storage_fee: u64,}
Total cost:
Total = computation_cost + storage_cost - storage_rebate
/// Return the `value: u64` field of a `Coin<T>` type./// Useful for reading the coin without deserializing the object into a Move valuepub fn get_coin_value_unsafe(&self) -> u64 { debug_assert!(self.type_.is_coin()); // 32 bytes for object ID, 8 for balance debug_assert!(self.contents.len() == 40); u64::from_le_bytes(<[u8; 8]>::try_from(&self.contents[ID_END_INDEX..]).unwrap())}/// Update the `value: u64` field of a `Coin<T>` type.pub fn set_coin_value_unsafe(&mut self, value: u64) { debug_assert!(self.type_.is_coin()); self.contents.splice(ID_END_INDEX.., value.to_le_bytes());}
Coins have fixed 40-byte layout enabling direct balance access without full deserialization.