From 0516ce15a25b1c9b726425216fe50a3f53390612 Mon Sep 17 00:00:00 2001 From: George Mitenkov Date: Tue, 12 Nov 2024 18:10:46 +0000 Subject: [PATCH] [fix] Fix & improve script benchmark --- .../src/publishing/raw_module_data.rs | 59 ++++++++++++++----- testsuite/module-publish/src/main.rs | 13 +++- .../src/packages/simple/scripts/main.move | 51 +++++++++++++--- 3 files changed, 100 insertions(+), 23 deletions(-) diff --git a/crates/transaction-generator-lib/src/publishing/raw_module_data.rs b/crates/transaction-generator-lib/src/publishing/raw_module_data.rs index 24e41f46998006..f3edf4b7134d2e 100644 --- a/crates/transaction-generator-lib/src/publishing/raw_module_data.rs +++ b/crates/transaction-generator-lib/src/publishing/raw_module_data.rs @@ -3864,10 +3864,10 @@ pub static MODULES_MODULE_LOADING_CHAIN_FRIENDS: Lazy>> = Lazy::new( pub static PACKAGE_SIMPLE_METADATA: Lazy> = Lazy::new(|| { vec![ 13, 71, 101, 110, 101, 114, 105, 99, 77, 111, 100, 117, 108, 101, 1, 0, 0, 0, - 0, 0, 0, 0, 0, 64, 69, 53, 53, 57, 68, 57, 51, 68, 67, 55, 70, 65, - 56, 70, 70, 66, 70, 53, 70, 65, 57, 48, 49, 52, 57, 69, 49, 65, 56, 48, - 56, 55, 57, 67, 65, 52, 56, 50, 66, 67, 52, 67, 48, 50, 48, 51, 51, 50, - 53, 53, 52, 67, 50, 67, 48, 52, 49, 56, 67, 54, 56, 56, 53, 69, 132, 1, + 0, 0, 0, 0, 0, 64, 57, 66, 56, 48, 68, 66, 66, 50, 48, 57, 69, 66, + 57, 49, 51, 54, 51, 56, 57, 55, 51, 65, 50, 67, 48, 67, 52, 70, 52, 67, + 51, 54, 69, 50, 49, 52, 48, 48, 57, 70, 56, 66, 53, 70, 68, 68, 53, 68, + 69, 51, 48, 65, 49, 54, 55, 67, 67, 66, 49, 57, 68, 55, 70, 68, 132, 1, 31, 139, 8, 0, 0, 0, 0, 0, 2, 255, 77, 139, 59, 14, 194, 48, 16, 68, 251, 61, 133, 229, 30, 135, 11, 80, 208, 64, 197, 9, 162, 20, 43, 123, 64, 86, 156, 93, 203, 134, 80, 32, 238, 142, 45, 1, 138, 102, 154, 249, 188, 49, 179, 159, @@ -3887,16 +3887,6 @@ pub static PACKAGE_SIMPLE_METADATA: Lazy> = Lazy::new(|| { ] }); -#[rustfmt::skip] -pub static SCRIPT_SIMPLE: Lazy> = Lazy::new(|| { - vec![ - 161, 28, 235, 11, 7, 0, 0, 10, 2, 5, 0, 4, 6, 4, 34, 1, 6, 12, - 0, 5, 32, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, - 0, 1, 3, 11, 0, 1, 2, - ] -}); - #[rustfmt::skip] pub static MODULE_SIMPLE_SIMPLE: Lazy> = Lazy::new(|| { vec![ @@ -4100,6 +4090,47 @@ pub static MODULE_SIMPLE_SIMPLE: Lazy> = Lazy::new(|| { ] }); +#[rustfmt::skip] +pub static SCRIPT_SIMPLE: Lazy> = Lazy::new(|| { + vec![ + 161, 28, 235, 11, 7, 0, 0, 10, 7, 1, 0, 2, 3, 2, 7, 4, 9, 2, + 5, 11, 32, 7, 43, 27, 8, 70, 64, 16, 134, 1, 31, 1, 2, 0, 3, 4, + 5, 1, 0, 1, 0, 3, 1, 6, 12, 0, 1, 3, 1, 10, 3, 1, 6, 9, + 0, 1, 10, 2, 1, 2, 11, 3, 3, 3, 3, 3, 3, 1, 1, 1, 10, 3, + 10, 2, 8, 60, 83, 69, 76, 70, 62, 95, 48, 4, 109, 97, 105, 110, 3, 98, + 99, 115, 8, 116, 111, 95, 98, 121, 116, 101, 115, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, 255, + 255, 255, 255, 255, 255, 255, 255, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, + 0, 0, 1, 20, 99, 111, 109, 112, 105, 108, 97, 116, 105, 111, 110, 95, 109, 101, + 116, 97, 100, 97, 116, 97, 9, 0, 3, 50, 46, 48, 3, 50, 46, 49, 0, 0, + 7, 139, 1, 6, 23, 0, 0, 0, 0, 0, 0, 0, 12, 1, 11, 0, 1, 10, + 1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 36, 4, 13, 11, 1, 6, 1, 0, + 0, 0, 0, 0, 0, 0, 23, 12, 1, 5, 4, 6, 0, 0, 0, 0, 0, 0, + 0, 0, 12, 2, 6, 0, 0, 0, 0, 0, 0, 0, 0, 12, 3, 10, 1, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 36, 4, 86, 11, 1, 6, 1, 0, 0, 0, + 0, 0, 0, 0, 23, 12, 1, 11, 2, 6, 1, 0, 0, 0, 0, 0, 0, 0, + 22, 12, 4, 11, 3, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 12, 5, 10, + 4, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 11, 4, 23, 12, 3, 10, 5, + 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 10, 5, 23, 12, 4, 10, 4, 6, + 1, 0, 0, 0, 0, 0, 0, 0, 22, 12, 2, 10, 4, 10, 2, 36, 4, 83, + 10, 2, 10, 5, 36, 12, 7, 11, 7, 4, 80, 11, 5, 10, 3, 36, 12, 8, + 11, 8, 4, 77, 10, 3, 11, 4, 36, 12, 9, 11, 9, 3, 72, 5, 17, 11, + 1, 6, 1, 0, 0, 0, 0, 0, 0, 0, 22, 12, 1, 5, 17, 9, 12, 9, + 5, 69, 9, 12, 8, 5, 63, 9, 12, 7, 5, 57, 6, 5, 0, 0, 0, 0, + 0, 0, 0, 12, 1, 64, 2, 0, 0, 0, 0, 0, 0, 0, 0, 12, 10, 6, + 0, 0, 0, 0, 0, 0, 0, 0, 12, 2, 10, 2, 6, 20, 0, 0, 0, 0, + 0, 0, 0, 35, 4, 104, 13, 10, 10, 2, 68, 2, 11, 2, 6, 1, 0, 0, + 0, 0, 0, 0, 0, 22, 12, 2, 5, 92, 6, 0, 0, 0, 0, 0, 0, 0, + 0, 12, 2, 10, 1, 6, 0, 0, 0, 0, 0, 0, 0, 0, 36, 4, 130, 1, + 14, 10, 56, 0, 12, 11, 11, 2, 12, 3, 14, 11, 6, 0, 0, 0, 0, 0, + 0, 0, 0, 66, 6, 20, 52, 12, 4, 11, 3, 11, 4, 22, 12, 2, 11, 1, + 6, 1, 0, 0, 0, 0, 0, 0, 0, 23, 12, 1, 5, 106, 11, 1, 6, 64, + 66, 15, 0, 0, 0, 0, 0, 33, 4, 135, 1, 5, 136, 1, 5, 138, 1, 5, + 136, 1, 5, 138, 1, 2, + ] +}); + #[rustfmt::skip] pub static MODULES_SIMPLE: Lazy>> = Lazy::new(|| { vec![ MODULE_SIMPLE_SIMPLE.to_vec(), diff --git a/testsuite/module-publish/src/main.rs b/testsuite/module-publish/src/main.rs index 7be0b3756122f9..aac459c7463664 100644 --- a/testsuite/module-publish/src/main.rs +++ b/testsuite/module-publish/src/main.rs @@ -150,7 +150,8 @@ fn write_package(file: &mut File, package_path: PathBuf, package_name: &str) -> // build package let package = BuiltPackage::build(package_path, BuildOptions::move_2()) .expect("building package must succeed"); - let code = package.extract_code(); + let modules = package.extract_code(); + let scripts = package.extract_script_code(); let package_metadata = package.extract_metadata().expect("Metadata must exist"); let metadata = bcs::to_bytes(&package_metadata).expect("Metadata must serialize"); @@ -164,7 +165,7 @@ fn write_package(file: &mut File, package_path: PathBuf, package_name: &str) -> let mut module_names = Vec::new(); // write out all modules - for module in &code { + for module in &modules { // this is an unfortunate way to find the module name but it is not // clear how to do it otherwise let compiled_module = CompiledModule::deserialize(module).expect("Module must deserialize"); @@ -180,6 +181,14 @@ fn write_package(file: &mut File, package_path: PathBuf, package_name: &str) -> module_names.push(name); } + // write out scripts (allow a single script for now) + assert!(scripts.len() <= 1); + for script in &scripts { + let name: String = format!("SCRIPT_{}", package_name.to_uppercase(),); + writeln!(file).expect("Empty line failed"); + write_lazy(file, name.as_str(), script); + } + writeln!(file).expect("Empty line failed"); writeln!(file, "#[rustfmt::skip]").expect("rustfmt skip failed"); writeln!( diff --git a/testsuite/module-publish/src/packages/simple/scripts/main.move b/testsuite/module-publish/src/packages/simple/scripts/main.move index 0c6c4767afb65d..b41d1fc0de31ef 100644 --- a/testsuite/module-publish/src/packages/simple/scripts/main.move +++ b/testsuite/module-publish/src/packages/simple/scripts/main.move @@ -2,16 +2,53 @@ script { // Note: this constant can be replaced in compiled script to make it hash to a different value. const SENDER: address = @0x1; - fun main(sender: &signer) { + fun main(_sender: &signer) { // The idea is to to ensure that this script takes some time to be deserialized and verified, but the actual // execution time is small (no-op). - if (false) { - 0xABCD::simple::loop_nop(sender, 0); - 0xABCD::simple::loop_arithmetic(sender, 0); - 0xABCD::simple::loop_bcs(sender, 0, 0); - if (false) { - while (true) {} + let count = 23; + while (count > 0) { + count = count - 1; + }; + + let a; + let b = 0; + let c; + let d = 0; + while (count > 0) { + count = count - 1; + + a = b + 1; + c = d + 1; + b = a + 1; + d = b - a; + b = c + 1; + a = b - c; + b = a + 1; + + // can never be true + if (a > b && b > c && c > d && d > a) { + count = count + 1; } + }; + + let count = 5; + let vec = std::vector::empty(); + let i = 0; + while (i < 20) { + std::vector::push_back(&mut vec, i); + i = i + 1; + }; + + let sum: u64 = 0; + + while (count > 0) { + let val = std::bcs::to_bytes(&vec); + sum = sum + ((*std::vector::borrow(&val, 0)) as u64); + count = count - 1; + }; + + if (count == 1000000) { + while (true) {} } } }