diff --git a/forc-pkg/src/pkg.rs b/forc-pkg/src/pkg.rs index 19291e0d0ce..50d8b24c703 100644 --- a/forc-pkg/src/pkg.rs +++ b/forc-pkg/src/pkg.rs @@ -46,7 +46,7 @@ use sway_core::{ transform::AttributeKind, write_dwarf, BuildTarget, Engines, FinalizedEntry, LspConfig, }; -use sway_core::{PrintAsm, PrintIr}; +use sway_core::{set_bytecode_configurables_offset, PrintAsm, PrintIr}; use sway_error::{error::CompileError, handler::Handler, warning::CompileWarning}; use sway_features::ExperimentalFeatures; use sway_types::constants::{CORE, PRELUDE, STD}; @@ -1914,7 +1914,7 @@ pub fn compile( let errored = handler.has_errors() || (handler.has_warnings() && profile.error_on_warnings); - let compiled = match bc_res { + let mut compiled = match bc_res { Ok(compiled) if !errored => compiled, _ => return fail(handler), }; @@ -1923,9 +1923,12 @@ pub fn compile( print_warnings(engines.se(), terse_mode, &pkg.name, &warnings, &tree_type); + // Metadata to be placed into the binary. + let mut md = [0u8, 0, 0, 0, 0, 0, 0, 0]; // TODO: This should probably be in `fuel_abi_json::generate_json_abi_program`? // If ABI requires knowing config offsets, they should be inputs to ABI gen. if let ProgramABI::Fuel(ref mut program_abi) = program_abi { + let mut configurables_offset = compiled.bytecode.len() as u64; if let Some(ref mut configurables) = program_abi.configurables { // Filter out all dead configurables (i.e. ones without offsets in the bytecode) configurables.retain(|c| { @@ -1934,12 +1937,22 @@ pub fn compile( .contains_key(&c.name) }); // Set the actual offsets in the JSON object - for (config, offset) in compiled.named_data_section_entries_offsets { - if let Some(idx) = configurables.iter().position(|c| c.name == config) { - configurables[idx].offset = offset; + for (config, offset) in &compiled.named_data_section_entries_offsets { + if *offset < configurables_offset { + configurables_offset = *offset; + } + if let Some(idx) = configurables.iter().position(|c| &c.name == config) { + configurables[idx].offset = *offset; } } } + + md = configurables_offset.to_be_bytes(); + } + + // We know to set the metadata only for fuelvm right now. + if let BuildTarget::Fuel = pkg.target { + set_bytecode_configurables_offset(&mut compiled, &md); } metrics.bytecode_size = compiled.bytecode.len(); diff --git a/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json b/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json index 81b65c43cd7..c51c80ae2e9 100644 --- a/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json +++ b/forc-plugins/forc-client/test/data/deployed_script/deployed_script-loader-abi.json @@ -251,62 +251,62 @@ { "name": "BOOL", "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", - "offset": 136 + "offset": 240 }, { "name": "U8", "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", - "offset": 248 + "offset": 352 }, { "name": "U16", "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", - "offset": 192 + "offset": 296 }, { "name": "U32", "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", - "offset": 232 + "offset": 336 }, { "name": "U64", "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", - "offset": 240 + "offset": 344 }, { "name": "U256", "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", - "offset": 200 + "offset": 304 }, { "name": "B256", "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", - "offset": 104 + "offset": 208 }, { "name": "STR_4", "concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a", - "offset": 176 + "offset": 280 }, { "name": "TUPLE", "concreteTypeId": "e0128f7be9902d1fe16326cafe703b52038064a7997b03ebfc1c9dd607e1536c", - "offset": 184 + "offset": 288 }, { "name": "ARRAY", "concreteTypeId": "d9fac01ab38fe10950758ae9604da330d6406a71fda3ef1ea818121261132d56", - "offset": 88 + "offset": 192 }, { "name": "STRUCT", "concreteTypeId": "563310524b4f4447a10d0e50556310253dfb3b5eb4b29c3773222b737c8b7075", - "offset": 160 + "offset": 264 }, { "name": "ENUM", "concreteTypeId": "37cd1cba311039a851ac8bfa614cc41359b4ad95c8656fcef2e8f504fe7a1272", - "offset": 144 + "offset": 248 } ] } \ No newline at end of file diff --git a/forc-plugins/forc-client/tests/deploy.rs b/forc-plugins/forc-client/tests/deploy.rs index dae3c123f51..8f428a6aa6e 100644 --- a/forc-plugins/forc-client/tests/deploy.rs +++ b/forc-plugins/forc-client/tests/deploy.rs @@ -373,7 +373,7 @@ async fn test_simple_deploy() { node.kill().unwrap(); let expected = vec![DeployedPackage::Contract(DeployedContract { id: ContractId::from_str( - "e50f0b4b396504398c0aff45951b1e44e108399c856cb92257dfa58fe96d53eb", + "adcd0480deb735ffd8f5bd0683b66c55465e0841076efca4c28be25c767ede5b", ) .unwrap(), proxy: None, @@ -416,7 +416,7 @@ async fn test_deploy_submit_only() { node.kill().unwrap(); let expected = vec![DeployedPackage::Contract(DeployedContract { id: ContractId::from_str( - "e50f0b4b396504398c0aff45951b1e44e108399c856cb92257dfa58fe96d53eb", + "adcd0480deb735ffd8f5bd0683b66c55465e0841076efca4c28be25c767ede5b", ) .unwrap(), proxy: None, @@ -462,12 +462,12 @@ async fn test_deploy_fresh_proxy() { node.kill().unwrap(); let impl_contract = DeployedPackage::Contract(DeployedContract { id: ContractId::from_str( - "e50f0b4b396504398c0aff45951b1e44e108399c856cb92257dfa58fe96d53eb", + "adcd0480deb735ffd8f5bd0683b66c55465e0841076efca4c28be25c767ede5b", ) .unwrap(), proxy: Some( ContractId::from_str( - "1c50e2d4d602fdd88b47fb7b84b7f87bbdefcf9b7e5985bb7ceeee9266a8e977", + "5297238a1d867c9d7c8fa83c700e2d0d1c57e1874ec95ff4a67063e222ab1880", ) .unwrap(), ), diff --git a/forc-test/src/execute.rs b/forc-test/src/execute.rs index 3436261af94..76e89324903 100644 --- a/forc-test/src/execute.rs +++ b/forc-test/src/execute.rs @@ -9,7 +9,7 @@ use fuel_vm::{ self as vm, checked_transaction::builder::TransactionBuilderExt, interpreter::{Interpreter, NotSupportedEcal}, - prelude::{Instruction, SecretKey}, + prelude::SecretKey, storage::MemoryStorage, }; use rand::{Rng, SeedableRng}; @@ -246,18 +246,21 @@ impl TestExecutor { /// The following is how the beginning of the bytecode is laid out: /// /// ```ignore -/// [0] ji i4 ; Jumps to the data section setup. -/// [1] noop -/// [2] DATA_SECTION_OFFSET[0..32] -/// [3] DATA_SECTION_OFFSET[32..64] -/// [4] lw $ds $is 1 ; The data section setup, i.e. where the first ji lands. -/// [5] add $$ds $$ds $is -/// [6] ; This is where we want to jump from to our test code! +/// [ 0] ji i(4 + 2) ; Jumps to the data section setup. +/// [ 1] noop +/// [ 2] DATA_SECTION_OFFSET[0..32] +/// [ 3] DATA_SECTION_OFFSET[32..64] +/// [ 4] CONFIGURABLES_OFFSET[0..32] +/// [ 5] CONFIGURABLES_OFFSET[32..64] +/// [ 6] lw $ds $is 1 ; The data section setup, i.e. where the first ji lands. +/// [ 7] add $$ds $$ds $is +/// [ 8] ; This is where we want to jump from to our test code! /// ``` fn patch_test_bytecode(bytecode: &[u8], test_offset: u32) -> std::borrow::Cow<[u8]> { - // TODO: Standardize this or add metadata to bytecode. - const PROGRAM_START_INST_OFFSET: u32 = 6; - const PROGRAM_START_BYTE_OFFSET: usize = PROGRAM_START_INST_OFFSET as usize * Instruction::SIZE; + // Each instruction is 4 bytes, + // so we divide the total byte-size by 4 to get the instruction offset. + const PROGRAM_START_INST_OFFSET: u32 = (sway_core::PRELUDE_SIZE_IN_BYTES / 4) as u32; + const PROGRAM_START_BYTE_OFFSET: usize = sway_core::PRELUDE_SIZE_IN_BYTES; // If our desired entry point is the program start, no need to jump. if test_offset == PROGRAM_START_INST_OFFSET { diff --git a/forc/src/cli/commands/parse_bytecode.rs b/forc/src/cli/commands/parse_bytecode.rs index f4a30c82d6d..4d5ecf0bdb6 100644 --- a/forc/src/cli/commands/parse_bytecode.rs +++ b/forc/src/cli/commands/parse_bytecode.rs @@ -59,6 +59,14 @@ pub(crate) fn exec(command: Command) -> ForcResult<()> { parsed_raw ) } + Err(fuel_asm::InvalidOpcode) if word_ix == 4 || word_ix == 5 => { + let parsed_raw = u32::from_be_bytes([raw[0], raw[1], raw[2], raw[3]]); + format!( + "configurables offset {} ({})", + if word_ix == 4 { "lo" } else { "hi" }, + parsed_raw + ) + } Ok(_) | Err(fuel_asm::InvalidOpcode) => "".into(), }; table.add_row(Row::new(vec![ diff --git a/forc/tests/cli_integration.rs b/forc/tests/cli_integration.rs index 407cda7489d..7aaf4f054de 100644 --- a/forc/tests/cli_integration.rs +++ b/forc/tests/cli_integration.rs @@ -49,10 +49,10 @@ fn test_forc_test_raw_logs() -> Result<(), rexpect::error::Error> { // Assert that the output is correct process.exp_string(" test test_log_4")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12660,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.exp_string(" test test_log_2")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12660,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.process.exit()?; Ok(()) @@ -74,11 +74,11 @@ fn test_forc_test_both_logs() -> Result<(), rexpect::error::Error> { process.exp_string(" test test_log_4")?; process.exp_string("Decoded log value: 4, log rb: 1515152261580153489")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000004","digest":"8005f02d43fa06e7d0585fb64c961d57e318b27a145c857bcd3a6bdb413ff7fc","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12660,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.exp_string(" test test_log_2")?; process.exp_string("Decoded log value: 2, log rb: 1515152261580153489")?; process.exp_string("Raw logs:")?; - process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12652,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; + process.exp_string(r#"[{"LogData":{"data":"0000000000000002","digest":"cd04a4754498e06db5a13c5f371f1f04ff6d2470f24aa9bd886540e5dce77f70","id":"0000000000000000000000000000000000000000000000000000000000000000","is":10368,"len":8,"pc":12660,"ptr":67107840,"ra":0,"rb":1515152261580153489}}]"#)?; process.process.exit()?; Ok(()) } diff --git a/sway-core/src/asm_generation/finalized_asm.rs b/sway-core/src/asm_generation/finalized_asm.rs index ce3c81e3a56..c132d687855 100644 --- a/sway-core/src/asm_generation/finalized_asm.rs +++ b/sway-core/src/asm_generation/finalized_asm.rs @@ -3,8 +3,8 @@ use super::{ fuel::{checks, data_section::DataSection}, ProgramABI, ProgramKind, }; -use crate::asm_generation::fuel::data_section::{DataId, Datum, Entry}; -use crate::asm_lang::allocated_ops::{AllocatedOp, AllocatedOpcode}; +use crate::asm_generation::fuel::data_section::{Datum, Entry, EntryName}; +use crate::asm_lang::allocated_ops::{AllocatedOp, AllocatedOpcode, FuelAsmData}; use crate::decl_engine::DeclRefFunction; use crate::source_map::SourceMap; use crate::BuildConfig; @@ -16,7 +16,6 @@ use sway_error::handler::{ErrorEmitted, Handler}; use sway_types::span::Span; use sway_types::SourceEngine; -use either::Either; use std::{collections::BTreeMap, fmt}; /// Represents an ASM set which has had register allocation, jump elimination, and optimization @@ -112,6 +111,7 @@ fn to_bytecode_mut( { 8 } + AllocatedOpcode::ConfigurablesOffsetPlaceholder => 8, AllocatedOpcode::DataSectionOffsetPlaceholder => 8, AllocatedOpcode::BLOB(count) => count.value as u64 * 4, AllocatedOpcode::CFEI(i) | AllocatedOpcode::CFSI(i) if i.value == 0 => 0, @@ -141,6 +141,29 @@ fn to_bytecode_mut( &ops_padded }; + let mut offset_from_instr_start = 0; + for op in ops.iter() { + match &op.opcode { + AllocatedOpcode::LoadDataId(_reg, data_label) + if !data_section + .has_copy_type(data_label) + .expect("data label references non existent data -- internal error") => + { + // For non-copy type loads, pre-insert pointers into the data_section so that + // from this point on, the data_section remains immutable. This is necessary + // so that when we take addresses of configurables, that address doesn't change + // later on if a non-configurable is added to the data-section. + let offset_bytes = data_section.data_id_to_offset(data_label) as u64; + // The -4 is because $pc is added in the *next* instruction. + let pointer_offset_from_current_instr = + offset_to_data_section_in_bytes - offset_from_instr_start + offset_bytes - 4; + data_section.append_pointer(pointer_offset_from_current_instr); + } + _ => (), + } + offset_from_instr_start += op_size_in_bytes(data_section, op); + } + let mut bytecode = Vec::with_capacity(offset_to_data_section_in_bytes as usize); if build_config.print_bytecode { @@ -166,7 +189,7 @@ fn to_bytecode_mut( offset_from_instr_start += op_size_in_bytes(data_section, op); match fuel_op { - Either::Right(data) => { + FuelAsmData::DatasectionOffset(data) => { if build_config.print_bytecode { print!("{}{:#010x} ", " ".repeat(indentation), bytecode.len()); println!( @@ -182,7 +205,23 @@ fn to_bytecode_mut( bytecode.extend(data.iter().cloned()); half_word_ix += 2; } - Either::Left(instructions) => { + FuelAsmData::ConfigurablesOffset(data) => { + if build_config.print_bytecode { + print!("{}{:#010x} ", " ".repeat(indentation), bytecode.len()); + println!( + " ;; {:?}", + data + ); + } + + // Static assert to ensure that we're only dealing with ConfigurablesOffsetPlaceholder, + // a 1-word (8 bytes) data within the code. No other uses are known. + let _: [u8; 8] = data; + + bytecode.extend(data.iter().cloned()); + half_word_ix += 2; + } + FuelAsmData::Instructions(instructions) => { for instruction in instructions { // Print original source span only once if build_config.print_bytecode_spans { @@ -295,9 +334,9 @@ fn to_bytecode_mut( }; } - for (i, entry) in data_section.value_pairs.iter().enumerate() { - let entry_offset = data_section.data_id_to_offset(&DataId(i as u32)); - print_entry(indentation, offset + entry_offset, entry); + for (i, entry) in data_section.iter_all_entries().enumerate() { + let entry_offset = data_section.absolute_idx_to_offset(i); + print_entry(indentation, offset + entry_offset, &entry); } println!(";; --- END OF TARGET BYTECODE ---\n"); @@ -306,16 +345,19 @@ fn to_bytecode_mut( assert_eq!(half_word_ix * 4, offset_to_data_section_in_bytes as usize); assert_eq!(bytecode.len(), offset_to_data_section_in_bytes as usize); + let num_nonconfigurables = data_section.non_configurables.len(); let named_data_section_entries_offsets = data_section - .value_pairs + .configurables .iter() .enumerate() - .filter(|entry| entry.1.name.is_some()) .map(|(id, entry)| { + let EntryName::Configurable(name) = &entry.name else { + panic!("Non-configurable in configurables part of datasection"); + }; ( - entry.name.as_ref().unwrap().clone(), + name.clone(), offset_to_data_section_in_bytes - + data_section.raw_data_id_to_offset(id as u32) as u64, + + data_section.absolute_idx_to_offset(id + num_nonconfigurables) as u64, ) }) .collect::>(); diff --git a/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs b/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs index 0865687f5c8..a0e53c98cce 100644 --- a/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs +++ b/sway-core/src/asm_generation/fuel/allocated_abstract_instruction_set.rs @@ -1,7 +1,10 @@ -use crate::asm_lang::{ - allocated_ops::{AllocatedOpcode, AllocatedRegister}, - AllocatedAbstractOp, ConstantRegister, ControlFlowOp, Label, RealizedOp, VirtualImmediate12, - VirtualImmediate18, VirtualImmediate24, +use crate::{ + asm_generation::fuel::data_section::EntryName, + asm_lang::{ + allocated_ops::{AllocatedOpcode, AllocatedRegister}, + AllocatedAbstractOp, ConstantRegister, ControlFlowOp, Label, RealizedOp, + VirtualImmediate12, VirtualImmediate18, VirtualImmediate24, + }, }; use super::{ @@ -348,6 +351,13 @@ impl AllocatedAbstractInstructionSet { comment: String::new(), }); } + ControlFlowOp::ConfigurablesOffsetPlaceholder => { + realized_ops.push(RealizedOp { + opcode: AllocatedOpcode::ConfigurablesOffsetPlaceholder, + owning_span: None, + comment: String::new(), + }); + } ControlFlowOp::LoadLabel(r1, ref lab) => { // LoadLabel ops are inserted by `rewrite_far_jumps`. // So the next instruction must be a relative jump. @@ -363,8 +373,11 @@ impl AllocatedAbstractInstructionSet { // We compute the relative offset w.r.t the actual jump. // Sub 1 because the relative jumps add a 1. let offset = rel_offset(curr_offset + 1, lab) - 1; - let data_id = - data_section.insert_data_value(Entry::new_word(offset, None, None)); + let data_id = data_section.insert_data_value(Entry::new_word( + offset, + EntryName::NonConfigurable, + None, + )); realized_ops.push(RealizedOp { opcode: AllocatedOpcode::LoadDataId(r1, data_id), owning_span, @@ -473,6 +486,8 @@ impl AllocatedAbstractInstructionSet { 2 } + Either::Right(ConfigurablesOffsetPlaceholder) => 2, + Either::Right(PushAll(_)) | Either::Right(PopAll(_)) => unreachable!( "fix me, pushall and popall don't really belong in control flow ops \ since they're not about control flow" diff --git a/sway-core/src/asm_generation/fuel/data_section.rs b/sway-core/src/asm_generation/fuel/data_section.rs index 3db12443f4f..e442dcf5ac1 100644 --- a/sway-core/src/asm_generation/fuel/data_section.rs +++ b/sway-core/src/asm_generation/fuel/data_section.rs @@ -1,16 +1,30 @@ +use rustc_hash::FxHashMap; use sway_ir::{size_bytes_round_up_to_word_alignment, Constant, ConstantValue, Context, Padding}; use std::{fmt, iter::repeat}; +#[derive(Clone, Debug, PartialEq, Eq)] +pub enum EntryName { + NonConfigurable, + Configurable(String), +} + +impl fmt::Display for EntryName { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + EntryName::NonConfigurable => write!(f, "NonConfigurable"), + EntryName::Configurable(name) => write!(f, "", name), + } + } +} + // An entry in the data section. It's important for the size to be correct, especially for unions // where the size could be larger than the represented value. #[derive(Clone, Debug)] pub struct Entry { pub value: Datum, pub padding: Padding, - // It is assumed, for now, that only configuration-time constants have a name. Otherwise, this - // is `None`. - pub name: Option, + pub name: EntryName, } #[derive(Clone, Debug)] @@ -23,7 +37,7 @@ pub enum Datum { } impl Entry { - pub(crate) fn new_byte(value: u8, name: Option, padding: Option) -> Entry { + pub(crate) fn new_byte(value: u8, name: EntryName, padding: Option) -> Entry { Entry { value: Datum::Byte(value), padding: padding.unwrap_or(Padding::default_for_u8(value)), @@ -31,7 +45,7 @@ impl Entry { } } - pub(crate) fn new_word(value: u64, name: Option, padding: Option) -> Entry { + pub(crate) fn new_word(value: u64, name: EntryName, padding: Option) -> Entry { Entry { value: Datum::Word(value), padding: padding.unwrap_or(Padding::default_for_u64(value)), @@ -41,7 +55,7 @@ impl Entry { pub(crate) fn new_byte_array( bytes: Vec, - name: Option, + name: EntryName, padding: Option, ) -> Entry { Entry { @@ -51,11 +65,7 @@ impl Entry { } } - pub(crate) fn new_slice( - bytes: Vec, - name: Option, - padding: Option, - ) -> Entry { + pub(crate) fn new_slice(bytes: Vec, name: EntryName, padding: Option) -> Entry { Entry { padding: padding.unwrap_or(Padding::default_for_byte_array(&bytes)), value: Datum::Slice(bytes), @@ -65,7 +75,7 @@ impl Entry { pub(crate) fn new_collection( elements: Vec, - name: Option, + name: EntryName, padding: Option, ) -> Entry { Entry { @@ -80,7 +90,7 @@ impl Entry { pub(crate) fn from_constant( context: &Context, constant: &Constant, - name: Option, + name: EntryName, padding: Option, ) -> Entry { // We need a special handling in case of enums. @@ -89,8 +99,9 @@ impl Entry { .enum_tag_and_value_with_paddings(context) .expect("Constant is an enum."); - let tag_entry = Entry::from_constant(context, tag.0, None, tag.1); - let value_entry = Entry::from_constant(context, value.0, None, value.1); + let tag_entry = Entry::from_constant(context, tag.0, EntryName::NonConfigurable, tag.1); + let value_entry = + Entry::from_constant(context, value.0, EntryName::NonConfigurable, value.1); return Entry::new_collection(vec![tag_entry, value_entry], name, padding); } @@ -118,7 +129,9 @@ impl Entry { .array_elements_with_padding(context) .expect("Constant is an array.") .into_iter() - .map(|(elem, padding)| Entry::from_constant(context, elem, None, padding)) + .map(|(elem, padding)| { + Entry::from_constant(context, elem, EntryName::NonConfigurable, padding) + }) .collect(), name, padding, @@ -128,7 +141,9 @@ impl Entry { .struct_fields_with_padding(context) .expect("Constant is a struct.") .into_iter() - .map(|(elem, padding)| Entry::from_constant(context, elem, None, padding)) + .map(|(elem, padding)| { + Entry::from_constant(context, elem, EntryName::NonConfigurable, padding) + }) .collect(), name, padding, @@ -198,45 +213,92 @@ impl Entry { } } +#[derive(Clone, Debug)] +pub enum DataIdEntryKind { + NonConfigurable, + Configurable, +} + +impl fmt::Display for DataIdEntryKind { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + match self { + DataIdEntryKind::NonConfigurable => write!(f, "NonConfigurable"), + DataIdEntryKind::Configurable => write!(f, "Configurable"), + } + } +} + /// An address which refers to a value in the data section of the asm. #[derive(Clone, Debug)] -pub(crate) struct DataId(pub(crate) u32); +pub(crate) struct DataId { + pub(crate) idx: u32, + pub(crate) kind: DataIdEntryKind, +} impl fmt::Display for DataId { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { - write!(f, "data_{}", self.0) + write!(f, "data_{}_{}", self.kind, self.idx) } } +/// The data to be put in the data section of the asm #[derive(Default, Clone, Debug)] pub struct DataSection { - /// the data to be put in the data section of the asm - pub value_pairs: Vec, + pub non_configurables: Vec, + pub configurables: Vec, + pub(crate) pointer_id: FxHashMap, } impl DataSection { + /// Get the number of entries + pub(crate) fn num_entries(&self) -> usize { + self.non_configurables.len() + self.configurables.len() + } + + /// Iterate over all entries, non-configurables followed by configurables + pub(crate) fn iter_all_entries(&self) -> impl Iterator + '_ { + self.non_configurables + .iter() + .chain(self.configurables.iter()) + .cloned() + } + + /// Get the absolute index of an id + fn absolute_idx(&self, id: &DataId) -> usize { + match id.kind { + DataIdEntryKind::NonConfigurable => id.idx as usize, + DataIdEntryKind::Configurable => id.idx as usize + self.non_configurables.len(), + } + } + + /// Get entry at id + fn get(&self, id: &DataId) -> Option<&Entry> { + match id.kind { + DataIdEntryKind::NonConfigurable => self.non_configurables.get(id.idx as usize), + DataIdEntryKind::Configurable => self.configurables.get(id.idx as usize), + } + } + /// Given a [DataId], calculate the offset _from the beginning of the data section_ to the data /// in bytes. pub(crate) fn data_id_to_offset(&self, id: &DataId) -> usize { - self.raw_data_id_to_offset(id.0) + let idx = self.absolute_idx(id); + self.absolute_idx_to_offset(idx) } - /// Given a [DataId], calculate the offset _from the beginning of the data section_ to the data + /// Given an absolute index, calculate the offset _from the beginning of the data section_ to the data /// in bytes. - pub(crate) fn raw_data_id_to_offset(&self, id: u32) -> usize { - self.value_pairs - .iter() - .take(id as usize) - .fold(0, |offset, entry| { - //entries must be word aligned - size_bytes_round_up_to_word_alignment!(offset + entry.to_bytes().len()) - }) + pub(crate) fn absolute_idx_to_offset(&self, idx: usize) -> usize { + self.iter_all_entries().take(idx).fold(0, |offset, entry| { + //entries must be word aligned + size_bytes_round_up_to_word_alignment!(offset + entry.to_bytes().len()) + }) } pub(crate) fn serialize_to_bytes(&self) -> Vec { // not the exact right capacity but serves as a lower bound - let mut buf = Vec::with_capacity(self.value_pairs.len()); - for entry in &self.value_pairs { + let mut buf = Vec::with_capacity(self.num_entries()); + for entry in self.iter_all_entries() { buf.append(&mut entry.to_bytes()); //entries must be word aligned @@ -248,16 +310,12 @@ impl DataSection { /// Returns whether a specific [DataId] value has a copy type (fits in a register). pub(crate) fn has_copy_type(&self, id: &DataId) -> Option { - self.value_pairs - .get(id.0 as usize) - .map(|entry| entry.has_copy_type()) + self.get(id).map(|entry| entry.has_copy_type()) } /// Returns whether a specific [DataId] value is a byte entry. pub(crate) fn is_byte(&self, id: &DataId) -> Option { - self.value_pairs - .get(id.0 as usize) - .map(|entry| entry.is_byte()) + self.get(id).map(|entry| entry.is_byte()) } /// When generating code, sometimes a hard-coded data pointer is needed to reference @@ -268,31 +326,57 @@ impl DataSection { /// relative to the current (load) instruction. pub(crate) fn append_pointer(&mut self, pointer_value: u64) -> DataId { // The 'pointer' is just a literal 64 bit address. - self.insert_data_value(Entry::new_word(pointer_value, None, None)) + let data_id = self.insert_data_value(Entry::new_word( + pointer_value, + EntryName::NonConfigurable, + None, + )); + self.pointer_id.insert(pointer_value, data_id.clone()); + data_id + } + + /// Get the [DataId] for a pointer, if it exists. + /// The pointer must've been inserted with append_pointer. + pub(crate) fn data_id_of_pointer(&self, pointer_value: u64) -> Option { + self.pointer_id.get(&pointer_value).cloned() } /// Given any data in the form of a [Literal] (using this type mainly because it includes type - /// information and debug spans), insert it into the data section and return its offset as a + /// information and debug spans), insert it into the data section and return its handle as /// [DataId]. pub(crate) fn insert_data_value(&mut self, new_entry: Entry) -> DataId { // if there is an identical data value, use the same id - match self - .value_pairs - .iter() - .position(|entry| entry.equiv(&new_entry)) - { - Some(num) => DataId(num as u32), + + let (value_pairs, kind) = match new_entry.name { + EntryName::NonConfigurable => ( + &mut self.non_configurables, + DataIdEntryKind::NonConfigurable, + ), + EntryName::Configurable(_) => (&mut self.configurables, DataIdEntryKind::Configurable), + }; + match value_pairs.iter().position(|entry| entry.equiv(&new_entry)) { + Some(num) => DataId { + idx: num as u32, + kind, + }, None => { - self.value_pairs.push(new_entry); + value_pairs.push(new_entry); // the index of the data section where the value is stored - DataId((self.value_pairs.len() - 1) as u32) + DataId { + idx: (value_pairs.len() - 1) as u32, + kind, + } } } } // If the stored data is Datum::Word, return the inner value. pub(crate) fn get_data_word(&self, data_id: &DataId) -> Option { - self.value_pairs.get(data_id.0 as usize).and_then(|entry| { + let value_pairs = match data_id.kind { + DataIdEntryKind::NonConfigurable => &self.non_configurables, + DataIdEntryKind::Configurable => &self.configurables, + }; + value_pairs.get(data_id.idx as usize).and_then(|entry| { if let Datum::Word(w) = entry.value { Some(w) } else { @@ -322,11 +406,12 @@ impl fmt::Display for DataSection { use std::fmt::Write; let mut data_buf = String::new(); - for (ix, entry) in self.value_pairs.iter().enumerate() { + for (ix, entry) in self.iter_all_entries().enumerate() { writeln!( data_buf, - "{} {}", - DataId(ix as u32), + "data_{}_{} {}", + entry.name, + ix, display_entry(&entry.value) )?; } diff --git a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs index 0e56e87d33f..5c98c09411e 100644 --- a/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs +++ b/sway-core/src/asm_generation/fuel/fuel_asm_builder.rs @@ -1,4 +1,5 @@ use super::{ + data_section::EntryName, globals_section::GlobalsSection, programs::{AbstractEntry, AbstractProgram}, }; @@ -98,7 +99,12 @@ impl<'ir, 'eng> AsmBuilder for FuelAsmBuilder<'ir, 'eng> { fn compile_configurable(&mut self, config: &ConfigContent) { match config { ConfigContent::V0 { name, constant, .. } => { - let entry = Entry::from_constant(self.context, constant, Some(name.clone()), None); + let entry = Entry::from_constant( + self.context, + constant, + EntryName::Configurable(name.clone()), + None, + ); let dataid = self.data_section.insert_data_value(entry); self.configurable_v0_data_id.insert(name.clone(), dataid); } @@ -117,7 +123,7 @@ impl<'ir, 'eng> AsmBuilder for FuelAsmBuilder<'ir, 'eng> { let (decode_fn_label, _) = self.func_label_map.get(&decode_fn.get()).unwrap(); let dataid = self.data_section.insert_data_value(Entry::new_byte_array( encoded_bytes.clone(), - Some(name.clone()), + EntryName::Configurable(name.clone()), None, )); @@ -2057,6 +2063,11 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { _otherwise => { // Get the constant into the namespace. + let config_name = if let Some(name) = config_name { + EntryName::Configurable(name) + } else { + EntryName::NonConfigurable + }; let entry = Entry::from_constant(self.context, constant, config_name, None); let data_id = self.data_section.insert_data_value(entry); @@ -2177,9 +2188,11 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { } } else { let comment = comment.into(); - let data_id = self - .data_section - .insert_data_value(Entry::new_word(imm, None, None)); + let data_id = self.data_section.insert_data_value(Entry::new_word( + imm, + EntryName::NonConfigurable, + None, + )); self.cur_bytecode.push(Op { opcode: Either::Left(VirtualOp::LoadDataId(reg.clone(), data_id)), owning_span: span.clone(), diff --git a/sway-core/src/asm_generation/fuel/functions.rs b/sway-core/src/asm_generation/fuel/functions.rs index 42577c543d6..f217a4e8396 100644 --- a/sway-core/src/asm_generation/fuel/functions.rs +++ b/sway-core/src/asm_generation/fuel/functions.rs @@ -26,7 +26,7 @@ use sway_error::{ }; use sway_types::{Ident, Span}; -use super::compiler_constants::NUM_ARG_REGISTERS; +use super::{compiler_constants::NUM_ARG_REGISTERS, data_section::EntryName}; /// A summary of the adopted calling convention: /// @@ -830,9 +830,13 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { ); } _ => { - let data_id = self.data_section.insert_data_value( - Entry::from_constant(self.context, constant, None, None), - ); + let data_id = + self.data_section.insert_data_value(Entry::from_constant( + self.context, + constant, + EntryName::NonConfigurable, + None, + )); self.ptr_map.insert(*ptr, Storage::Data(data_id)); } } @@ -858,9 +862,13 @@ impl<'ir, 'eng> FuelAsmBuilder<'ir, 'eng> { }); } _ => { - let data_id = self.data_section.insert_data_value( - Entry::from_constant(self.context, constant, None, None), - ); + let data_id = + self.data_section.insert_data_value(Entry::from_constant( + self.context, + constant, + EntryName::NonConfigurable, + None, + )); init_mut_vars.push(InitMutVars { stack_base_words, diff --git a/sway-core/src/asm_generation/fuel/programs/abstract.rs b/sway-core/src/asm_generation/fuel/programs/abstract.rs index b5a8a12e302..3256da242bb 100644 --- a/sway-core/src/asm_generation/fuel/programs/abstract.rs +++ b/sway-core/src/asm_generation/fuel/programs/abstract.rs @@ -5,7 +5,7 @@ use crate::{ abstract_instruction_set::AbstractInstructionSet, allocated_abstract_instruction_set::AllocatedAbstractInstructionSet, compiler_constants, - data_section::{DataSection, Entry}, + data_section::{DataSection, Entry, EntryName}, globals_section::GlobalsSection, register_sequencer::RegisterSequencer, }, @@ -75,7 +75,7 @@ impl AbstractProgram { pub(crate) fn is_empty(&self) -> bool { self.non_entries.is_empty() && self.entries.is_empty() - && self.data_section.value_pairs.is_empty() + && self.data_section.iter_all_entries().next().is_none() } /// Adds prologue, globals allocation, before entries, contract method switch, and allocates virtual register. @@ -164,14 +164,28 @@ impl AbstractProgram { /// Right now, it looks like this: /// /// WORD OP - /// [1] MOV $scratch $pc - /// [-] JMPF $zero i2 - /// [2] DATA_START (0-32) (in bytes, offset from $is) - /// [-] DATA_START (32-64) - /// [3] LW $ds $scratch 1 - /// [-] ADD $ds $ds $scratch - /// [4] .program_start: + /// 1 MOV $scratch $pc + /// - JMPF $zero i10 + /// 2 DATA_START (0-32) (in bytes, offset from $is) + /// - DATA_START (32-64) + /// 3 CONFIGURABLES_OFFSET (0-32) + /// - CONFIGURABLES_OFFSET (32-64) + /// 4 LW $ds $scratch 1 + /// - ADD $ds $ds $scratch + /// 5 .program_start: fn build_prologue(&mut self) -> AllocatedAbstractInstructionSet { + const _: () = assert!( + crate::PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES == 16, + "Inconsistency in the assumption of prelude organisation" + ); + const _: () = assert!( + crate::PRELUDE_CONFIGURABLES_SIZE_IN_BYTES == 8, + "Inconsistency in the assumption of prelude organisation" + ); + const _: () = assert!( + crate::PRELUDE_SIZE_IN_BYTES == 32, + "Inconsistency in the assumption of prelude organisation" + ); let label = self.reg_seqr.get_label(); AllocatedAbstractInstructionSet { ops: [ @@ -195,12 +209,18 @@ impl AbstractProgram { comment: "data section offset".into(), owning_span: None, }, + // word 3 -- full word u64 placeholder + AllocatedAbstractOp { + opcode: Either::Right(ControlFlowOp::ConfigurablesOffsetPlaceholder), + comment: "configurables offset".into(), + owning_span: None, + }, AllocatedAbstractOp { opcode: Either::Right(ControlFlowOp::Label(label)), - comment: "end of metadata".into(), + comment: "end of configurables offset".into(), owning_span: None, }, - // word 3 -- load the data offset into $ds + // word 4 -- load the data offset into $ds AllocatedAbstractOp { opcode: Either::Left(AllocatedOpcode::LW( AllocatedRegister::Constant(ConstantRegister::DataSectionStart), @@ -210,7 +230,7 @@ impl AbstractProgram { comment: "".into(), owning_span: None, }, - // word 3.5 -- add $ds $ds $is + // word 4.5 -- add $ds $ds $is AllocatedAbstractOp { opcode: Either::Left(AllocatedOpcode::ADD( AllocatedRegister::Constant(ConstantRegister::DataSectionStart), @@ -281,7 +301,7 @@ impl AbstractProgram { // Put the selector in the data section. let data_label = self.data_section.insert_data_value(Entry::new_word( u32::from_be_bytes(selector) as u64, - None, + EntryName::NonConfigurable, None, )); diff --git a/sway-core/src/asm_lang/allocated_ops.rs b/sway-core/src/asm_lang/allocated_ops.rs index b78ba37b2db..31220a0900d 100644 --- a/sway-core/src/asm_lang/allocated_ops.rs +++ b/sway-core/src/asm_lang/allocated_ops.rs @@ -17,7 +17,6 @@ use crate::{ }, fuel_prelude::fuel_asm::{self, op}, }; -use either::Either; use fuel_vm::fuel_asm::{op::ADDI, Imm12}; use std::fmt::{self, Write}; use sway_types::span::Span; @@ -273,6 +272,7 @@ pub(crate) enum AllocatedOpcode { /* Non-VM Instructions */ BLOB(VirtualImmediate24), + ConfigurablesOffsetPlaceholder, DataSectionOffsetPlaceholder, LoadDataId(AllocatedRegister, DataId), AddrDataId(AllocatedRegister, DataId), @@ -397,6 +397,7 @@ impl AllocatedOpcode { /* Non-VM Instructions */ BLOB(_imm) => vec![], + ConfigurablesOffsetPlaceholder => vec![], DataSectionOffsetPlaceholder => vec![], LoadDataId(r1, _i) => vec![r1], AddrDataId(r1, _i) => vec![r1], @@ -525,6 +526,10 @@ impl fmt::Display for AllocatedOpcode { /* Non-VM Instructions */ BLOB(a) => write!(fmtr, "blob {a}"), + ConfigurablesOffsetPlaceholder => write!( + fmtr, + "CONFIGURABLES_OFFSET[0..32]\nCONFIGURABLES_OFFSET[32..64]" + ), DataSectionOffsetPlaceholder => { write!( fmtr, @@ -562,17 +567,21 @@ impl fmt::Display for AllocatedOp { } } -type DoubleWideData = [u8; 8]; +pub(crate) enum FuelAsmData { + ConfigurablesOffset([u8; 8]), + DatasectionOffset([u8; 8]), + Instructions(Vec), +} impl AllocatedOp { pub(crate) fn to_fuel_asm( &self, offset_to_data_section: u64, offset_from_instr_start: u64, - data_section: &mut DataSection, - ) -> Either, DoubleWideData> { + data_section: &DataSection, + ) -> FuelAsmData { use AllocatedOpcode::*; - Either::Left(vec![match &self.opcode { + FuelAsmData::Instructions(vec![match &self.opcode { /* Arithmetic/Logic (ALU) Instructions */ ADD(a, b, c) => op::ADD::new(a.to_reg_id(), b.to_reg_id(), c.to_reg_id()).into(), ADDI(a, b, c) => op::ADDI::new(a.to_reg_id(), b.to_reg_id(), c.value.into()).into(), @@ -641,9 +650,9 @@ impl AllocatedOp { /* Memory Instructions */ ALOC(a) => op::ALOC::new(a.to_reg_id()).into(), - CFEI(a) if a.value == 0 => return Either::Left(vec![]), + CFEI(a) if a.value == 0 => return FuelAsmData::Instructions(vec![]), CFEI(a) => op::CFEI::new(a.value.into()).into(), - CFSI(a) if a.value == 0 => return Either::Left(vec![]), + CFSI(a) if a.value == 0 => return FuelAsmData::Instructions(vec![]), CFSI(a) => op::CFSI::new(a.value.into()).into(), CFE(a) => op::CFE::new(a.to_reg_id()).into(), CFS(a) => op::CFS::new(a.to_reg_id()).into(), @@ -727,17 +736,20 @@ impl AllocatedOp { /* Non-VM Instructions */ BLOB(a) => { - return Either::Left( + return FuelAsmData::Instructions( std::iter::repeat(op::NOOP::new().into()) .take(a.value as usize) .collect(), ) } + ConfigurablesOffsetPlaceholder => { + return FuelAsmData::ConfigurablesOffset([0, 0, 0, 0, 0, 0, 0, 0]) + } DataSectionOffsetPlaceholder => { - return Either::Right(offset_to_data_section.to_be_bytes()) + return FuelAsmData::DatasectionOffset(offset_to_data_section.to_be_bytes()) } LoadDataId(a, b) => { - return Either::Left(realize_load( + return FuelAsmData::Instructions(realize_load( a, b, data_section, @@ -745,7 +757,7 @@ impl AllocatedOp { offset_from_instr_start, )) } - AddrDataId(a, b) => return Either::Left(addr_of(a, b, data_section)), + AddrDataId(a, b) => return FuelAsmData::Instructions(addr_of(a, b, data_section)), Undefined => unreachable!("Sway cannot generate undefined ASM opcodes"), }]) } @@ -755,7 +767,7 @@ impl AllocatedOp { fn addr_of( dest: &AllocatedRegister, data_id: &DataId, - data_section: &mut DataSection, + data_section: &DataSection, ) -> Vec { let offset_bytes = data_section.data_id_to_offset(data_id) as u64; vec![fuel_asm::Instruction::ADDI(ADDI::new( @@ -772,7 +784,7 @@ fn addr_of( fn realize_load( dest: &AllocatedRegister, data_id: &DataId, - data_section: &mut DataSection, + data_section: &DataSection, offset_to_data_section: u64, offset_from_instr_start: u64, ) -> Vec { @@ -815,7 +827,9 @@ fn realize_load( offset_to_data_section - offset_from_instr_start + offset_bytes - 4; // insert the pointer as bytes as a new data section entry at the end of the data - let data_id_for_pointer = data_section.append_pointer(pointer_offset_from_current_instr); + let data_id_for_pointer = data_section + .data_id_of_pointer(pointer_offset_from_current_instr) + .expect("Pointer offset must be in data_section"); // now load the pointer we just created into the `dest`ination let mut buf = Vec::with_capacity(2); diff --git a/sway-core/src/asm_lang/mod.rs b/sway-core/src/asm_lang/mod.rs index 5e1bcaded52..71e09cc2290 100644 --- a/sway-core/src/asm_lang/mod.rs +++ b/sway-core/src/asm_lang/mod.rs @@ -1248,6 +1248,7 @@ impl fmt::Display for VirtualOp { /* Non-VM Instructions */ BLOB(a) => write!(fmtr, "blob {a}"), DataSectionOffsetPlaceholder => write!(fmtr, "data section offset placeholder"), + ConfigurablesOffsetPlaceholder => write!(fmtr, "configurables offset placeholder"), LoadDataId(a, b) => write!(fmtr, "load {a} {b}"), AddrDataId(a, b) => write!(fmtr, "addr {a} {b}"), Undefined => write!(fmtr, "undefined op"), @@ -1277,6 +1278,8 @@ pub(crate) enum ControlFlowOp { Call(Label), // Save a return label address in a register. SaveRetAddr(Reg, Label), + // Placeholder for the offset into the configurables section. + ConfigurablesOffsetPlaceholder, // placeholder for the DataSection offset DataSectionOffsetPlaceholder, // Placeholder for loading an address from the data section. @@ -1304,6 +1307,8 @@ impl fmt::Display for ControlFlowOp { SaveRetAddr(r1, lab) => format!("mova {r1} {lab}"), DataSectionOffsetPlaceholder => "DATA SECTION OFFSET[0..32]\nDATA SECTION OFFSET[32..64]".into(), + ConfigurablesOffsetPlaceholder => + "CONFIGURABLES_OFFSET[0..32]\nCONFIGURABLES_OFFSET[32..64]".into(), LoadLabel(r1, lab) => format!("lwlab {r1} {lab}"), PushAll(lab) => format!("pusha {lab}"), PopAll(lab) => format!("popa {lab}"), @@ -1321,6 +1326,7 @@ impl ControlFlowOp { | Jump(_) | Call(_) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | PushAll(_) | PopAll(_) => vec![], @@ -1339,6 +1345,7 @@ impl ControlFlowOp { | Call(_) | SaveRetAddr(..) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | LoadLabel(..) | PushAll(_) | PopAll(_) => vec![], @@ -1360,6 +1367,7 @@ impl ControlFlowOp { | JumpIfNotZero(..) | Call(_) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | PushAll(_) | PopAll(_) => vec![], }) @@ -1381,6 +1389,7 @@ impl ControlFlowOp { | Jump(_) | Call(_) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | PushAll(_) | PopAll(_) => self.clone(), @@ -1410,6 +1419,7 @@ impl ControlFlowOp { | Call(_) | SaveRetAddr(..) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | LoadLabel(..) | PushAll(_) | PopAll(_) => (), @@ -1466,6 +1476,7 @@ impl ControlFlowOp { Jump(label) => Jump(*label), Call(label) => Call(*label), DataSectionOffsetPlaceholder => DataSectionOffsetPlaceholder, + ConfigurablesOffsetPlaceholder => ConfigurablesOffsetPlaceholder, PushAll(label) => PushAll(*label), PopAll(label) => PopAll(*label), diff --git a/sway-core/src/asm_lang/virtual_ops.rs b/sway-core/src/asm_lang/virtual_ops.rs index ffe3509b7cd..3d041713a4f 100644 --- a/sway-core/src/asm_lang/virtual_ops.rs +++ b/sway-core/src/asm_lang/virtual_ops.rs @@ -226,6 +226,7 @@ pub(crate) enum VirtualOp { /* Non-VM Instructions */ BLOB(VirtualImmediate24), + ConfigurablesOffsetPlaceholder, DataSectionOffsetPlaceholder, // LoadDataId takes a virtual register and a DataId, which points to a labeled piece // of data in the data section. Note that the ASM op corresponding to a LW is @@ -347,6 +348,7 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(_imm) => vec![], DataSectionOffsetPlaceholder => vec![], + ConfigurablesOffsetPlaceholder => vec![], LoadDataId(r1, _i) => vec![r1], AddrDataId(r1, _) => vec![r1], @@ -465,6 +467,7 @@ impl VirtualOp { // Virtual OPs | BLOB(_) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | Undefined => true } } @@ -571,6 +574,7 @@ impl VirtualOp { | GTF(_, _, _) | BLOB(_) | DataSectionOffsetPlaceholder + | ConfigurablesOffsetPlaceholder | LoadDataId(_, _) | AddrDataId(_, _) | Undefined => vec![], @@ -692,6 +696,7 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(_imm) => vec![], DataSectionOffsetPlaceholder => vec![], + ConfigurablesOffsetPlaceholder => vec![], LoadDataId(_r1, _i) => vec![], AddrDataId(_r1, _i) => vec![], @@ -815,6 +820,7 @@ impl VirtualOp { LoadDataId(r1, _i) => vec![r1], AddrDataId(r1, _i) => vec![r1], DataSectionOffsetPlaceholder => vec![], + ConfigurablesOffsetPlaceholder => vec![], Undefined => vec![], }) .into_iter() @@ -1263,6 +1269,7 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(i) => Self::BLOB(i.clone()), DataSectionOffsetPlaceholder => Self::DataSectionOffsetPlaceholder, + ConfigurablesOffsetPlaceholder => Self::ConfigurablesOffsetPlaceholder, LoadDataId(r1, i) => Self::LoadDataId(update_reg(reg_to_reg_map, r1), i.clone()), AddrDataId(r1, i) => Self::AddrDataId(update_reg(reg_to_reg_map, r1), i.clone()), Undefined => Self::Undefined, @@ -1743,6 +1750,7 @@ impl VirtualOp { /* Non-VM Instructions */ BLOB(imm) => AllocatedOpcode::BLOB(imm.clone()), DataSectionOffsetPlaceholder => AllocatedOpcode::DataSectionOffsetPlaceholder, + ConfigurablesOffsetPlaceholder => AllocatedOpcode::ConfigurablesOffsetPlaceholder, LoadDataId(reg1, label) => { AllocatedOpcode::LoadDataId(map_reg(&mapping, reg1), label.clone()) } diff --git a/sway-core/src/lib.rs b/sway-core/src/lib.rs index d66b8e779eb..ac6b7d54d34 100644 --- a/sway-core/src/lib.rs +++ b/sway-core/src/lib.rs @@ -992,6 +992,28 @@ pub fn compile_to_bytecode( asm_to_bytecode(handler, asm_res, source_map, engines.se(), build_config) } +/// Size of the prelude's CONFIGURABLES_OFFSET section, in bytes. +pub const PRELUDE_CONFIGURABLES_SIZE_IN_BYTES: usize = 8; +/// Offset (in bytes) of the CONFIGURABLES_OFFSET section in the prelude. +pub const PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES: usize = 16; +/// Total size of the prelude in bytes. Instructions start right after. +pub const PRELUDE_SIZE_IN_BYTES: usize = 32; + +/// Given bytecode, overwrite the existing offset to configurables offset in the prelude with the given one. +pub fn set_bytecode_configurables_offset( + compiled_bytecode: &mut CompiledBytecode, + md: &[u8; PRELUDE_CONFIGURABLES_SIZE_IN_BYTES], +) { + assert!( + compiled_bytecode.bytecode.len() + >= PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES + PRELUDE_CONFIGURABLES_SIZE_IN_BYTES + ); + let code = &mut compiled_bytecode.bytecode; + for (index, byte) in md.iter().enumerate() { + code[index + PRELUDE_CONFIGURABLES_OFFSET_IN_BYTES] = *byte; + } +} + /// Given the assembly (opcodes), compile to [CompiledBytecode], containing the asm in bytecode form. pub fn asm_to_bytecode( handler: &Handler, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json index 2daeaffdc6a..4447c387c37 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_consts/json_abi_oracle_new_encoding.json @@ -62,82 +62,82 @@ { "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", "name": "BOOL", - "offset": 6896 + "offset": 7056 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "U8", - "offset": 7088 + "offset": 7248 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "ANOTHER_U8", - "offset": 6824 + "offset": 6984 }, { "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", "name": "U16", - "offset": 7032 + "offset": 7192 }, { "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", "name": "U32", - "offset": 7072 + "offset": 7232 }, { "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", "name": "U64", - "offset": 7080 + "offset": 7240 }, { "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", "name": "U256", - "offset": 7040 + "offset": 7200 }, { "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", "name": "B256", - "offset": 6864 + "offset": 7024 }, { "concreteTypeId": "81fc10c4681a3271cf2d66b2ec6fbc8ed007a442652930844fcf11818c295bff", "name": "CONFIGURABLE_STRUCT", - "offset": 6984 + "offset": 7144 }, { "concreteTypeId": "a2922861f03be8a650595dd76455b95383a61b46dd418f02607fa2e00dc39d5c", "name": "CONFIGURABLE_ENUM_A", - "offset": 6904 + "offset": 7064 }, { "concreteTypeId": "a2922861f03be8a650595dd76455b95383a61b46dd418f02607fa2e00dc39d5c", "name": "CONFIGURABLE_ENUM_B", - "offset": 6944 + "offset": 7104 }, { "concreteTypeId": "4926d35d1a5157936b0a29bc126b8aace6d911209a5c130e9b716b0c73643ea6", "name": "ARRAY_BOOL", - "offset": 6832 + "offset": 6992 }, { "concreteTypeId": "776fb5a3824169d6736138565fdc20aad684d9111266a5ff6d5c675280b7e199", "name": "ARRAY_U64", - "offset": 6840 + "offset": 7000 }, { "concreteTypeId": "c998ca9a5f221fe7b5c66ae70c8a9562b86d964408b00d17f883c906bc1fe4be", "name": "TUPLE_BOOL_U64", - "offset": 7016 + "offset": 7176 }, { "concreteTypeId": "94f0fa95c830be5e4f711963e83259fe7e8bc723278ab6ec34449e791a99b53a", "name": "STR_4", - "offset": 7008 + "offset": 7168 }, { "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", "name": "NOT_USED", - "offset": 7000 + "offset": 7160 } ], "encodingVersion": "1", diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap index 283bf9e035f..be59f759d26 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode/stdout.snap @@ -1,5 +1,6 @@ --- source: test/tests/tests.rs +assertion_line: 99 --- > forc build --path test/src/e2e_vm_tests/test_programs/should_pass/language/configurable_dedup_decode --release --ir final exit status: 0 @@ -358,4 +359,4 @@ script { !127 = fn_call_path_span !0 235 236 !128 = (!126 !127) - Finished release [optimized + fuel] target(s) [736 B] in ??? + Finished release [optimized + fuel] target(s) [744 B] in ??? diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json index 5b834c3566e..33f149499d6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/u256/u256_abi/json_abi_oracle_new_encoding.json @@ -9,7 +9,7 @@ { "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", "name": "SOME_U256", - "offset": 808 + "offset": 864 } ], "encodingVersion": "1", diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw index 575ca323135..3150cc69907 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/array_of_structs_caller/src/main.sw @@ -6,7 +6,7 @@ use std::hash::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x14ed3cd06c2947248f69d54bfa681fe40d26267be84df7e19e253622b7921bbe; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xbbda20fb25bdb4b18451501418b06324376c61cb984e75fcbc983fc0a047f85b; // AUTO-CONTRACT-ID ../../test_contracts/array_of_structs_contract --release +const CONTRACT_ID = 0x91c3e72c3b3f4bf7bd5c548d8752c766d5fb8ebf15be3cf92ff34682da9bfb4d; // AUTO-CONTRACT-ID ../../test_contracts/array_of_structs_contract --release fn get_address() -> Option { Some(CONTRACT_ID.into()) diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw index e177370b102..685e3d5444b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/asset_ops_test/src/main.sw @@ -9,12 +9,12 @@ use test_fuel_coin_abi::*; #[cfg(experimental_new_encoding = false)] const FUEL_COIN_CONTRACT_ID = 0xec2277ebe007ade87e3d797c3b1e070dcd542d5ef8f038b471f262ef9cebc87c; #[cfg(experimental_new_encoding = true)] -const FUEL_COIN_CONTRACT_ID = 0xf2fecff29038dab2ef571397ea5507359265c9154608e7de36ccbea20ed5c8aa; +const FUEL_COIN_CONTRACT_ID = 0x19c0d374734bd8a92b776787e9dffa0f105a90e3c977626f93a1916de54dd714; #[cfg(experimental_new_encoding = false)] const BALANCE_CONTRACT_ID = 0xf6cd545152ac83225e8e7df2efb5c6fa6e37bc9b9e977b5ea8103d28668925df; #[cfg(experimental_new_encoding = true)] -const BALANCE_CONTRACT_ID = 0xebe7a84ed5198e9d7d3e002a571058dc24d56f61f2526ca30328f519528f98eb; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release +const BALANCE_CONTRACT_ID = 0xc0ae93ca2a6ec1c740a4869a3f5bfe061184e30e4e5c6185891d3ec2dba9a33d; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release fn main() -> bool { let default_gas = 1_000_000_000_000; diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw index 3afdbe1afc2..448359905b5 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/bal_opcode/src/main.sw @@ -5,7 +5,7 @@ use balance_test_abi::BalanceTest; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xf6cd545152ac83225e8e7df2efb5c6fa6e37bc9b9e977b5ea8103d28668925df; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xebe7a84ed5198e9d7d3e002a571058dc24d56f61f2526ca30328f519528f98eb; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release +const CONTRACT_ID = 0xc0ae93ca2a6ec1c740a4869a3f5bfe061184e30e4e5c6185891d3ec2dba9a33d; // AUTO-CONTRACT-ID ../../test_contracts/balance_test_contract --release fn main() -> bool { let balance_test_contract = abi(BalanceTest, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw index 49d7c83bf80..7778fd9369b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_abi_with_tuples/src/main.sw @@ -6,7 +6,7 @@ use abi_with_tuples::{MyContract, Location, Person}; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xfdc14550c8aee742cd556d0ab7f378b7be0d3b1e6e086c097352e94590d4ed02; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0x95bff8249257356f042d500e9f7db1a964ab5739a1b156eafaca3c7a4efc8aaa; // AUTO-CONTRACT-ID ../../test_contracts/abi_with_tuples_contract --release +const CONTRACT_ID = 0xeb1d43bccc97620c80599c25722b1be3a22affd0570cfdcc57deac7c729e5389; // AUTO-CONTRACT-ID ../../test_contracts/abi_with_tuples_contract --release fn main() -> bool { let the_abi = abi(MyContract, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw index 1f66a607f42..d519240f19d 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_basic_storage/src/main.sw @@ -4,7 +4,7 @@ use basic_storage_abi::{BasicStorage, Quad}; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x94db39f409a31b9f2ebcadeea44378e419208c20de90f5d8e1e33dc1523754cb; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xfa786fd319eeb24fe328ceb0e033779ba444962f5534ec4ec24dc6686d3fdc1d; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release +const CONTRACT_ID = 0x770eb6e1b7de06098474e110cac9ed32c72c455ba7f34bea00ebb47a43986701; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release fn main() -> u64 { let addr = abi(BasicStorage, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw index a8ae0aaa993..61ba86c1b2c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_contract_with_type_aliases/src/main.sw @@ -5,7 +5,7 @@ use contract_with_type_aliases_abi::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x0cbeb6efe3104b460be769bdc4ea101ebf16ccc16f2d7b667ec3e1c7f5ce35b5; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0x741e73148cf8c2f12b620adb9a15275eeabe703a5c058b0e786117e92024fde2; // AUTO-CONTRACT-ID ../../test_contracts/contract_with_type_aliases --release +const CONTRACT_ID = 0xa3ebed6b4c9d17001bf759332daaa22c2e522cb1c61116ac395443f5ab392225; // AUTO-CONTRACT-ID ../../test_contracts/contract_with_type_aliases --release fn main() { let caller = abi(MyContract, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw index f518c022f5b..cdc8f7d508a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_increment_contract/src/main.sw @@ -6,7 +6,7 @@ use dynamic_contract_call::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xd1b4047af7ef111c023ab71069e01dc2abfde487c0a0ce1268e4f447e6c6e4c2; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xc906accda9e1e516ee3122770217d913edca1ae6e3b8bad15c2c1a53ebf5e13e; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release +const CONTRACT_ID = 0x3a0ad1930a751f3849e10d55aedad4b14be604a1807b3016db959a311dbbd101; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release fn main() -> bool { let the_abi = abi(Incrementor, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_storage_enum/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_storage_enum/src/main.sw index c3e736cb17f..c91268acb0f 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_storage_enum/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/call_storage_enum/src/main.sw @@ -5,7 +5,7 @@ use storage_enum_abi::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xc601d11767195485a6654d566c67774134668863d8c797a8c69e8778fb1f89e9; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xaa4e990e0796764624423b63c1bb14fdc02918294fab87682c1ee768de745a7e; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release +const CONTRACT_ID = 0x14df60f48d5874d2623ba7f5604987b29f6288a1ae35a130bfae57e64f74aa89; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release fn main() -> u64 { let caller = abi(StorageEnum, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw index 931e9f010df..ec50cbe43bd 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_auth_test/src/main.sw @@ -5,7 +5,7 @@ use auth_testing_abi::AuthTesting; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xc2eec20491b53aab7232cbd27c31d15417b4e9daf0b89c74cc242ef1295f681f; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0x57892f3d8bd8c58137b35d177a8c03121193d51138ad2218e814af505e90a7f2; // AUTO-CONTRACT-ID ../../test_contracts/auth_testing_contract --release +const CONTRACT_ID = 0xa3ee3b5d5469efa870ba468c36c3775ea5287da385d70fbcd4aadbf5acb5a772; // AUTO-CONTRACT-ID ../../test_contracts/auth_testing_contract --release // should be false in the case of a script fn main() -> bool { diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw index 0f6ed8007b6..65bca7c89cd 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/caller_context_test/src/main.sw @@ -6,7 +6,7 @@ use context_testing_abi::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x6054c11cda000f5990373a4d61929396165be4dfdd61d5b7bd26da60ab0d8577; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0x6c159e40368c6a37b8c479cd63f5462832d5dbdc8d872c4b30edc38e230b7e51; // AUTO-CONTRACT-ID ../../test_contracts/context_testing_contract --release +const CONTRACT_ID = 0x16f15adbe1fbdee5d19349fc245429dad3265f8a0f7a8143ffec39de8c809ff4; // AUTO-CONTRACT-ID ../../test_contracts/context_testing_contract --release fn main() -> bool { let gas: u64 = u64::max(); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw index 8410b0175e8..505fff93133 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/nested_struct_args_caller/src/main.sw @@ -5,7 +5,7 @@ use nested_struct_args_abi::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0xe63d33a1b3a6903808b379f6a41a72fa8a370e8b76626775e7d9d2f9c4c5da40; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xc26e4f54f9bca811be460d07aaedfa12d46477378573947ae95653affba962be; // AUTO-CONTRACT-ID ../../test_contracts/nested_struct_args_contract --release +const CONTRACT_ID = 0xd9e836ce255122c0c243cb0bd6d10450d87206f995d127e60e90bf9ab4fc3532; // AUTO-CONTRACT-ID ../../test_contracts/nested_struct_args_contract --release fn main() -> bool { let caller = abi(NestedStructArgs, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw index d8f0d656e18..33f80e65b6b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/require_contract_deployment/storage_access_caller/src/main.sw @@ -6,7 +6,7 @@ use std::hash::*; #[cfg(experimental_new_encoding = false)] const CONTRACT_ID = 0x3bc28acd66d327b8c1b9624c1fabfc07e9ffa1b5d71c2832c3bfaaf8f4b805e9; #[cfg(experimental_new_encoding = true)] -const CONTRACT_ID = 0xdc525dd2ea57aa691d4d61acd725ebbefd974eaeb397598ca90c38807dc749bb; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release +const CONTRACT_ID = 0x9075162ba3ecabb57aae8ddcd785d8a1211d08281de71c34a1772a888e339ba1; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release fn main() -> bool { let caller = abi(StorageAccess, CONTRACT_ID); diff --git a/test/src/sdk-harness/test_projects/auth/mod.rs b/test/src/sdk-harness/test_projects/auth/mod.rs index 2fefd28f8c8..5c167a1d927 100644 --- a/test/src/sdk-harness/test_projects/auth/mod.rs +++ b/test/src/sdk-harness/test_projects/auth/mod.rs @@ -624,7 +624,7 @@ async fn can_get_predicate_address() { // Setup predicate. let hex_predicate_address: &str = - "0x5dcc82a88eebb07fb628db93d11ec38f085cbf36453a7135fea41b93cc44e118"; + "0x8b300a68337368654e71c65ae93c3d9eb3b9837d0c11d770cbf8740a6a5a8631"; let predicate_address = Address::from_str(hex_predicate_address).expect("failed to create Address from string"); let predicate_bech32_address = Bech32Address::from(predicate_address); @@ -750,7 +750,7 @@ async fn when_incorrect_predicate_address_passed() { async fn can_get_predicate_address_in_message() { // Setup predicate address. let hex_predicate_address: &str = - "0x5dcc82a88eebb07fb628db93d11ec38f085cbf36453a7135fea41b93cc44e118"; + "0x8b300a68337368654e71c65ae93c3d9eb3b9837d0c11d770cbf8740a6a5a8631"; let predicate_address = Address::from_str(hex_predicate_address).expect("failed to create Address from string"); let predicate_bech32_address = Bech32Address::from(predicate_address);