diff --git a/Cargo.lock b/Cargo.lock index d779980a4c3..19da7df0054 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1039,9 +1039,9 @@ dependencies = [ [[package]] name = "clap" -version = "3.2.24" +version = "3.2.25" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "eef2b3ded6a26dfaec672a742c93c8cf6b689220324da509ec5caa20de55dc83" +checksum = "4ea181bf566f71cb9a5d17a59e1871af638180a18fb0035c92ae62b705207123" dependencies = [ "bitflags", "clap_lex 0.2.4", @@ -1051,9 +1051,9 @@ dependencies = [ [[package]] name = "clap" -version = "4.2.4" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "956ac1f6381d8d82ab4684768f89c0ea3afe66925ceadb4eeb3fc452ffc55d62" +checksum = "8a1f23fa97e1d1641371b51f35535cb26959b8e27ab50d167a8b996b5bada819" dependencies = [ "clap_builder", "clap_derive", @@ -1062,9 +1062,9 @@ dependencies = [ [[package]] name = "clap_builder" -version = "4.2.4" +version = "4.2.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "84080e799e54cff944f4b4a4b0e71630b0e0443b25b985175c7dddc1a859b749" +checksum = "0fdc5d93c358224b4d6867ef1356d740de2303e9892edc06c5340daeccd96bab" dependencies = [ "anstream", "anstyle", @@ -1404,7 +1404,7 @@ dependencies = [ "atty", "cast", "ciborium", - "clap 3.2.24", + "clap 3.2.25", "criterion-plot", "itertools", "lazy_static", @@ -2545,7 +2545,7 @@ dependencies = [ "async-graphql", "async-trait", "axum", - "clap 4.2.4", + "clap 4.2.5", "derive_more", "enum-iterator", "fuel-core-chain-config", @@ -2591,7 +2591,7 @@ dependencies = [ name = "fuel-core-benches" version = "0.0.0" dependencies = [ - "clap 4.2.4", + "clap 4.2.5", "criterion", "ctrlc", "fuel-core", @@ -2617,7 +2617,7 @@ name = "fuel-core-bin" version = "0.18.0" dependencies = [ "anyhow", - "clap 4.2.4", + "clap 4.2.5", "const_format", "dirs", "fuel-core", @@ -2678,7 +2678,7 @@ dependencies = [ name = "fuel-core-client-bin" version = "0.18.0" dependencies = [ - "clap 4.2.4", + "clap 4.2.5", "fuel-core-client", "fuel-core-types", "serde_json", @@ -2764,7 +2764,7 @@ name = "fuel-core-keygen" version = "0.18.0" dependencies = [ "anyhow", - "clap 4.2.4", + "clap 4.2.5", "fuel-core-types", "libp2p-core 0.38.0", "serde_json", @@ -4519,7 +4519,7 @@ version = "0.6.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "d7b603516767d1ab23d0de09d023e62966c3322f7148297c35cf3d97aa8b37fa" dependencies = [ - "clap 4.2.4", + "clap 4.2.5", "termcolor", "threadpool", ] @@ -4543,9 +4543,9 @@ checksum = "0717cef1bc8b636c6e1c1bbdefc09e6322da8a9321966e8928ef80d20f7f770f" [[package]] name = "linux-raw-sys" -version = "0.3.4" +version = "0.3.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36eb31c1778188ae1e64398743890d0877fef36d11521ac60406b42016e8c2cf" +checksum = "2e8776872cdc2f073ccaab02e336fa321328c1e02646ebcb9d2108d0baab480d" [[package]] name = "lock_api" @@ -8437,7 +8437,7 @@ dependencies = [ name = "xtask" version = "0.0.0" dependencies = [ - "clap 4.2.4", + "clap 4.2.5", "fuel-core", ] diff --git a/benches/benches/set/blockchain.rs b/benches/benches/set/blockchain.rs index bd5d47ce995..dc151d7a0b0 100644 --- a/benches/benches/set/blockchain.rs +++ b/benches/benches/set/blockchain.rs @@ -6,6 +6,7 @@ use criterion::{ Criterion, Throughput, }; +use fuel_core::database::vm_database::VmDatabase; use fuel_core_benches::*; use fuel_core_storage::ContractsAssetsStorage; use fuel_core_types::{ @@ -251,7 +252,7 @@ pub fn run(c: &mut Criterion) { op::add(0x15, 0x15, 0x15), op::addi(0x15, 0x15, 32), op::aloc(0x15), - op::addi(0x15, RegId::HP, 1), + op::move_(0x15, RegId::HP), ]; ccp.throughput(Throughput::Bytes(i)); @@ -308,7 +309,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::bhsh(0x10, RegId::ZERO)).with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), ]), ); @@ -332,7 +333,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::cb(0x10)).with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), ]), ); @@ -404,7 +405,7 @@ pub fn run(c: &mut Criterion) { op::gtf_args(0x16, 0x00, GTFArgs::ScriptData), op::movi(0x15, 2000), op::aloc(0x15), - op::addi(0x14, RegId::HP, 1), + op::move_(0x14, RegId::HP), ]); run_group_ref(&mut c.benchmark_group("croo"), "croo", input); } @@ -426,14 +427,21 @@ pub fn run(c: &mut Criterion) { for i in linear.clone() { let mut input = VmBench::contract(rng, op::smo(0x15, 0x16, 0x17, 0x18)) .expect("failed to prepare contract"); - let index = input.outputs.len() - 1; + input.prepare_db = Some(Box::new(|mut db: VmDatabase| { + db.merkle_contract_asset_id_balance_insert( + &ContractId::default(), + &AssetId::default(), + Word::MAX, + )?; + Ok(db) + })); input.post_call.extend(vec![ op::gtf_args(0x15, 0x00, GTFArgs::ScriptData), - // Offset 32 + 8+ 8 + 32 - op::addi(0x15, 0x15, 32 + 8 + 8 + 32), - op::movi(0x16, i.try_into().unwrap()), - op::movi(0x17, index.try_into().unwrap()), - op::movi(0x18, 10), + // Offset 32 + 8 + 8 + 32 + op::addi(0x15, 0x15, 32 + 8 + 8 + 32), // target address pointer + op::addi(0x16, 0x15, 32), // data ppinter + op::movi(0x17, i.try_into().unwrap()), // data length + op::movi(0x18, 10), // coins to send ]); input.data.extend( Address::new([1u8; 32]) @@ -475,7 +483,7 @@ pub fn run(c: &mut Criterion) { op::muli(0x15, 0x15, 32), op::addi(0x15, 0x15, 1), op::aloc(0x15), - op::addi(0x14, RegId::HP, 1), + op::move_(0x14, RegId::HP), ]; let mut bench = VmBench::contract(rng, op::srwq(0x14, 0x11, 0x27, 0x16)) .expect("failed to prepare contract") diff --git a/benches/benches/set/crypto.rs b/benches/benches/set/crypto.rs index 31003ecabb9..3bbfb6c84a8 100644 --- a/benches/benches/set/crypto.rs +++ b/benches/benches/set/crypto.rs @@ -29,7 +29,7 @@ pub fn run(c: &mut Criterion) { op::addi(0x22, 0x21, message.as_ref().len().try_into().unwrap()), op::movi(0x10, PublicKey::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x11, RegId::HP, 1), + op::move_(0x11, RegId::HP), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), ); @@ -41,7 +41,7 @@ pub fn run(c: &mut Criterion) { .with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), op::movi(0x11, 32), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), @@ -54,7 +54,7 @@ pub fn run(c: &mut Criterion) { .with_prepare_script(vec![ op::movi(0x10, Bytes32::LEN.try_into().unwrap()), op::aloc(0x10), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), op::movi(0x11, 32), ]) .with_data(signature.iter().chain(message.iter()).copied().collect()), diff --git a/benches/benches/set/mem.rs b/benches/benches/set/mem.rs index d946e9379d8..10fe1921c61 100644 --- a/benches/benches/set/mem.rs +++ b/benches/benches/set/mem.rs @@ -9,6 +9,18 @@ use criterion::{ use fuel_core_benches::*; use fuel_core_types::fuel_asm::*; +/// Set a register `r` to a Word-sized number value using left-shifts +fn set_full_word(r: RegisterId, v: Word) -> Vec { + let r = u8::try_from(r).unwrap(); + let mut ops = vec![op::movi(r, 0)]; + for byte in v.to_be_bytes() { + ops.push(op::ori(r, r, byte as u16)); + ops.push(op::slli(r, r, 8)); + } + ops.pop().unwrap(); // Remove last shift + ops +} + pub fn run(c: &mut Criterion) { run_group_ref( &mut c.benchmark_group("lb"), @@ -27,7 +39,7 @@ pub fn run(c: &mut Criterion) { "sb", VmBench::new(op::sb(0x10, 0x11, 0)).with_prepare_script(vec![ op::aloc(RegId::ONE), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), op::movi(0x11, 50), ]), ); @@ -38,7 +50,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::sw(0x10, 0x11, 0)).with_prepare_script(vec![ op::movi(0x10, 8), op::aloc(0x10), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), op::movi(0x11, 50), ]), ); @@ -66,7 +78,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::mcl(0x10, 0x11)).with_prepare_script(vec![ op::movi(0x11, *i), op::aloc(0x11), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), ]), ); } @@ -81,7 +93,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::mcli(0x10, *i)).with_prepare_script(vec![ op::movi(0x11, *i), op::aloc(0x11), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), ]), ); } @@ -96,7 +108,7 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::mcp(0x10, RegId::ZERO, 0x11)).with_prepare_script(vec![ op::movi(0x11, *i), op::aloc(0x11), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), ]), ); } @@ -108,21 +120,23 @@ pub fn run(c: &mut Criterion) { VmBench::new(op::mcpi(0x10, RegId::ZERO, 4000)).with_prepare_script(vec![ op::movi(0x11, 4000), op::aloc(0x11), - op::addi(0x10, RegId::HP, 1), + op::move_(0x10, RegId::HP), ]), ); let mut mem_meq = c.benchmark_group("meq"); for i in &linear { mem_meq.throughput(Throughput::Bytes(*i as u64)); + + let mut prepare_script = vec![op::movi(0x11, 0)]; + prepare_script.extend(set_full_word(0x12, (i * 3) as u64)); + prepare_script.extend(set_full_word(0x13, (*i) as u64)); + run_group_ref( &mut mem_meq, format!("{i}"), - VmBench::new(op::meq(0x10, 0x11, 0x12, 0x13)).with_prepare_script(vec![ - op::movi(0x11, 0), - op::movi(0x12, i * 3), - op::movi(0x13, *i), - ]), + VmBench::new(op::meq(0x10, 0x11, 0x12, 0x13)) + .with_prepare_script(prepare_script), ); } mem_meq.finish(); diff --git a/crates/fuel-core/src/executor.rs b/crates/fuel-core/src/executor.rs index 17677fc0420..4d26a3d522e 100644 --- a/crates/fuel-core/src/executor.rs +++ b/crates/fuel-core/src/executor.rs @@ -1952,9 +1952,8 @@ mod tests { // Allocate 32 bytes on the heap. op::aloc(0x11), // Store the pointer to the beginning of the free memory into - // register `0x10`. It requires shifting of `RegId::HP` by 1 to point - // on the free memory. - op::addi(0x10, RegId::HP, 0), + // register `0x10`. + op::move_(0x10, RegId::HP), // Store `config_coinbase` `Address` into MEM[$0x10; 32]. op::cb(0x10), // Store the pointer on the beginning of script data into register `0x12`. diff --git a/tests/tests/contract.rs b/tests/tests/contract.rs index 2f2ecba2772..38fb86f9837 100644 --- a/tests/tests/contract.rs +++ b/tests/tests/contract.rs @@ -162,7 +162,7 @@ async fn can_get_message_proof() { // Set the location in memory to write the bytes to. op::movi(0x11, 100), op::aloc(0x11), - op::addi(0x11, RegId::HP, 1), + op::move_(0x11, RegId::HP), op::movi(0x13, 2), // Write read to 0x11. // Write status to 0x30. diff --git a/tests/tests/messages.rs b/tests/tests/messages.rs index 9cacd24f486..fb222c4cbbf 100644 --- a/tests/tests/messages.rs +++ b/tests/tests/messages.rs @@ -221,12 +221,12 @@ async fn can_get_message_proof() { // of the message recipient. op::addi(0x10, 0x10, starting_offset), ]; - contract.extend(args.iter().enumerate().flat_map(|(index, arg)| { + contract.extend(args.iter().flat_map(|arg| { [ + // Pointer to the message in memory + op::addi(0x11, 0x10, 32), // The length of the message data in memory. - op::movi(0x11, arg.message_data.len() as u32), - // The index of the of the output message in the transactions outputs. - op::movi(0x12, (index + 1) as u32), + op::movi(0x12, arg.message_data.len() as u32), // The amount to send in coins. op::movi(0x13, amount), // Send the message output.