Skip to content

Commit

Permalink
Binary limits (#16684)
Browse files Browse the repository at this point in the history
## Description 

Organize better several limits...

## Test Plan 

How did you test the new or updated feature?

---
If your changes are not user-facing and do not break anything, you can
skip the following section. Otherwise, please briefly describe what has
changed under the Release Notes section.

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

- [ ] protocol change
- [ ] user-visible impact
- [ ] breaking change for a client SDKs
- [ ] breaking change for FNs (FN binary must upgrade)
- [ ] 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

---------

Co-authored-by: Ashok Menon <ashok@mystenlabs.com>
Co-authored-by: Stefan Stanciulescu <stefan.stanciulescu@mystenlabs.com>
  • Loading branch information
3 people authored Mar 16, 2024
1 parent 3de11db commit 9e8d0e3
Show file tree
Hide file tree
Showing 319 changed files with 41,979 additions and 2,691 deletions.
117 changes: 117 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ exclude = [
"external-crates/move/move-execution/v1/crates/move-bytecode-verifier",
"external-crates/move/move-execution/v1/crates/move-stdlib",
"external-crates/move/move-execution/v1/crates/move-vm-runtime",
"external-crates/move/move-execution/v2/crates/move-bytecode-verifier",
"external-crates/move/move-execution/v2/crates/move-stdlib",
"external-crates/move/move-execution/v2/crates/move-vm-runtime",
"sdk/move-bytecode-template",
]

Expand Down Expand Up @@ -183,6 +186,9 @@ members = [
"sui-execution/v1/sui-adapter",
"sui-execution/v1/sui-move-natives",
"sui-execution/v1/sui-verifier",
"sui-execution/v2/sui-adapter",
"sui-execution/v2/sui-move-natives",
"sui-execution/v2/sui-verifier",
]

[workspace.package]
Expand Down
27 changes: 8 additions & 19 deletions crates/sui-core/src/authority.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use fastcrypto::encoding::Base58;
use fastcrypto::encoding::Encoding;
use fastcrypto::hash::MultisetHash;
use itertools::Itertools;
use move_binary_format::binary_config::BinaryConfig;
use move_binary_format::CompiledModule;
use move_core_types::annotated_value::MoveStructLayout;
use move_core_types::language_storage::ModuleId;
Expand Down Expand Up @@ -156,6 +157,7 @@ use crate::transaction_manager::TransactionManager;

#[cfg(msim)]
use sui_types::committee::CommitteeTrait;
use sui_types::execution_config_utils::to_binary_config;

#[cfg(test)]
#[path = "unit_tests/authority_tests.rs"]
Expand Down Expand Up @@ -4059,8 +4061,7 @@ impl AuthorityState {
/// compatible with the current versions of those packages on-chain.
pub async fn get_available_system_packages(
&self,
max_binary_format_version: u32,
no_extraneous_module_bytes: bool,
binary_config: &BinaryConfig,
) -> Vec<ObjectRef> {
let mut results = vec![];

Expand All @@ -4084,8 +4085,7 @@ impl AuthorityState {
system_package.id(),
&modules,
system_package.dependencies().to_vec(),
max_binary_format_version,
no_extraneous_module_bytes,
binary_config,
)
.await
else {
Expand Down Expand Up @@ -4113,8 +4113,7 @@ impl AuthorityState {
async fn get_system_package_bytes(
&self,
system_packages: Vec<ObjectRef>,
move_binary_format_version: u32,
no_extraneous_module_bytes: bool,
binary_config: &BinaryConfig,
) -> Option<Vec<(SequenceNumber, Vec<Vec<u8>>, Vec<ObjectID>)>> {
let ids: Vec<_> = system_packages.iter().map(|(id, _, _)| *id).collect();
let objects = self.get_objects(&ids).await.expect("read cannot fail");
Expand Down Expand Up @@ -4151,14 +4150,7 @@ impl AuthorityState {

let modules: Vec<_> = bytes
.iter()
.map(|m| {
CompiledModule::deserialize_with_config(
m,
move_binary_format_version,
no_extraneous_module_bytes,
)
.unwrap()
})
.map(|m| CompiledModule::deserialize_with_config(m, binary_config).unwrap())
.collect();

let new_object = Object::new_system_package(
Expand Down Expand Up @@ -4415,12 +4407,9 @@ impl AuthorityState {
// since system packages are created during the current epoch, they should abide by the
// rules of the current epoch, including the current epoch's max Move binary format version
let config = epoch_store.protocol_config();
let binary_config = to_binary_config(config);
let Some(next_epoch_system_package_bytes) = self
.get_system_package_bytes(
next_epoch_system_packages.clone(),
config.move_binary_format_version(),
config.no_extraneous_module_bytes(),
)
.get_system_package_bytes(next_epoch_system_packages.clone(), &binary_config)
.await
else {
error!(
Expand Down
3 changes: 1 addition & 2 deletions crates/sui-core/src/transaction_outputs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,8 @@ impl TransactionOutputs {
mutable_inputs,
written,
events,
max_binary_format_version: _,
loaded_runtime_objects: _,
no_extraneous_module_bytes: _,
binary_config: _,
runtime_packages_loaded_from_db: _,
lamport_version,
} = inner_temporary_store;
Expand Down
10 changes: 3 additions & 7 deletions crates/sui-core/src/unit_tests/move_package_upgrade_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use sui_types::{
use std::{collections::BTreeSet, path::PathBuf, str::FromStr, sync::Arc};
use sui_types::effects::{TransactionEffects, TransactionEffectsAPI};
use sui_types::error::{SuiError, UserInputError};
use sui_types::execution_config_utils::to_binary_config;
use sui_types::execution_status::{
CommandArgumentError, ExecutionFailureStatus, ExecutionStatus, PackageUpgradeError,
};
Expand Down Expand Up @@ -269,13 +270,8 @@ async fn test_upgrade_package_happy_path() {
.unwrap()
.unwrap();
let config = ProtocolConfig::get_for_max_version_UNSAFE();
let normalized_modules = package
.move_package()
.normalize(
config.move_binary_format_version(),
config.no_extraneous_module_bytes(),
)
.unwrap();
let binary_config = to_binary_config(&config);
let normalized_modules = package.move_package().normalize(&binary_config).unwrap();
assert!(normalized_modules.contains_key("new_module"));
assert!(normalized_modules["new_module"]
.functions
Expand Down
Binary file not shown.
Binary file not shown.
7 changes: 3 additions & 4 deletions crates/sui-framework-snapshot/tests/compatibility_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ mod compatibility_tests {
use sui_framework::{compare_system_package, BuiltInFramework};
use sui_framework_snapshot::{load_bytecode_snapshot, load_bytecode_snapshot_manifest};
use sui_protocol_config::{Chain, ProtocolConfig, ProtocolVersion};
use sui_types::execution_config_utils::to_binary_config;

#[tokio::test]
async fn test_framework_compatibility() {
Expand All @@ -14,8 +15,7 @@ mod compatibility_tests {
for (version, _snapshots) in load_bytecode_snapshot_manifest() {
let config =
ProtocolConfig::get_for_version(ProtocolVersion::new(version), Chain::Unknown);
let max_binary_format_version = config.move_binary_format_version();
let no_extraneous_module_bytes = config.no_extraneous_module_bytes();
let binary_config = to_binary_config(&config);
let framework = load_bytecode_snapshot(version).unwrap();
let old_framework_store: BTreeMap<_, _> = framework
.into_iter()
Expand All @@ -27,8 +27,7 @@ mod compatibility_tests {
cur_package.id(),
&cur_package.modules(),
cur_package.dependencies().to_vec(),
max_binary_format_version,
no_extraneous_module_bytes,
&binary_config,
)
.await
.is_none()
Expand Down
21 changes: 14 additions & 7 deletions crates/sui-framework/docs/deepbook/clob_v2.md
Original file line number Diff line number Diff line change
Expand Up @@ -1132,6 +1132,15 @@ do not have this capability:



<a name="0xdee9_clob_v2_EIncorrectPoolOwner"></a>



<pre><code><b>const</b> <a href="clob_v2.md#0xdee9_clob_v2_EIncorrectPoolOwner">EIncorrectPoolOwner</a>: u64 = 1;
</code></pre>



<a name="0xdee9_clob_v2_EInvalidFee"></a>


Expand Down Expand Up @@ -1310,7 +1319,7 @@ Accessor functions
Function to withdraw fees created from a pool


<pre><code><b>public</b> <b>fun</b> <a href="clob_v2.md#0xdee9_clob_v2_withdraw_fees">withdraw_fees</a>&lt;BaseAsset, QuoteAsset&gt;(_pool_owner_cap: &<a href="clob_v2.md#0xdee9_clob_v2_PoolOwnerCap">clob_v2::PoolOwnerCap</a>, pool: &<b>mut</b> <a href="clob_v2.md#0xdee9_clob_v2_Pool">clob_v2::Pool</a>&lt;BaseAsset, QuoteAsset&gt;, ctx: &<b>mut</b> <a href="dependencies/sui-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="dependencies/sui-framework/coin.md#0x2_coin_Coin">coin::Coin</a>&lt;QuoteAsset&gt;
<pre><code><b>public</b> <b>fun</b> <a href="clob_v2.md#0xdee9_clob_v2_withdraw_fees">withdraw_fees</a>&lt;BaseAsset, QuoteAsset&gt;(pool_owner_cap: &<a href="clob_v2.md#0xdee9_clob_v2_PoolOwnerCap">clob_v2::PoolOwnerCap</a>, pool: &<b>mut</b> <a href="clob_v2.md#0xdee9_clob_v2_Pool">clob_v2::Pool</a>&lt;BaseAsset, QuoteAsset&gt;, ctx: &<b>mut</b> <a href="dependencies/sui-framework/tx_context.md#0x2_tx_context_TxContext">tx_context::TxContext</a>): <a href="dependencies/sui-framework/coin.md#0x2_coin_Coin">coin::Coin</a>&lt;QuoteAsset&gt;
</code></pre>


Expand All @@ -1320,10 +1329,11 @@ Function to withdraw fees created from a pool


<pre><code><b>public</b> <b>fun</b> <a href="clob_v2.md#0xdee9_clob_v2_withdraw_fees">withdraw_fees</a>&lt;BaseAsset, QuoteAsset&gt;(
_pool_owner_cap: &<a href="clob_v2.md#0xdee9_clob_v2_PoolOwnerCap">PoolOwnerCap</a>,
pool_owner_cap: &<a href="clob_v2.md#0xdee9_clob_v2_PoolOwnerCap">PoolOwnerCap</a>,
pool: &<b>mut</b> <a href="clob_v2.md#0xdee9_clob_v2_Pool">Pool</a>&lt;BaseAsset, QuoteAsset&gt;,
ctx: &<b>mut</b> TxContext,
): Coin&lt;QuoteAsset&gt; {
<b>assert</b>!(pool_owner_cap.owner == <a href="dependencies/sui-framework/object.md#0x2_object_uid_to_address">object::uid_to_address</a>(&pool.id), <a href="clob_v2.md#0xdee9_clob_v2_EIncorrectPoolOwner">EIncorrectPoolOwner</a>);
<b>let</b> quantity = <a href="clob_v2.md#0xdee9_clob_v2_quote_asset_trading_fees_value">quote_asset_trading_fees_value</a>(pool);
<b>let</b> to_withdraw = <a href="dependencies/sui-framework/balance.md#0x2_balance_split">balance::split</a>(&<b>mut</b> pool.quote_asset_trading_fees, quantity);
<a href="dependencies/sui-framework/coin.md#0x2_coin_from_balance">coin::from_balance</a>(to_withdraw, ctx)
Expand Down Expand Up @@ -1569,11 +1579,8 @@ Helper function that all the create pools now call to create pools.

// Creates the capability <b>to</b> mark a pool owner.
<b>let</b> id = <a href="dependencies/sui-framework/object.md#0x2_object_new">object::new</a>(ctx);
<b>let</b> owner = <a href="dependencies/sui-framework/object.md#0x2_object_uid_to_address">object::uid_to_address</a>(&id);
<b>let</b> pool_owner_cap = <a href="clob_v2.md#0xdee9_clob_v2_PoolOwnerCap">PoolOwnerCap</a> {
id,
owner
};
<b>let</b> owner = <a href="dependencies/sui-framework/object.md#0x2_object_uid_to_address">object::uid_to_address</a>(&pool_uid);
<b>let</b> pool_owner_cap = <a href="clob_v2.md#0xdee9_clob_v2_PoolOwnerCap">PoolOwnerCap</a> { id, owner };

<a href="dependencies/sui-framework/event.md#0x2_event_emit">event::emit</a>(<a href="clob_v2.md#0xdee9_clob_v2_PoolCreated">PoolCreated</a> {
pool_id,
Expand Down
Loading

0 comments on commit 9e8d0e3

Please sign in to comment.