From eda6e204b4a26af564738dd06100832452b158b7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Sun, 25 Aug 2024 15:58:29 +0200 Subject: [PATCH 1/8] Forbid storage key collision between `storage` and `StorageMap` --- sway-core/src/ir_generation/function.rs | 10 +-- sway-core/src/ir_generation/storage.rs | 47 +++++++++---- .../src/language/ty/declaration/storage.rs | 17 +++++ .../ast_node/declaration/declaration.rs | 41 +++++++---- .../ast_node/declaration/storage.rs | 39 ++++------- .../typed_expression/enum_instantiation.rs | 6 +- .../typed_expression/struct_instantiation.rs | 6 +- sway-error/src/warning.rs | 57 +++++++++++++-- sway-lib-std/src/storage/storage_map.sw | 23 ++++-- sway-utils/src/constants.rs | 3 +- .../Forc.lock | 8 +++ .../Forc.toml | 9 +++ .../json_abi_oracle.json | 1 + .../src/main.sw | 5 ++ .../test.toml | 17 +++++ .../duplicated_storage_keys/src/main.sw | 10 ++- .../duplicated_storage_keys/test.toml | 34 ++++++--- .../call_basic_storage/src/main.sw | 2 +- .../call_increment_contract/src/main.sw | 2 +- .../call_storage_enum/src/main.sw | 2 +- .../storage_access_caller/src/main.sw | 2 +- .../json_storage_slots_oracle.json | 54 +++++++------- .../test_contracts/basic_storage/src/main.sw | 4 +- .../test_contracts/basic_storage/test.toml | 2 +- .../json_storage_slots_oracle.json | 2 +- .../json_storage_slots_oracle.json | 70 +++++++++---------- .../json_storage_slots_oracle.json | 58 +++++++-------- .../storage_enum_contract/src/main.sw | 12 ---- .../json_storage_slots_oracle.json | 50 ++++++------- .../storage_namespace/test.toml | 2 +- 30 files changed, 375 insertions(+), 220 deletions(-) create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index 7c333f55185..3b0ad43f805 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -4262,6 +4262,10 @@ impl<'eng> FnCompiler<'eng> { base_type: &Type, span_md_idx: Option, ) -> Result { + // Use the `struct_field_names` to get a field id that is unique even for zero-sized values that live in the same slot. + // We calculate the `unique_field_id` early, here, before the `storage_filed_names` get consumed by `get_storage_key` below. + let unique_field_id = get_storage_field_id(&storage_field_names, &struct_field_names); + // Get the actual storage key as a `Bytes32` as well as the offset, in words, // within the slot. The offset depends on what field of the top level storage // variable is being accessed. @@ -4294,10 +4298,7 @@ impl<'eng> FnCompiler<'eng> { // plus the offset, in number of slots, computed above. The offset within this // particular slot is the remaining offset, in words. ( - add_to_b256( - get_storage_key(storage_field_names.clone(), key.clone()), - offset_in_slots, - ), + add_to_b256(get_storage_key(storage_field_names, key), offset_in_slots), offset_remaining, ) }; @@ -4352,7 +4353,6 @@ impl<'eng> FnCompiler<'eng> { .add_metadatum(context, span_md_idx); // Store the field identifier as the third field in the `StorageKey` struct - let unique_field_id = get_storage_field_id(storage_field_names, struct_field_names); // use the struct_field_names to get a field id that is unique even for zero-sized values that live in the same slot let field_id = convert_literal_to_value(context, &Literal::B256(unique_field_id.into())) .add_metadatum(context, span_md_idx); let gep_2_val = diff --git a/sway-core/src/ir_generation/storage.rs b/sway-core/src/ir_generation/storage.rs index 14fd2b8ef00..b5d42db2828 100644 --- a/sway-core/src/ir_generation/storage.rs +++ b/sway-core/src/ir_generation/storage.rs @@ -20,28 +20,27 @@ enum InByte8Padding { } /// Hands out storage keys using storage field names or an existing key. -/// Basically returns sha256("storage::::.") +/// Basically returns sha256((0u8, "storage::::.")) /// or key if defined. pub(super) fn get_storage_key(storage_field_names: Vec, key: Option) -> Bytes32 { - if let Some(key) = key { - return key.to_be_bytes().into(); + match key { + Some(key) => key.to_be_bytes().into(), + None => hash_storage_key_string(get_storage_key_string(&storage_field_names)), } - - Hasher::hash(get_storage_key_string(storage_field_names)) } -pub fn get_storage_key_string(storage_field_names: Vec) -> String { +pub fn get_storage_key_string(storage_field_names: &[String]) -> String { if storage_field_names.len() == 1 { format!( "{}{}{}", - sway_utils::constants::STORAGE_DOMAIN, + sway_utils::constants::STORAGE_TOP_LEVEL_NAMESPACE, sway_utils::constants::STORAGE_FIELD_SEPARATOR, storage_field_names.last().unwrap(), ) } else { format!( "{}{}{}{}{}", - sway_utils::constants::STORAGE_DOMAIN, + sway_utils::constants::STORAGE_TOP_LEVEL_NAMESPACE, sway_utils::constants::STORAGE_NAMESPACE_SEPARATOR, storage_field_names .iter() @@ -56,10 +55,10 @@ pub fn get_storage_key_string(storage_field_names: Vec) -> String { } /// Hands out unique storage field ids using storage field names and struct field names. -/// Basically returns sha256("storage::::...") +/// Basically returns sha256((0u8, "storage::::...")). pub(super) fn get_storage_field_id( - storage_field_names: Vec, - struct_field_names: Vec, + storage_field_names: &[String], + struct_field_names: &[String], ) -> Bytes32 { let data = format!( "{}{}", @@ -74,7 +73,27 @@ pub(super) fn get_storage_field_id( ) } ); - Hasher::hash(data) + + hash_storage_key_string(data) +} + +fn hash_storage_key_string(storage_key_string: String) -> Bytes32 { + let mut hasher = Hasher::default(); + // Certain storage types, like, e.g., `StorageMap` allow + // storage slots of their contained elements to be defined + // based on developers/users input. E.g., the `key` in a `StorageMap` + // used to calculate the storage slot is a developer/user input. + // + // To ensure that pre-images of such storage slots can never + // be the same as a pre-image of compiler generated key of storage + // field, we prefix the pre-images with a single byte that denotes + // the domain. Storage types like `StorageMap` must have a different + // domain prefix than the `STORAGE_DOMAIN` which is 0u8. + // + // For detailed elaboration see: https://github.com/FuelLabs/sway/issues/6317 + hasher.input(sway_utils::constants::STORAGE_DOMAIN); + hasher.input(storage_key_string); + hasher.finalize() } use uint::construct_uint; @@ -224,8 +243,10 @@ pub fn serialize_to_storage_slots( type_size_in_bytes, ty.as_string(context) ); + + let storage_key = get_storage_key(storage_field_names, key); (0..(type_size_in_bytes + 31) / 32) - .map(|i| add_to_b256(get_storage_key(storage_field_names.clone(), key.clone()), i)) + .map(|i| add_to_b256(storage_key, i)) .zip((0..packed.len() / 4).map(|i| { Bytes32::new( Vec::from_iter((0..4).flat_map(|j| *packed[4 * i + j])) diff --git a/sway-core/src/language/ty/declaration/storage.rs b/sway-core/src/language/ty/declaration/storage.rs index 767d5728ee7..3fbbc5abae7 100644 --- a/sway-core/src/language/ty/declaration/storage.rs +++ b/sway-core/src/language/ty/declaration/storage.rs @@ -8,6 +8,7 @@ use sway_types::{Ident, Named, Span, Spanned}; use crate::{ engine_threading::*, + ir_generation::storage::get_storage_key_string, language::{parsed::StorageDeclaration, ty::*, Visibility}, transform::{self}, type_system::*, @@ -273,6 +274,22 @@ pub struct TyStorageField { pub attributes: transform::AttributesMap, } +impl TyStorageField { + /// Returns the full name of the [TyStorageField], consisting + /// of its name preceded by its full namespace path. + /// E.g., "storage::ns1::ns1.name". + pub fn full_name(&self) -> String { + get_storage_key_string( + &self + .namespace_names + .iter() + .map(|i| i.as_str().to_string()) + .chain(vec![self.name.as_str().to_string()]) + .collect::>(), + ) + } +} + impl EqWithEngines for TyStorageField {} impl PartialEqWithEngines for TyStorageField { fn eq(&self, other: &Self, ctx: &PartialEqWithEnginesContext) -> bool { diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs b/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs index 3f37865215a..0ce499fbccd 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/declaration.rs @@ -518,25 +518,36 @@ impl TyDecl { let initializer = ty::TyExpression::type_check(handler, ctx.by_ref(), &initializer)?; - let mut key_ty_expression = None; - if let Some(key_expression) = key_expression { - let mut key_ctx = ctx.with_type_annotation(engines.te().insert( - engines, - TypeInfo::B256, - None, - )); - - key_ty_expression = Some(ty::TyExpression::type_check( - handler, - key_ctx.by_ref(), - &key_expression, - )?); - } + let key_expression = match key_expression { + Some(key_expression) => { + let key_ctx = ctx + .with_type_annotation(engines.te().insert( + engines, + TypeInfo::B256, + None, + )) + .with_help_text("Storage keys must have type \"b256\"."); + + // TODO: Remove the `handler.scope` once https://github.com/FuelLabs/sway/issues/5606 gets solved. + // We need it here so that we can short-circuit in case of a `TypeMismatch` error which is + // not treated as an error in the `type_check()`'s result. + let typed_expr = handler.scope(|handler| { + ty::TyExpression::type_check( + handler, + key_ctx, + &key_expression, + ) + })?; + + Some(typed_expr) + } + None => None, + }; fields_buf.push(ty::TyStorageField { name, namespace_names: namespace_names.clone(), - key_expression: key_ty_expression, + key_expression, type_argument, initializer, span: field_span, diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs b/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs index 8b0028f7333..678138603be 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs @@ -3,8 +3,7 @@ use std::collections::HashMap; use crate::{ fuel_prelude::fuel_tx::StorageSlot, ir_generation::{ - const_eval::compile_constant_expression_to_constant, - storage::{get_storage_key_string, serialize_to_storage_slots}, + const_eval::compile_constant_expression_to_constant, storage::serialize_to_storage_slots, }, language::ty::{self, TyExpression, TyStorageField}, metadata::MetadataManager, @@ -41,32 +40,24 @@ impl ty::TyStorageDecl { let slots = f.get_initialized_storage_slots(engines, context, md_mgr, module); // Check if slot with same key was already used and throw warning. - if let Ok(slots) = slots.clone() { - for s in slots.into_iter() { + if let Ok(slots) = &slots { + for s in slots.iter() { if let Some(old_field) = slot_fields.insert(*s.key(), f.clone()) { handler.emit_warn(CompileWarning { span: f.span(), warning_content: sway_error::warning::Warning::DuplicatedStorageKey { - key: format!("{:X} ", s.key()), - field1: get_storage_key_string( - old_field - .namespace_names - .iter() - .map(|i| i.as_str().to_string()) - .chain(vec![old_field - .name - .as_str() - .to_string()]) - .collect::>(), - ), - field2: get_storage_key_string( - f.namespace_names - .iter() - .map(|i| i.as_str().to_string()) - .chain(vec![f.name.as_str().to_string()]) - .collect::>(), - ), + first_field: (&old_field.name).into(), + first_field_full_name: old_field.full_name(), + first_field_key_is_compiler_generated: old_field + .key_expression + .is_none(), + second_field: (&f.name).into(), + second_field_full_name: f.full_name(), + second_field_key_is_compiler_generated: f + .key_expression + .is_none(), + key: format!("0x{:x}", s.key()), }, }) } @@ -138,7 +129,7 @@ impl ty::TyStorageField { Ok(Some(key)) } else { Err(CompileError::Internal( - "Expected B256 key", + "Storage keys must have type \"b256\".", key_expression.span.clone(), )) } diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/enum_instantiation.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/enum_instantiation.rs index 35ddcb183ca..2b1cf01ca6f 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/enum_instantiation.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/enum_instantiation.rs @@ -140,9 +140,9 @@ pub(crate) fn instantiate_enum( .with_help_text(help_text) .with_type_annotation(enum_variant_type_id); - // TODO-IG: Remove the `handler.scope` once https://github.com/FuelLabs/sway/issues/5606 gets solved. - // We need it here so that we can short-circuit in case of a `TypeMismatch` error which is - // not treated as an error in the `type_check()`'s result. + // TODO: Remove the `handler.scope` once https://github.com/FuelLabs/sway/issues/5606 gets solved. + // We need it here so that we can short-circuit in case of a `TypeMismatch` error which is + // not treated as an error in the `type_check()`'s result. let typed_expr = handler .scope(|handler| ty::TyExpression::type_check(handler, enum_ctx, single_expr))?; diff --git a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs index a6b331768ec..fd3b90fc078 100644 --- a/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs +++ b/sway-core/src/semantic_analysis/ast_node/expression/typed_expression/struct_instantiation.rs @@ -407,9 +407,9 @@ fn type_check_field_arguments( .with_type_annotation(struct_field.type_argument.type_id) .with_unify_generic(true); - // TODO-IG: Remove the `handler.scope` once https://github.com/FuelLabs/sway/issues/5606 gets solved. - // We need it here so that we can short-circuit in case of a `TypeMismatch` error which is - // not treated as an error in the `type_check()`'s result. + // TODO: Remove the `handler.scope` once https://github.com/FuelLabs/sway/issues/5606 gets solved. + // We need it here so that we can short-circuit in case of a `TypeMismatch` error which is + // not treated as an error in the `type_check()`'s result. let typed_expr = handler .scope(|handler| ty::TyExpression::type_check(handler, ctx, &field.value)); diff --git a/sway-error/src/warning.rs b/sway-error/src/warning.rs index 78a4ac8953b..5ae25ab6a18 100644 --- a/sway-error/src/warning.rs +++ b/sway-error/src/warning.rs @@ -1,4 +1,7 @@ -use crate::diagnostic::{Code, Diagnostic, Hint, Issue, Reason, ToDiagnostic}; +use crate::{ + diagnostic::{Code, Diagnostic, Hint, Issue, Reason, ToDiagnostic}, + formatting::Indent, +}; use core::fmt; @@ -128,9 +131,13 @@ pub enum Warning { message: String, }, DuplicatedStorageKey { + first_field: IdentUnique, + first_field_full_name: String, + first_field_key_is_compiler_generated: bool, + second_field: IdentUnique, + second_field_full_name: String, + second_field_key_is_compiler_generated: bool, key: String, - field1: String, - field2: String, }, } @@ -279,7 +286,8 @@ impl fmt::Display for Warning { You can enable the new behavior with the --experimental-private-modules flag, which will become the default behavior in a later release. More details are available in the related RFC: https://github.com/FuelLabs/sway-rfcs/blob/master/rfcs/0008-private-modules.md"), UsingDeprecated { message } => write!(f, "{}", message), - DuplicatedStorageKey { key, field1, field2 } => write!(f, "Two storage fields are using the same storage key.\nFirst field: {field1}\nSecond field: {field2}\nKey: {key}"), + DuplicatedStorageKey { first_field_full_name, second_field_full_name, key, .. } => + write!(f, "Two storage fields have the same storage key.\nFirst field: {first_field_full_name}\nSecond field: {second_field_full_name}\nKey: {key}"), } } } @@ -412,6 +420,47 @@ impl ToDiagnostic for CompileWarning { "Consider adding assembly instructions or a return register to the ASM block, or removing the block altogether.".to_string(), ], }, + DuplicatedStorageKey { first_field, first_field_full_name, first_field_key_is_compiler_generated, second_field, second_field_full_name, second_field_key_is_compiler_generated, key } => Diagnostic { + reason: Some(Reason::new(code(1), "Two storage fields have the same storage key".to_string())), + issue: Issue::warning( + source_engine, + first_field.span(), + format!("\"{first_field_full_name}\" has the same storage key as \"{second_field_full_name}\"."), + ), + hints: vec![ + Hint::info( + source_engine, + second_field.span(), + format!("\"{second_field_full_name}\" is declared here."), + ), + ], + help: vec![ + if *first_field_key_is_compiler_generated || *second_field_key_is_compiler_generated { + format!("The key of \"{}\" is generated by the compiler using the following formula:", + if *first_field_key_is_compiler_generated { + first_field_full_name + } else { + second_field_full_name + } + ) + } else { + "Both keys are explicitly defined by using the `in` keyword.".to_string() + }, + if *first_field_key_is_compiler_generated || *second_field_key_is_compiler_generated { + format!("{}sha256((0u8, \"{}\"))", + Indent::Single, + if *first_field_key_is_compiler_generated { + first_field_full_name + } else { + second_field_full_name + } + ) + } else { + Diagnostic::help_none() + }, + format!("The common key is: {key}.") + ], + }, _ => Diagnostic { // TODO: Temporary we use self here to achieve backward compatibility. // In general, self must not be used and will not be used once we diff --git a/sway-lib-std/src/storage/storage_map.sw b/sway-lib-std/src/storage/storage_map.sw index 360ed95ade3..20e5d692b8a 100644 --- a/sway-lib-std/src/storage/storage_map.sw +++ b/sway-lib-std/src/storage/storage_map.sw @@ -6,6 +6,21 @@ use ::result::Result; use ::storage::storage_api::*; use ::storage::storage_key::*; +/// The storage domain value of the [StorageMap]. +/// +/// Storage slots of elements contained within a [StorageMap] +/// are calculated based on developers' or users' input (the key). +/// +/// To ensure that pre-images used to calculate storage slots can never +/// be the same as a pre-image of a compiler generated key of a storage +/// field, we prefix the pre-images with a single byte that denotes +/// the storage map domain. +/// +/// The domain prefix for the [StorageMap] is 1u8. +/// +/// For detailed elaboration see: https://github.com/FuelLabs/sway/issues/6317 +const STORAGE_MAP_DOMAIN: u8 = 1; + /// Errors pertaining to the `StorageMap` struct. pub enum StorageMapError { /// Indicates that a value already exists for the key. @@ -51,7 +66,7 @@ where where K: Hash, { - let key = sha256((key, self.field_id())); + let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); write::(key, 0, value); } @@ -85,7 +100,7 @@ where where K: Hash, { - let key = sha256((key, self.field_id())); + let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); StorageKey::::new(key, 0, key) } @@ -124,7 +139,7 @@ where where K: Hash, { - let key = sha256((key, self.field_id())); + let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); clear::(key, 0) } @@ -175,7 +190,7 @@ where where K: Hash, { - let key = sha256((key, self.field_id())); + let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); let val = read::(key, 0); diff --git a/sway-utils/src/constants.rs b/sway-utils/src/constants.rs index 00214945ed5..c0f8b6938a9 100644 --- a/sway-utils/src/constants.rs +++ b/sway-utils/src/constants.rs @@ -7,7 +7,8 @@ pub const USER_FORC_DIRECTORY: &str = ".forc"; pub const SRC_DIR: &str = "src"; pub const DEFAULT_NODE_URL: &str = "http://127.0.0.1:4000"; pub const LANGUAGE_NAME: &str = "Sway"; -pub const STORAGE_DOMAIN: &str = "storage"; +pub const STORAGE_DOMAIN: [u8; 1] = [0u8]; +pub const STORAGE_TOP_LEVEL_NAMESPACE: &str = "storage"; pub const STORAGE_NAMESPACE_SEPARATOR: &str = "::"; pub const STORAGE_FIELD_SEPARATOR: &str = "."; pub const STRUCT_FIELD_SEPARATOR: &str = "."; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.lock new file mode 100644 index 00000000000..6024e958c64 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.lock @@ -0,0 +1,8 @@ +[[package]] +name = "core" +source = "path+from-root-C0C563B172E50A8D" + +[[package]] +name = "storage_invalid_storage_key_type" +source = "member" +dependencies = ["core"] diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.toml new file mode 100644 index 00000000000..18a5527966d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/Forc.toml @@ -0,0 +1,9 @@ +[project] +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" +name = "storage_invalid_storage_key_type" +implicit-std = false + +[dependencies] +core = { path = "../../../../../../sway-lib-core" } diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json new file mode 100644 index 00000000000..0637a088a01 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json @@ -0,0 +1 @@ +[] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw new file mode 100644 index 00000000000..78ab282305b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw @@ -0,0 +1,5 @@ +contract; + +storage { + field in u256::zero(): u64 = 0, +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml new file mode 100644 index 00000000000..1699fb78d80 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml @@ -0,0 +1,17 @@ +category = "fail" + +#check: $()error +#check: $()field in u256::zero(): u64 = 0, +#nextln: $()Mismatched types. +#nextln: $()expected: b256 +#nextln: $()found: u256. +#nextln: $()Function return type does not match up with local type annotation. + +#check: $()error +#check: $()field in u256::zero(): u64 = 0, +#nextln: $()Mismatched types. +#nextln: $()expected: b256 +#nextln: $()found: u256. +#nextln: $()Storage keys must have type "b256". + +#check: $()2 errors. \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw index 54c8ccf3246..6a6c6903558 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw @@ -2,12 +2,18 @@ contract; storage { f1:u64 = 1, - f2 in 0x36389d1013642dcb070193fc48b0316e9dfdfef1860096dc5957e3eb44430b83: u64 = 2, + f2 in 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b: u64 = 2, ns1 { f3 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, }, ns2 { f4 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, - } + }, + ns3 { + f5 in 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069: u64 = 3, + }, + ns4 { + f6: u64 = 4, + }, } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml index 8e5e7a86ef3..9229425d18a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml @@ -1,13 +1,29 @@ category = "compile" -# check: $()Two storage fields are using the same storage key. -# nextln: $()First field: storage.f1 -# nextln: $()Second field: storage.f2 -# nextln: $()Key: 36389D1013642DCB070193FC48B0316E9DFDFEF1860096DC5957E3EB44430B83 +# check: $()Two storage fields have the same storage key +# check: $()f1:u64 = 1, +# nextln: $()"storage.f1" has the same storage key as "storage.f2". +# check: $()f2 in 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b: u64 = 2, +# nextln: $()"storage.f2" is declared here. +# check: $()The key of "storage.f1" is generated by the compiler using the following formula: +# nextln: $()sha256((0u8, "storage.f1")) +# nextln: $()The common key is: 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b. -# check: $()Two storage fields are using the same storage key. -# nextln: $()First field: storage::ns1.f3 -# nextln: $()Second field: storage::ns2.f4 -# nextln: $()Key: 5F4C20CE4BD128E5393A4C2B82007DAC795FA0006D01ACF8DB4C42632BC680CA +# check: $()Two storage fields have the same storage key +# check: $()f3 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, +# nextln: $()"storage::ns1.f3" has the same storage key as "storage::ns2.f4". +# check: $()f4 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, +# nextln: $()"storage::ns2.f4" is declared here. +# check: $()Both keys are explicitly defined by using the `in` keyword. +# nextln: $()The common key is: 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca. -expected_warnings = 6 +# check: $()Two storage fields have the same storage key +# check: $()f5 in 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069: u64 = 3, +# nextln: $()"storage::ns3.f5" has the same storage key as "storage::ns4.f6". +# check: $()f6: u64 = 4, +# nextln: $()"storage::ns4.f6" is declared here. +# check: $()The key of "storage::ns4.f6" is generated by the compiler using the following formula: +# nextln: $()sha256((0u8, "storage::ns4.f6")) +# nextln: $()The common key is: 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069. + +expected_warnings = 9 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 e57fa0fbb2d..5f1f2cf91f7 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 = 0x882ef2f70013d9437c7e727c3e41bb2918441c7804fca647d38245d7309ee5df; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release +const CONTRACT_ID = 0x38c67ce526d7395128b26565949902c74632b8af161a0a03016db58d1879bff9; // 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_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 ec1ae9dd8e0..2801594f440 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 = 0x1ea00e7ace6ea3cc3928a4bd4eb6121da9c13dcc62351ee9c3cc33daf1244797; // AUTO-CONTRACT-ID ../../test_contracts/increment_contract --release +const CONTRACT_ID = 0x7597beb4ff4007b2343d71b886f5cc929b93aff0b2c79c1c7649834105c25c97; // 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 d9e4eac9539..d13ac026c6b 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 = 0xb362dfb21211b3ffad920cb6a200f3aa413066057229b6d64e0867a121ae2a52; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release +const CONTRACT_ID = 0x2e22448da06b50dc0381620be508ebdfbc4ca148b1eae55d2f73a88e96402543; // 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/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 54ba110acca..034ba97090f 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 = 0x5a4e8650faa5f2d17aa9d7edcbe9c561c11e74fe1879bbb7b4c1a6950096fb53; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release +const CONTRACT_ID = 0xe17cf63f31c980ff478cdc097806a0c855bf30566176df6355560e5d9c157566; // AUTO-CONTRACT-ID ../../test_contracts/storage_access_contract --release fn main() -> bool { let caller = abi(StorageAccess, CONTRACT_ID); diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json index b2063f1474b..8c0169567bb 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json @@ -1,58 +1,58 @@ [ { - "key": "26a0f316674277151cdb647fc857710df30dca882c9c61a48e35790d5cb75159", - "value": "6161616161616161000000000000000000000000000000000000000000000000" + "key": "040f131e97eaba9c2d25f5c1d6ea9489ce530940dd87d486f8cd9c7ff5360f6c", + "value": "6161616161000000000000000000000000000000000000000000000000000000" }, { - "key": "2873dd8e90786169217d1dc180cdbeb5642b04daf3979c26776d8b8e93720c12", - "value": "6161616161610000000000000000000000000000000000000000000000000000" + "key": "077f64b0ca598a020551265c0faf95f8e860b45700f27c06af3640a123818b17", + "value": "6161000000000000000000000000000000000000000000000000000000000000" }, { - "key": "323860f3257dc73a83c0b26b915b97575ef2cf8cc150988eb0b0fae2fe61ad77", - "value": "6100000000000000000000000000000000000000000000000000000000000000" + "key": "2b46310c8d886cf7d9e4339837ecc696ecfaf2c431e56e725c552b92b11c3bc8", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "3c025b285aab5e23d355e104b29cb021a7581c1485c4aee6f93c3a37569636ef", - "value": "6161616161000000000000000000000000000000000000000000000000000000" + "key": "30226b031f925fbb2a1ad161ce31b798a684c6f52ed49cf84e244d324eceaf58", + "value": "6161616100000000000000000000000000000000000000000000000000000000" }, { - "key": "533dcc8c8bc47b384931e0bdab958e580a48b65d633991b87ecf6f035a2ec53a", - "value": "0000000000000002000000000000000000000000000000000000000000000000" + "key": "42e97a774f87c61347e7283755a043a5a896d37e801045e8f5ce538b6d1ce8c8", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "67572eb5ab2c5a6c11d8a7217f617a380ad7adbe7e7fed0ffa18be2a11ae78fc", - "value": "6161000000000000000000000000000000000000000000000000000000000000" + "key": "78dabd24c80fc40f05bae92654874f2f77bd13ef803fd55ccf014ff5849cdfd0", + "value": "6161616161610000000000000000000000000000000000000000000000000000" }, { - "key": "6c1f46e5e38cfa9767a552ab89186da5647f603b447e226eb8b0fdbdefb97f0e", - "value": "6161616161616161616100000000000000000000000000000000000000000000" + "key": "848a0a618b9c374a4b1b47c59ef2f0a01f5c42bb5e805ffd669412ce283b992a", + "value": "6161616161616161000000000000000000000000000000000000000000000000" }, { - "key": "933a534d4af4c376b0b569e8d8a2c62e635e26f403e124cb91d9c42e83d54373", - "value": "0100000000000000000000000000000000000000000000000000000000000000" + "key": "84e44dc0900861559343f0fc02dc0d92f7e87872a50e730a85740b701b162863", + "value": "6161616161616100000000000000000000000000000000000000000000000000" }, { - "key": "98ba41aa317c3ee2a207b8deaf0a3386a1705b2548777944f29d8a288999c460", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "933a534d4af4c376b0b569e8d8a2c62e635e26f403e124cb91d9c42e83d54373", + "value": "0100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "a605c78ce1b8f4b67230a55ea491e2b7c5f3d6099cbdcb67e8bf60c9678ae047", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "976540acfef542cb328d6679def3e281cdb1a5bbaca7d9e59a30aa74f3952d90", + "value": "6100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "c4085ef85fb993a44237f78f083c0e96be21522fa8d00bd74b8b8d51b8aa2e8a", - "value": "6161616100000000000000000000000000000000000000000000000000000000" + "key": "9d3f8eb1f2d99b97a2fd6fa68fe7e5a9c5b6734739f8dd84f2ae3da221206a80", + "value": "0000000000000002000000000000000000000000000000000000000000000000" }, { - "key": "d40c4527ee86df5ab69139820872760c294318505804f4327672d6ce7ee2e15f", - "value": "6161616161616100000000000000000000000000000000000000000000000000" + "key": "a42ed3ecc6aaf8d594f165e6c60cdaf172d59436167556f954e6559036736ceb", + "value": "6161610000000000000000000000000000000000000000000000000000000000" }, { - "key": "dc7ac8a34653cb050eb9eeb0792ed909ecaf9df17158e8c2a44820cada45805b", - "value": "6161610000000000000000000000000000000000000000000000000000000000" + "key": "d33763008c92b260fc4381d53aa5976de2b5f991798799fa5edf300bb4a40e02", + "value": "6161616161616161616100000000000000000000000000000000000000000000" }, { - "key": "eafb8114029f277e266bedc3d0b60a5576e8476bc97b96ea42482e20ad15e051", + "key": "f8fde9e56bb5ab545fdfe17edabb876e6f4cd1b3296d92b266d4acb9ca0b5f79", "value": "6161616161616161610000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw index 261bd8cb0e8..d38911b3893 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw @@ -296,8 +296,8 @@ fn test_storage() { assert_eq(storage::ns1::ns2.c1.read(), NS1_NS2_C1); assert_eq(storage.c1.slot(), C1KEY); - assert_eq(storage.const_b256.slot(), sha256("storage.const_b256")); - assert_eq(storage::ns1::ns2.c1.slot(), sha256("storage::ns1::ns2.c1")); + assert_eq(storage.const_b256.slot(), sha256((0u8,"storage.const_b256"))); + assert_eq(storage::ns1::ns2.c1.slot(), sha256((0u8,"storage::ns1::ns2.c1"))); } // If these comparisons are done inline just above then it blows out the register allocator due to diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.toml index 8bce24f6a24..c1349fc15dc 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.toml @@ -1,4 +1,4 @@ category = "compile" validate_abi = true validate_storage_slots = true -expected_warnings = 3 +expected_warnings = 2 # TODO-DCA: Set to zero once https://github.com/FuelLabs/sway/issues/5921 is fixed. diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json index 27d01be9eb2..efa6132760a 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json @@ -1,6 +1,6 @@ [ { - "key": "1f5327d8b018fe8a341aec49e087546980b521535a650107a53efdc5e7038723", + "key": "d810923c0d6cc6ed49622594d7368eb1e124753474e3ebd52a66c6c2ecb42642", "value": "0000000000000000000000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json index 24a5f2c6daf..ff1eae7956b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json @@ -1,74 +1,74 @@ [ { - "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87cb", - "value": "0000000000000001000000000000000200000000000000000000000000000000" + "key": "419b1120ea993203d7e223dfbe76184322453d6f8de946e827a8669102ab395b", + "value": "0000000000000040000000000000000000000000000000000000000000000000" }, { - "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87cc", - "value": "0000000000000000000000000000000300000000000000040000000000000005" + "key": "4b06f7ce27bc88217a7c9d4300619d2900cef25ecb29a790ec869b02e4191275", + "value": "4141414141414141414141414141414141414141414141414141414141414141" }, { - "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87cd", - "value": "0000000000000000000000000000000000000000000000000000000000000006" + "key": "4b06f7ce27bc88217a7c9d4300619d2900cef25ecb29a790ec869b02e4191276", + "value": "4141414141414141000000000000000000000000000000000000000000000000" }, { - "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87ce", - "value": "0100000000000000070000000000000000000000000000080000000000000009" + "key": "7299da45c4430837636de04fb23f3343a80d88c1dc0455562b3066913f0d7745", + "value": "0000000000000020000000000000000000000000000000000000000000000000" }, { - "key": "5dc4bb371cab39153d3503dc677662a2c02b616d1789ffc8c7f11cd6838a5b8d", - "value": "0000000000000020000000000000000000000000000000000000000000000000" + "key": "865b6b6b53f4babe503029163d7076d649da88a10c4ed333d19c645d271f495c", + "value": "0000000000000010000000000000000000000000000000000000000000000000" }, { - "key": "9a1c37d22e51c475d6284f621e29ad5753c418595c5d7b24a7d1684f11f31adf", - "value": "0100000000000000000000000000000000000000000000000000000000000000" + "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0c", + "value": "0000000000000001000000000000000100000000000000020000000000000000" }, { - "key": "a87982353688625e3011294e19aa0a5c027b02e2045c8df73c59cf2142416a37", - "value": "0000000000000010000000000000000000000000000000000000000000000000" + "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0d", + "value": "0000000000000000000000000000000000000000000000030100000000000000" }, { - "key": "aa834639bd045ecb5b8644fda6256196e090c28df31665d3ab8516fb89fb39cd", - "value": "0000000000000000000000000000000000000000000000000000000000000000" + "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0e", + "value": "0400000000000000000000000000000500000000000000060000000000000000" }, { - "key": "aa834639bd045ecb5b8644fda6256196e090c28df31665d3ab8516fb89fb39ce", + "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f2", "value": "0000000000000000000000000000000000000000000000000000000000000000" }, { - "key": "aa834639bd045ecb5b8644fda6256196e090c28df31665d3ab8516fb89fb39cf", - "value": "0000000000000000000000000000000000000000000003090000000000000000" + "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f3", + "value": "0000000000000000000000000000000000000000000000000000000000000000" }, { - "key": "ae4a9d6171099362a9d5a398016d7bf8555a8ba706d68ef7c879d4a439c8a6d5", - "value": "4141414141414141414141414141414141414141414141414141414141414141" + "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f4", + "value": "0000000000000000000000000000000000000000000003090000000000000000" }, { - "key": "ae4a9d6171099362a9d5a398016d7bf8555a8ba706d68ef7c879d4a439c8a6d6", - "value": "4141414141414141000000000000000000000000000000000000000000000000" + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c86", + "value": "0000000000000001000000000000000200000000000000000000000000000000" }, { - "key": "b9ffa363d401358f328bb44e635cded3208652b383e46c121afb23d599356f41", - "value": "0800000000000000000000000000000000000000000000000000000000000000" + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c87", + "value": "0000000000000000000000000000000300000000000000040000000000000005" }, { - "key": "c979570128d5f52725e9a343a7f4992d8ed386d7c8cfd25f1c646c51c2ac6b4b", - "value": "0000000000000040000000000000000000000000000000000000000000000000" + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c88", + "value": "0000000000000000000000000000000000000000000000000000000000000006" }, { - "key": "d95f4c8d717d52323d34c1118b3f0598a5ec3cabae386887507cabd6dd546a43", - "value": "0101010101010101010101010101010101010101010101010101010101010101" + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c89", + "value": "0100000000000000070000000000000000000000000000080000000000000009" }, { - "key": "e153542f820f1e716d34120d0ea017c2fab2e2545c0556584bc7462f2dafb3bd", - "value": "0000000000000001000000000000000100000000000000020000000000000000" + "key": "d871d81721e9905a5cafe5b82dfde0ddb930f96a8e6deb44f92a8c9ce4d24ac1", + "value": "0800000000000000000000000000000000000000000000000000000000000000" }, { - "key": "e153542f820f1e716d34120d0ea017c2fab2e2545c0556584bc7462f2dafb3be", - "value": "0000000000000000000000000000000000000000000000030100000000000000" + "key": "e8aaf9a6b72b4eee2bcb2315773bc50e9166ff05c4221843637e25f0424a5dd5", + "value": "0100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "e153542f820f1e716d34120d0ea017c2fab2e2545c0556584bc7462f2dafb3bf", - "value": "0400000000000000000000000000000500000000000000060000000000000000" + "key": "eb390d9f85c8c849ff8aeb05c865ca66b37ba69a7bec8489b1c467f029b650af", + "value": "0101010101010101010101010101010101010101010101010101010101010101" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json index 569da2a8bea..f2d1ca396cb 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json @@ -1,62 +1,62 @@ [ { - "key": "07692c5e306e34754c8507b83507787cd816e26e21a73f984267468c6a858c5f", - "value": "00000000000000000000000000000000000000000000000000000000000000ee" + "key": "12f9e955b5b2b5a00c0ebd1320f2cbd0e66c39396b3b3d7ff95c87f4b6e48c0d", + "value": "000000000000000000000000000000cd00000000000000000000000000000000" }, { - "key": "093917a687c53cb2abc027cec98a5bbf66c8ae7f5cd58a0880fc9c79617ce148", + "key": "23e09d7a09a27d7d9c5c9d0f5191084c19a0a668c60b804a94e99234e6069c7b", "value": "0000000000000001000000000000aa00000000000000bb00000000000000cc00" }, { - "key": "1381e00cddf07f6fb1d14cdcb956f38a498a20369226d4528826287fd98e6d33", - "value": "0000000000000000000000000000000100000000000000000000000000000000" + "key": "2e7251f5b28dbe052a7f5113d45f3cc2faccf7c955cbc0966089aa0d0059beab", + "value": "0000000000000001000000000000ab00000000000000bc00000000000000cd00" }, { - "key": "163670615ae62a8f957b50ab4ce2c32b22427e70577a54b971439c44f1c4f6ac", - "value": "0000000000000001000000000000bb0000000000000000000000000000000000" + "key": "2e7251f5b28dbe052a7f5113d45f3cc2faccf7c955cbc0966089aa0d0059beac", + "value": "000000000000de00000000000000ef0000000000000000000000000000000000" }, { - "key": "306d92806670cbeca4a1dcd450149e8aac249b1446ab7a4360b511de83dc031c", - "value": "0000000000000001000000000000ab00000000000000bc00000000000000cd00" + "key": "2f02e964cd75fddf505a740d9daa11fef5f09b4d17058f893fc0f4e8b2244f53", + "value": "0000000000000000000000000000000100000000000000000000000000000000" }, { - "key": "306d92806670cbeca4a1dcd450149e8aac249b1446ab7a4360b511de83dc031d", - "value": "000000000000de00000000000000ef0000000000000000000000000000000000" + "key": "50010301032c3383ef066fbb9ac7c25e3de42bdd5ccaec2d6e0bd26b6531bb0f", + "value": "0000000000000000000000000000000100000000000000000000000000000000" }, { - "key": "919b268af8b1d0e73ebd666050f0d8ca91c4a57c1f07de173500c1204f12b4b5", - "value": "0000000000000002000000000000000000000000000000000000000000000000" + "key": "6b765908aa8ec7bc3a1d73cd252e40fb055de29fb0e9486a16e388cba9fa7c9f", + "value": "00000000000000000000000000000000000000000000000000000000000000ee" }, { - "key": "b1852fd03d24006ecb20b244b4a807a5cc1901e1615b4c2cf38ad968da5778a3", - "value": "0000000000000002000000000000000000000000000000000000000000000000" + "key": "728df923e281e7cb9793c2c2d6419b735161b5e1b8d5ca2065569611418fc194", + "value": "000000000000000100000000000000cd00000000000000000000000000000000" }, { - "key": "b791faa009af5f959cb5b1e527897b5445b819ad012dbcdb4e6747fc67a74abf", - "value": "000000000000000000000000000000ab00000000000000000000000000000000" + "key": "7ddacb90e6ff09ed9aa4fde095854476123392aab8c73165cc65097b0a2a2578", + "value": "0000000000000000000000000000000000000000000000000000000000000000" }, { - "key": "ca79befa366adbeb06bd973bbb1c4edf732df97bfec0caf094cf9f83fee6dead", - "value": "0000000000000000000000000000000100000000000000000000000000000000" + "key": "7ddacb90e6ff09ed9aa4fde095854476123392aab8c73165cc65097b0a2a2579", + "value": "000000000000000000000000000000ff00000000000000000000000000000000" }, { - "key": "d44c3a30232bc40cbe5f573493a6951cd072404880b4dde75e10903d0b0a5256", - "value": "000000000000000000000000000000aa00000000000000000000000000000000" + "key": "c20357da738934c36211a22c69d4c44bc7a3b500b07d9e7328c3f0a7c2c426c0", + "value": "0000000000000002000000000000000000000000000000000000000000000000" }, { - "key": "e487c22c16cab65d2a63a26de30fd41df1586b5abbad6746cacdf958aa539d49", - "value": "000000000000000000000000000000cd00000000000000000000000000000000" + "key": "d60810fb854958d678015228bfbd5a23a3e1763c1ff90f6790f69fbb85b413c6", + "value": "000000000000000000000000000000ab00000000000000000000000000000000" }, { - "key": "fb07f807a63ddfd1422b1cba4ed39940c50eade2002542e1faccea5c64d5b087", - "value": "000000000000000100000000000000cd00000000000000000000000000000000" + "key": "d71ff2e9ac87ec91301ee89d18b1dc8991b79753f004ce0810661bd5bfa92bd2", + "value": "0000000000000001000000000000bb0000000000000000000000000000000000" }, { - "key": "fdfd23cb7462d11986f91b4f130b7ddb400b7bbc388ad6754175d93c2b00bd25", - "value": "0000000000000000000000000000000000000000000000000000000000000000" + "key": "d9149ae8e217ec10a045c9f83c5bc9d227285fe76b9bcdc8245e6a57a23d0229", + "value": "000000000000000000000000000000aa00000000000000000000000000000000" }, { - "key": "fdfd23cb7462d11986f91b4f130b7ddb400b7bbc388ad6754175d93c2b00bd26", - "value": "000000000000000000000000000000ff00000000000000000000000000000000" + "key": "e7af73ebbf0ab36c9e30283a504e1326febe010a1b2d0deae9252af8302526a1", + "value": "0000000000000002000000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/src/main.sw index e604563d4e2..597bed643ce 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/src/main.sw @@ -117,10 +117,6 @@ fn check_s_u8_a(expected: u8) -> u8 { assert(i == expected); return i; }, - _ => { - assert(false); - return 99; - } } } @@ -132,10 +128,6 @@ fn check_s_u64_a(expected: u64) -> u64 { assert(i == expected); return i; }, - _ => { - assert(false); - return 9999; - } } } @@ -147,10 +139,6 @@ fn check_s_bool_a(expected: bool) -> u64 { assert(i == expected); return 171; }, - _ => { - assert(false); - return 9999; - } } } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json index 0b71f7ba584..30e9e240f7c 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json @@ -1,54 +1,54 @@ [ { - "key": "156750d12322b9d55699e5f250927c45dbc5a716ed514e5d5c6e001c72743958", - "value": "6161616161616161610000000000000000000000000000000000000000000000" + "key": "130875c838ab7f4f039a63d56d8173198d6edade9a61967c93b9d32d93547979", + "value": "6161000000000000000000000000000000000000000000000000000000000000" }, { - "key": "1900d3c5816770f72962fcc1c2903deaef383aad2245f8dce3ea438edb50d5be", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "1997c0b14a3944421bc909d65cdb7f96023661790725e7a06d0bdf211002f9c0", + "value": "6161610000000000000000000000000000000000000000000000000000000000" }, { - "key": "316435c84dec635a59eafe5c7bbe948529d9b334642e3042790ccc24a48d020f", - "value": "6161610000000000000000000000000000000000000000000000000000000000" + "key": "1cb08489095e2318cabf34c2c00b0f2b78c151bf4e3caf2a1762778c1b79c052", + "value": "0000000000000001000000000000000000000000000000000000000000000000" }, { - "key": "75c8aa025fcadccc0595011724f38d1c4502877ab67e96c2d5ac4e28c7c067d2", - "value": "6161616161000000000000000000000000000000000000000000000000000000" + "key": "35338f6734c20524ba70780eae61e4dc5398122eab4a3cad9509a3d3ddc1551b", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "8d03529726cb560c58c7c256daa265105ab1657cc58f285a4e450ade5e3b99b9", + "key": "55279c57558d3bb1938f803552769ed7dcb3efacd74d9a16cf71d0cfbaab6c0a", "value": "6161616161616161616100000000000000000000000000000000000000000000" }, { - "key": "8e2eedb0198112b5758b3ca68ff81ccf74f35bde89f59324c6349834b7446d42", - "value": "6161616161610000000000000000000000000000000000000000000000000000" + "key": "5d5895256cdf173ecc135c1a18de5133b00b36e5caae538407a883dd44cc0dac", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "96f53fe759d3f6112e66216565e101a4e3ad50e0b67047a2b1bc71f58e838b3b", - "value": "6161000000000000000000000000000000000000000000000000000000000000" + "key": "5dbeb0e7fc4c2fa3b01b9873d2a4e23488fb486046b6074b4ae463b7bbacbe89", + "value": "6161616161000000000000000000000000000000000000000000000000000000" }, { - "key": "9cd3727531d07180cf222a86ab51e4d6933e82ffa5a846a51ee7554929eec408", - "value": "0000000000000001000000000000000000000000000000000000000000000000" + "key": "659790a8d5d87a599ab69d1a3e6f48ff00c850fb7d24ccd782b209a52e4be83c", + "value": "6161616161616100000000000000000000000000000000000000000000000000" }, { - "key": "b48939b669452acd21e7e052008441cf16898ebecad0cf50ea5d1022cc91683d", - "value": "6161616161616100000000000000000000000000000000000000000000000000" + "key": "7aac1eb5fdc9d977b39721c2ccddb3ae405eecac0d8570e3be2d70fe677db4bd", + "value": "6161616161616161610000000000000000000000000000000000000000000000" }, { - "key": "c2cec376bf7389162e8706fbb83f4c7d322150bbae540c4d7a89711e86a54d0b", - "value": "6161616100000000000000000000000000000000000000000000000000000000" + "key": "8449d22802f944884dd98b791627c4265f4303014d1975f3da48fde003d77936", + "value": "6161616161616161000000000000000000000000000000000000000000000000" }, { - "key": "c47aaa0a4460ad82387b70843b35804e6526ec4a4094793064abda38e789d70b", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "c2f546e9b4a2a37895f7f563be4610aa580468ddd8ba5d3544513965d79eac8a", + "value": "6100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "dbaf1317f4011ad87979853011781f2088cdd8422250f19f27a90b5ce8037cac", - "value": "6161616161616161000000000000000000000000000000000000000000000000" + "key": "e1ba0adcc27d3a21cfe72cc296e282f1c4b9f6798f89ac4e4b8ac95e3ee16d81", + "value": "6161616161610000000000000000000000000000000000000000000000000000" }, { - "key": "f665e43dbe17620f6ef1e4beb22f9d4f1e2bb711e20c003a09dad812801f59e0", - "value": "6100000000000000000000000000000000000000000000000000000000000000" + "key": "fdcf008347ae968111d6837c46f05f1a9943e76f6998d51ee1220b4069709a51", + "value": "6161616100000000000000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.toml index 94671fb72d4..a235275de20 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.toml @@ -1,4 +1,4 @@ category = "compile" validate_abi = true validate_storage_slots = true -expected_warnings = 1 +expected_warnings = 1 # TODO-DCA: Set to zero once https://github.com/FuelLabs/sway/issues/5921 is fixed. From 1fa03827311a3b860a858a0289b43e36eae9520c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 16:49:37 +0100 Subject: [PATCH 2/8] Implement `storage_domains` experimental feature --- sway-core/src/ir_generation/function.rs | 4 +- sway-core/src/ir_generation/storage.rs | 33 +- .../ast_node/declaration/storage.rs | 1 + sway-error/src/warning.rs | 31 +- sway-features/src/lib.rs | 3 + sway-lib-std/src/storage/storage_map.sw | 19 +- test/src/e2e_vm_tests/harness.rs | 44 +- test/src/e2e_vm_tests/mod.rs | 10 +- .../json_abi_oracle.json | 1 - .../src/main.sw | 6 +- .../test.toml | 4 +- .../duplicated_storage_keys/src/main.sw | 6 + .../test.storage_domains.toml | 30 + .../duplicated_storage_keys/test.toml | 12 +- .../call_basic_storage/src/main.sw | 2 +- .../call_storage_enum/src/main.sw | 2 +- .../storage_slot_key_calculation/Forc.lock | 13 + .../storage_slot_key_calculation/Forc.toml | 8 + .../storage_slot_key_calculation/src/main.sw | 53 ++ .../test.storage_domains.toml | 1 + .../storage_slot_key_calculation/test.toml | 2 + .../json_abi_oracle.storage_domains.json | 297 +++++++ .../json_storage_slots_oracle.json | 54 +- ..._storage_slots_oracle.storage_domains.json | 58 ++ .../test_contracts/basic_storage/src/main.sw | 2 - .../basic_storage/test.storage_domains.toml | 1 + .../json_abi_oracle.storage_domains.json | 102 +++ .../json_storage_slots_oracle.json | 2 +- ..._storage_slots_oracle.storage_domains.json | 6 + .../test.storage_domains.toml | 1 + .../json_abi_oracle.storage_domains.json | 769 ++++++++++++++++++ .../json_storage_slots_oracle.json | 70 +- ..._storage_slots_oracle.storage_domains.json | 74 ++ .../test.storage_domains.toml | 1 + .../json_abi_oracle.storage_domains.json | 31 + .../json_storage_slots_oracle.json | 58 +- ..._storage_slots_oracle.storage_domains.json | 62 ++ .../test.storage_domains.toml | 1 + .../json_abi_oracle.storage_domains.json | 289 +++++++ .../json_storage_slots_oracle.json | 50 +- ..._storage_slots_oracle.storage_domains.json | 54 ++ .../test.storage_domains.toml | 1 + test/src/ir_generation/mod.rs | 4 +- 43 files changed, 2092 insertions(+), 180 deletions(-) delete mode 100644 test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.storage_domains.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.lock create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/src/main.sw create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.storage_domains.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.storage_domains.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_abi_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/test.storage_domains.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/test.storage_domains.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_abi_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/test.storage_domains.toml create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.storage_domains.json create mode 100644 test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.storage_domains.toml diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index 3b0ad43f805..9e17e9d039e 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -4264,7 +4264,7 @@ impl<'eng> FnCompiler<'eng> { ) -> Result { // Use the `struct_field_names` to get a field id that is unique even for zero-sized values that live in the same slot. // We calculate the `unique_field_id` early, here, before the `storage_filed_names` get consumed by `get_storage_key` below. - let unique_field_id = get_storage_field_id(&storage_field_names, &struct_field_names); + let unique_field_id = get_storage_field_id(&storage_field_names, &struct_field_names, context.experimental); // Get the actual storage key as a `Bytes32` as well as the offset, in words, // within the slot. The offset depends on what field of the top level storage @@ -4298,7 +4298,7 @@ impl<'eng> FnCompiler<'eng> { // plus the offset, in number of slots, computed above. The offset within this // particular slot is the remaining offset, in words. ( - add_to_b256(get_storage_key(storage_field_names, key), offset_in_slots), + add_to_b256(get_storage_key(storage_field_names, key, context.experimental), offset_in_slots), offset_remaining, ) }; diff --git a/sway-core/src/ir_generation/storage.rs b/sway-core/src/ir_generation/storage.rs index b5d42db2828..a069bfd406c 100644 --- a/sway-core/src/ir_generation/storage.rs +++ b/sway-core/src/ir_generation/storage.rs @@ -3,6 +3,7 @@ use crate::fuel_prelude::{ fuel_tx::StorageSlot, fuel_types::{Bytes32, Bytes8}, }; +use sway_features::ExperimentalFeatures; use sway_ir::{ constant::{Constant, ConstantValue}, context::Context, @@ -22,10 +23,10 @@ enum InByte8Padding { /// Hands out storage keys using storage field names or an existing key. /// Basically returns sha256((0u8, "storage::::.")) /// or key if defined. -pub(super) fn get_storage_key(storage_field_names: Vec, key: Option) -> Bytes32 { +pub(super) fn get_storage_key(storage_field_names: Vec, key: Option, experimental: ExperimentalFeatures) -> Bytes32 { match key { Some(key) => key.to_be_bytes().into(), - None => hash_storage_key_string(get_storage_key_string(&storage_field_names)), + None => hash_storage_key_string(get_storage_key_string(&storage_field_names), experimental), } } @@ -59,6 +60,7 @@ pub fn get_storage_key_string(storage_field_names: &[String]) -> String { pub(super) fn get_storage_field_id( storage_field_names: &[String], struct_field_names: &[String], + experimental: ExperimentalFeatures, ) -> Bytes32 { let data = format!( "{}{}", @@ -74,15 +76,15 @@ pub(super) fn get_storage_field_id( } ); - hash_storage_key_string(data) + hash_storage_key_string(data, experimental) } -fn hash_storage_key_string(storage_key_string: String) -> Bytes32 { +fn hash_storage_key_string(storage_key_string: String, experimental: ExperimentalFeatures) -> Bytes32 { let mut hasher = Hasher::default(); // Certain storage types, like, e.g., `StorageMap` allow // storage slots of their contained elements to be defined - // based on developers/users input. E.g., the `key` in a `StorageMap` - // used to calculate the storage slot is a developer/user input. + // based on developer's input. E.g., the `key` in a `StorageMap` + // used to calculate the storage slot is a developer input. // // To ensure that pre-images of such storage slots can never // be the same as a pre-image of compiler generated key of storage @@ -91,7 +93,9 @@ fn hash_storage_key_string(storage_key_string: String) -> Bytes32 { // domain prefix than the `STORAGE_DOMAIN` which is 0u8. // // For detailed elaboration see: https://github.com/FuelLabs/sway/issues/6317 - hasher.input(sway_utils::constants::STORAGE_DOMAIN); + if experimental.storage_domains { + hasher.input(sway_utils::constants::STORAGE_DOMAIN); + } hasher.input(storage_key_string); hasher.finalize() } @@ -128,17 +132,18 @@ pub fn serialize_to_storage_slots( key: Option, ty: &Type, ) -> Vec { + let experimental = context.experimental; match &constant.value { ConstantValue::Undef => vec![], // If not being a part of an aggregate, single byte values like `bool`, `u8`, and unit // are stored as a byte at the beginning of the storage slot. ConstantValue::Unit if ty.is_unit(context) => vec![StorageSlot::new( - get_storage_key(storage_field_names, key), + get_storage_key(storage_field_names, key, experimental), Bytes32::new([0; 32]), )], ConstantValue::Bool(b) if ty.is_bool(context) => { vec![StorageSlot::new( - get_storage_key(storage_field_names, key), + get_storage_key(storage_field_names, key, experimental), Bytes32::new([ if *b { 1 } else { 0 }, 0, @@ -177,7 +182,7 @@ pub fn serialize_to_storage_slots( } ConstantValue::Uint(b) if ty.is_uint8(context) => { vec![StorageSlot::new( - get_storage_key(storage_field_names, key), + get_storage_key(storage_field_names, key, experimental), Bytes32::new([ *b as u8, 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, @@ -187,7 +192,7 @@ pub fn serialize_to_storage_slots( // Similarly, other uint values are stored at the beginning of the storage slot. ConstantValue::Uint(n) if ty.is_uint(context) => { vec![StorageSlot::new( - get_storage_key(storage_field_names, key), + get_storage_key(storage_field_names, key, experimental), Bytes32::new( n.to_be_bytes() .iter() @@ -201,13 +206,13 @@ pub fn serialize_to_storage_slots( } ConstantValue::U256(b) if ty.is_uint_of(context, 256) => { vec![StorageSlot::new( - get_storage_key(storage_field_names, key), + get_storage_key(storage_field_names, key, experimental), Bytes32::new(b.to_be_bytes()), )] } ConstantValue::B256(b) if ty.is_b256(context) => { vec![StorageSlot::new( - get_storage_key(storage_field_names, key), + get_storage_key(storage_field_names, key, experimental), Bytes32::new(b.to_be_bytes()), )] } @@ -244,7 +249,7 @@ pub fn serialize_to_storage_slots( ty.as_string(context) ); - let storage_key = get_storage_key(storage_field_names, key); + let storage_key = get_storage_key(storage_field_names, key, experimental); (0..(type_size_in_bytes + 31) / 32) .map(|i| add_to_b256(storage_key, i)) .zip((0..packed.len() / 4).map(|i| { diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs b/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs index 04ebcfdb907..63c971487f8 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs @@ -71,6 +71,7 @@ impl ty::TyStorageDecl { .key_expression .is_none(), key: format!("0x{:x}", s.key()), + experimental_storage_domains: context.experimental.storage_domains, }, }) } diff --git a/sway-error/src/warning.rs b/sway-error/src/warning.rs index 5ae25ab6a18..dce69c85805 100644 --- a/sway-error/src/warning.rs +++ b/sway-error/src/warning.rs @@ -138,6 +138,8 @@ pub enum Warning { second_field_full_name: String, second_field_key_is_compiler_generated: bool, key: String, + // True if the experimental feature `storage_domains` is used. + experimental_storage_domains: bool, }, } @@ -420,7 +422,7 @@ impl ToDiagnostic for CompileWarning { "Consider adding assembly instructions or a return register to the ASM block, or removing the block altogether.".to_string(), ], }, - DuplicatedStorageKey { first_field, first_field_full_name, first_field_key_is_compiler_generated, second_field, second_field_full_name, second_field_key_is_compiler_generated, key } => Diagnostic { + DuplicatedStorageKey { first_field, first_field_full_name, first_field_key_is_compiler_generated, second_field, second_field_full_name, second_field_key_is_compiler_generated, key, experimental_storage_domains } => Diagnostic { reason: Some(Reason::new(code(1), "Two storage fields have the same storage key".to_string())), issue: Issue::warning( source_engine, @@ -447,14 +449,25 @@ impl ToDiagnostic for CompileWarning { "Both keys are explicitly defined by using the `in` keyword.".to_string() }, if *first_field_key_is_compiler_generated || *second_field_key_is_compiler_generated { - format!("{}sha256((0u8, \"{}\"))", - Indent::Single, - if *first_field_key_is_compiler_generated { - first_field_full_name - } else { - second_field_full_name - } - ) + if *experimental_storage_domains { + format!("{}sha256((0u8, \"{}\"))", + Indent::Single, + if *first_field_key_is_compiler_generated { + first_field_full_name + } else { + second_field_full_name + } + ) + } else { + format!("{}sha256(\"{}\")", + Indent::Single, + if *first_field_key_is_compiler_generated { + first_field_full_name + } else { + second_field_full_name + } + ) + } } else { Diagnostic::help_none() }, diff --git a/sway-features/src/lib.rs b/sway-features/src/lib.rs index 55d50920891..fdff644741a 100644 --- a/sway-features/src/lib.rs +++ b/sway-features/src/lib.rs @@ -131,6 +131,8 @@ impl ExperimentalFeatures { features! { new_encoding = true, "https://github.com/FuelLabs/sway/issues/5727", + storage_domains = false, + "https://github.com/FuelLabs/sway/issues/6701", } #[derive(Clone, Debug, Default, Parser)] @@ -228,6 +230,7 @@ mod tests { let mut features = ExperimentalFeatures { new_encoding: false, + ..Default::default() }; std::env::set_var("FORC_EXPERIMENTAL", "new_encoding"); diff --git a/sway-lib-std/src/storage/storage_map.sw b/sway-lib-std/src/storage/storage_map.sw index 20e5d692b8a..4d7aca969ae 100644 --- a/sway-lib-std/src/storage/storage_map.sw +++ b/sway-lib-std/src/storage/storage_map.sw @@ -19,6 +19,7 @@ use ::storage::storage_key::*; /// The domain prefix for the [StorageMap] is 1u8. /// /// For detailed elaboration see: https://github.com/FuelLabs/sway/issues/6317 +#[cfg(experimental_storage_domains = true)] const STORAGE_MAP_DOMAIN: u8 = 1; /// Errors pertaining to the `StorageMap` struct. @@ -66,7 +67,7 @@ where where K: Hash, { - let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); + let key = self.get_slot_key(key); write::(key, 0, value); } @@ -100,7 +101,7 @@ where where K: Hash, { - let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); + let key = self.get_slot_key(key); StorageKey::::new(key, 0, key) } @@ -139,7 +140,7 @@ where where K: Hash, { - let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); + let key = self.get_slot_key(key); clear::(key, 0) } @@ -190,7 +191,7 @@ where where K: Hash, { - let key = sha256((STORAGE_MAP_DOMAIN, key, self.field_id())); + let key = self.get_slot_key(key); let val = read::(key, 0); @@ -204,4 +205,14 @@ where } } } + + #[cfg(experimental_storage_domains = false)] + fn get_slot_key(self, key: K) -> b256 { + sha256((key, self.field_id())) + } + + #[cfg(experimental_storage_domains = true)] + fn get_slot_key(self, key: K) -> b256 { + sha256((STORAGE_MAP_DOMAIN, key, self.field_id())) + } } diff --git a/test/src/e2e_vm_tests/harness.rs b/test/src/e2e_vm_tests/harness.rs index 164d442e7bf..7ed8ab0353d 100644 --- a/test/src/e2e_vm_tests/harness.rs +++ b/test/src/e2e_vm_tests/harness.rs @@ -398,22 +398,21 @@ pub(crate) fn test_json_abi( } if fs::metadata(oracle_path.clone()).is_err() { - bail!("JSON ABI oracle file does not exist for this test."); + bail!("JSON ABI oracle file does not exist for this test\nExpected oracle path: {}", &oracle_path); } if fs::metadata(output_path.clone()).is_err() { - bail!("JSON ABI output file does not exist for this test."); + bail!("JSON ABI output file does not exist for this test\nExpected output path: {}", &output_path); } let oracle_contents = - fs::read_to_string(&oracle_path).expect("Something went wrong reading the file."); + fs::read_to_string(&oracle_path).expect("Something went wrong reading the JSON ABI oracle file."); let output_contents = - fs::read_to_string(&output_path).expect("Something went wrong reading the file."); + fs::read_to_string(&output_path).expect("Something went wrong reading the JSON ABI output file."); if oracle_contents != output_contents { - println!("Mismatched ABI JSON output [{oracle_path}] versus [{output_path}]",); - println!( - "{}", + bail!("Mismatched ABI JSON output.\nOracle path: {}\nOutput path: {}\n{}", + oracle_path, + output_path, prettydiff::diff_lines(&oracle_contents, &output_contents) ); - bail!("Mismatched ABI JSON output."); } Ok(()) } @@ -435,29 +434,42 @@ fn emit_json_abi(file_name: &str, built_package: &BuiltPackage) -> Result<()> { Ok(()) } -pub(crate) fn test_json_storage_slots(file_name: &str, built_package: &BuiltPackage) -> Result<()> { +pub(crate) fn test_json_storage_slots(file_name: &str, built_package: &BuiltPackage, suffix: &Option,) -> Result<()> { emit_json_storage_slots(file_name, built_package)?; let manifest_dir = env!("CARGO_MANIFEST_DIR"); let oracle_path = format!( - "{}/src/e2e_vm_tests/test_programs/{}/{}", - manifest_dir, file_name, "json_storage_slots_oracle.json" + "{}/src/e2e_vm_tests/test_programs/{}/json_storage_slots_oracle.{}json", + manifest_dir, + file_name, + suffix + .as_ref() + .unwrap() + .strip_prefix("test") + .unwrap() + .strip_suffix("toml") + .unwrap() + .trim_start_matches('.') ); let output_path = format!( "{}/src/e2e_vm_tests/test_programs/{}/{}", manifest_dir, file_name, "json_storage_slots_output.json" ); if fs::metadata(oracle_path.clone()).is_err() { - bail!("JSON storage slots oracle file does not exist for this test."); + bail!("JSON storage slots oracle file does not exist for this test.\nExpected oracle path: {}", &oracle_path); } if fs::metadata(output_path.clone()).is_err() { - bail!("JSON storage slots output file does not exist for this test."); + bail!("JSON storage slots output file does not exist for this test.\nExpected output path: {}", &output_path); } let oracle_contents = - fs::read_to_string(oracle_path).expect("Something went wrong reading the file."); + fs::read_to_string(oracle_path.clone()).expect("Something went wrong reading the JSON storage slots oracle file."); let output_contents = - fs::read_to_string(output_path).expect("Something went wrong reading the file."); + fs::read_to_string(output_path.clone()).expect("Something went wrong reading the JSON storage slots output file."); if oracle_contents != output_contents { - bail!("Mismatched storage slots JSON output."); + bail!("Mismatched storage slots JSON output.\nOracle path: {}\nOutput path: {}\n{}", + oracle_path, + output_path, + prettydiff::diff_lines(&oracle_contents, &output_contents) + ); } Ok(()) } diff --git a/test/src/e2e_vm_tests/mod.rs b/test/src/e2e_vm_tests/mod.rs index 62dc360fea1..6fc6ff8ae04 100644 --- a/test/src/e2e_vm_tests/mod.rs +++ b/test/src/e2e_vm_tests/mod.rs @@ -515,7 +515,7 @@ impl TestContext { if validate_storage_slots { for (name, built_pkg) in &compiled_pkgs { let (result, out) = run_and_capture_output(|| async { - harness::test_json_storage_slots(name, built_pkg) + harness::test_json_storage_slots(name, built_pkg, &suffix) }) .await; result?; @@ -602,7 +602,9 @@ impl TestContext { ))); } } - _ => todo!(), + TestResult::ReturnData(_) => todo!("Test result `ReturnData` is currently not implemented."), + TestResult::Return(_) => todo!("Test result `Return` is currently not implemented."), + TestResult::Revert(_) => todo!("Test result `Revert` is currently not implemented."), }, Receipt::ReturnData { data, .. } => match expected_result.unwrap() { TestResult::ReturnData(v) => { @@ -612,7 +614,9 @@ impl TestContext { ))); } } - _ => todo!(), + TestResult::Result(_) => todo!("Test result `Result` is currently not implemented."), + TestResult::Return(_) => todo!("Test result `Return` is currently not implemented."), + TestResult::Revert(_) => todo!("Test result `Revert` is currently not implemented."), }, _ => {} }; diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json deleted file mode 100644 index 0637a088a01..00000000000 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/json_abi_oracle.json +++ /dev/null @@ -1 +0,0 @@ -[] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw index 78ab282305b..18a4f599f52 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/src/main.sw @@ -1,5 +1,9 @@ contract; +fn get_u256() -> u256 { + 0x0u256 +} + storage { - field in u256::zero(): u64 = 0, + field in get_u256(): u64 = 0, } \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml index 1699fb78d80..150a184e449 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_fail/storage_invalid_storage_key_type/test.toml @@ -1,14 +1,14 @@ category = "fail" #check: $()error -#check: $()field in u256::zero(): u64 = 0, +#check: $()field in get_u256(): u64 = 0, #nextln: $()Mismatched types. #nextln: $()expected: b256 #nextln: $()found: u256. #nextln: $()Function return type does not match up with local type annotation. #check: $()error -#check: $()field in u256::zero(): u64 = 0, +#check: $()field in get_u256(): u64 = 0, #nextln: $()Mismatched types. #nextln: $()expected: b256 #nextln: $()found: u256. diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw index 6a6c6903558..2bfa29631e6 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/src/main.sw @@ -2,7 +2,10 @@ contract; storage { f1:u64 = 1, + #[cfg(experimental_storage_domains = true)] f2 in 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b: u64 = 2, + #[cfg(experimental_storage_domains = false)] + f2 in 0x36389d1013642dcb070193fc48b0316e9dfdfef1860096dc5957e3eb44430b83: u64 = 2, ns1 { f3 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, }, @@ -10,7 +13,10 @@ storage { f4 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, }, ns3 { + #[cfg(experimental_storage_domains = true)] f5 in 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069: u64 = 3, + #[cfg(experimental_storage_domains = false)] + f5 in 0xa49ebab6739a90f7658bbbdc2ed139942bd0b7be2e89aa8d90a953c45bf7a211: u64 = 3, }, ns4 { f6: u64 = 4, diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.storage_domains.toml new file mode 100644 index 00000000000..4e181f7e13d --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.storage_domains.toml @@ -0,0 +1,30 @@ +category = "compile" +experimental = { storage_domains = true } + +# check: $()Two storage fields have the same storage key +# check: $()f1:u64 = 1, +# nextln: $()"storage.f1" has the same storage key as "storage.f2". +# check: $()f2 in 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b: u64 = 2, +# nextln: $()"storage.f2" is declared here. +# check: $()The key of "storage.f1" is generated by the compiler using the following formula: +# nextln: $()sha256((0u8, "storage.f1")) +# nextln: $()The common key is: 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b. + +# check: $()Two storage fields have the same storage key +# check: $()f3 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, +# nextln: $()"storage::ns1.f3" has the same storage key as "storage::ns2.f4". +# check: $()f4 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, +# nextln: $()"storage::ns2.f4" is declared here. +# check: $()Both keys are explicitly defined by using the `in` keyword. +# nextln: $()The common key is: 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca. + +# check: $()Two storage fields have the same storage key +# check: $()f5 in 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069: u64 = 3, +# nextln: $()"storage::ns3.f5" has the same storage key as "storage::ns4.f6". +# check: $()f6: u64 = 4, +# nextln: $()"storage::ns4.f6" is declared here. +# check: $()The key of "storage::ns4.f6" is generated by the compiler using the following formula: +# nextln: $()sha256((0u8, "storage::ns4.f6")) +# nextln: $()The common key is: 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069. + +expected_warnings = 9 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml index 9229425d18a..30c36d8b5f8 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml +++ b/test/src/e2e_vm_tests/test_programs/should_pass/language/duplicated_storage_keys/test.toml @@ -3,11 +3,11 @@ category = "compile" # check: $()Two storage fields have the same storage key # check: $()f1:u64 = 1, # nextln: $()"storage.f1" has the same storage key as "storage.f2". -# check: $()f2 in 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b: u64 = 2, +# check: $()f2 in 0x36389d1013642dcb070193fc48b0316e9dfdfef1860096dc5957e3eb44430b83: u64 = 2, # nextln: $()"storage.f2" is declared here. # check: $()The key of "storage.f1" is generated by the compiler using the following formula: -# nextln: $()sha256((0u8, "storage.f1")) -# nextln: $()The common key is: 0xcecf0a910789de762c699a85a66835df1662df633238cbb25804b7f78640747b. +# nextln: $()sha256("storage.f1") +# nextln: $()The common key is: 0x36389d1013642dcb070193fc48b0316e9dfdfef1860096dc5957e3eb44430b83. # check: $()Two storage fields have the same storage key # check: $()f3 in 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca: u64 = 2, @@ -18,12 +18,12 @@ category = "compile" # nextln: $()The common key is: 0x5f4c20ce4bd128e5393a4c2b82007dac795fa0006d01acf8db4c42632bc680ca. # check: $()Two storage fields have the same storage key -# check: $()f5 in 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069: u64 = 3, +# check: $()f5 in 0xa49ebab6739a90f7658bbbdc2ed139942bd0b7be2e89aa8d90a953c45bf7a211: u64 = 3, # nextln: $()"storage::ns3.f5" has the same storage key as "storage::ns4.f6". # check: $()f6: u64 = 4, # nextln: $()"storage::ns4.f6" is declared here. # check: $()The key of "storage::ns4.f6" is generated by the compiler using the following formula: -# nextln: $()sha256((0u8, "storage::ns4.f6")) -# nextln: $()The common key is: 0x41e70e0fdfa49becc40cbfd5c057ab0540e8844f3d737fa3b1ab21a564b48069. +# nextln: $()sha256("storage::ns4.f6") +# nextln: $()The common key is: 0xa49ebab6739a90f7658bbbdc2ed139942bd0b7be2e89aa8d90a953c45bf7a211. expected_warnings = 9 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 d519240f19d..3e775aa38ad 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 = 0x770eb6e1b7de06098474e110cac9ed32c72c455ba7f34bea00ebb47a43986701; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release +const CONTRACT_ID = 0x918deef6932aa65b243a70e1abddc4fa07964038270f137e1759f797dcbc9422; // 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_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 c91268acb0f..02b20a7db63 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 = 0x14df60f48d5874d2623ba7f5604987b29f6288a1ae35a130bfae57e64f74aa89; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release +const CONTRACT_ID = 0x3eb4e52446444c5b4450aa5b88f68e971aef07d4a0f62147810f5a0fa0e763cf; // 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/storage_slot_key_calculation/Forc.lock b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.lock new file mode 100644 index 00000000000..fe96407a20f --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.lock @@ -0,0 +1,13 @@ +[[package]] +name = "core" +source = "path+from-root-90F1067CD9AC8A94" + +[[package]] +name = "std" +source = "path+from-root-90F1067CD9AC8A94" +dependencies = ["core"] + +[[package]] +name = "storage_slot_key_calculation" +source = "member" +dependencies = ["std"] diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.toml b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.toml new file mode 100644 index 00000000000..cb479a470ea --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/Forc.toml @@ -0,0 +1,8 @@ +[project] +name = "storage_slot_key_calculation" +authors = ["Fuel Labs "] +entry = "main.sw" +license = "Apache-2.0" + +[dependencies] +std = { path = "../../../../../../sway-lib-std" } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/src/main.sw new file mode 100644 index 00000000000..a4810dff242 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/src/main.sw @@ -0,0 +1,53 @@ +contract; + +use std::hash::*; + +storage { + a: u8 = 0, + b: u8 = 0, + ns1 { + a: u8 = 0, + b: u8 = 0, + }, + ns2 { + ns3 { + a: u8 = 0, + b: u8 = 0, + }, + }, +} + +abi TestStorageKeyCalculation { + #[storage(read)] + fn test_storage_key_calculation(); +} + +impl TestStorageKeyCalculation for Contract { + #[cfg(experimental_storage_domains = false)] + #[storage(read)] + fn test_storage_key_calculation() { + assert_eq(storage.a.slot(), sha256("storage.a")); + assert_eq(storage.b.slot(), sha256("storage.b")); + assert_eq(storage::ns1.a.slot(), sha256("storage::ns1.a")); + assert_eq(storage::ns1.b.slot(), sha256("storage::ns1.b")); + assert_eq(storage::ns2::ns3.a.slot(), sha256("storage::ns2::ns3.a")); + assert_eq(storage::ns2::ns3.b.slot(), sha256("storage::ns2::ns3.b")); + } + + #[cfg(experimental_storage_domains = true)] + #[storage(read)] + fn test_storage_key_calculation() { + assert_eq(storage.a.slot(), sha256((0u8, "storage.a"))); + assert_eq(storage.b.slot(), sha256((0u8, "storage.b"))); + assert_eq(storage::ns1.a.slot(), sha256((0u8, "storage::ns1.a"))); + assert_eq(storage::ns1.b.slot(), sha256((0u8, "storage::ns1.b"))); + assert_eq(storage::ns2::ns3.a.slot(), sha256((0u8, "storage::ns2::ns3.a"))); + assert_eq(storage::ns2::ns3.b.slot(), sha256((0u8, "storage::ns2::ns3.b"))); + } +} + +#[test] +fn test() { + let caller = abi(TestStorageKeyCalculation, CONTRACT_ID); + caller.test_storage_key_calculation(); +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.storage_domains.toml new file mode 100644 index 00000000000..0890b8a8510 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.storage_domains.toml @@ -0,0 +1 @@ +experimental = { storage_domains = true } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.toml b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.toml new file mode 100644 index 00000000000..c82484373af --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/storage_slot_key_calculation/test.toml @@ -0,0 +1,2 @@ +category = "unit_tests_pass" +expected_warnings = 1 diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.storage_domains.json new file mode 100644 index 00000000000..2f821ed58f1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_abi_oracle.storage_domains.json @@ -0,0 +1,297 @@ +{ + "concreteTypes": [ + { + "concreteTypeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d", + "type": "()" + }, + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "type": "b256" + }, + { + "concreteTypeId": "d852149004cc9ec0bbe7dc4e37bffea1d41469b759512b6136f2e865a4c06e7d", + "metadataTypeId": 0, + "type": "enum std::option::Option", + "typeArguments": [ + "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + ] + }, + { + "concreteTypeId": "6906df92e2e485dde893b7d719d621b8910422e7c468f99caa5920e6ac19d9c6", + "metadataTypeId": 3, + "type": "struct basic_storage_abi::Quad" + }, + { + "concreteTypeId": "7880d311d30802b48bd6a100a31adb5af17f94bff12daee556d4f02c1ac5b2ff", + "metadataTypeId": 5, + "type": "struct std::vec::Vec", + "typeArguments": [ + "6906df92e2e485dde893b7d719d621b8910422e7c468f99caa5920e6ac19d9c6" + ] + }, + { + "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", + "type": "u256" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "type": "u64" + }, + { + "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", + "type": "u8" + } + ], + "configurables": [], + "encodingVersion": "1", + "functions": [ + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "storage_key" + } + ], + "name": "get_u64", + "output": "d852149004cc9ec0bbe7dc4e37bffea1d41469b759512b6136f2e865a4c06e7d" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "slots" + } + ], + "name": "intrinsic_load_quad", + "output": "7880d311d30802b48bd6a100a31adb5af17f94bff12daee556d4f02c1ac5b2ff" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + } + ], + "name": "intrinsic_load_word", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "7880d311d30802b48bd6a100a31adb5af17f94bff12daee556d4f02c1ac5b2ff", + "name": "values" + } + ], + "name": "intrinsic_store_quad", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "value" + } + ], + "name": "intrinsic_store_word", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "value" + } + ], + "name": "store_u64", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "read", + "write" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "test_storage_exhaustive", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + } + ], + "loggedTypes": [ + { + "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", + "logId": "14454674236531057292" + }, + { + "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", + "logId": "1970142151624111756" + }, + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "logId": "8961848586872524460" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "logId": "1515152261580153489" + } + ], + "messagesTypes": [], + "metadataTypes": [ + { + "components": [ + { + "name": "None", + "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "name": "Some", + "typeId": 1 + } + ], + "metadataTypeId": 0, + "type": "enum std::option::Option", + "typeParameters": [ + 1 + ] + }, + { + "metadataTypeId": 1, + "type": "generic T" + }, + { + "metadataTypeId": 2, + "type": "raw untyped ptr" + }, + { + "components": [ + { + "name": "v1", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "v2", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "v3", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "v4", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "metadataTypeId": 3, + "type": "struct basic_storage_abi::Quad" + }, + { + "components": [ + { + "name": "ptr", + "typeId": 2 + }, + { + "name": "cap", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "metadataTypeId": 4, + "type": "struct std::vec::RawVec", + "typeParameters": [ + 1 + ] + }, + { + "components": [ + { + "name": "buf", + "typeArguments": [ + { + "name": "", + "typeId": 1 + } + ], + "typeId": 4 + }, + { + "name": "len", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "metadataTypeId": 5, + "type": "struct std::vec::Vec", + "typeParameters": [ + 1 + ] + } + ], + "programType": "contract", + "specVersion": "1" +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json index 8c0169567bb..b2063f1474b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.json @@ -1,58 +1,58 @@ [ { - "key": "040f131e97eaba9c2d25f5c1d6ea9489ce530940dd87d486f8cd9c7ff5360f6c", - "value": "6161616161000000000000000000000000000000000000000000000000000000" - }, - { - "key": "077f64b0ca598a020551265c0faf95f8e860b45700f27c06af3640a123818b17", - "value": "6161000000000000000000000000000000000000000000000000000000000000" + "key": "26a0f316674277151cdb647fc857710df30dca882c9c61a48e35790d5cb75159", + "value": "6161616161616161000000000000000000000000000000000000000000000000" }, { - "key": "2b46310c8d886cf7d9e4339837ecc696ecfaf2c431e56e725c552b92b11c3bc8", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "2873dd8e90786169217d1dc180cdbeb5642b04daf3979c26776d8b8e93720c12", + "value": "6161616161610000000000000000000000000000000000000000000000000000" }, { - "key": "30226b031f925fbb2a1ad161ce31b798a684c6f52ed49cf84e244d324eceaf58", - "value": "6161616100000000000000000000000000000000000000000000000000000000" + "key": "323860f3257dc73a83c0b26b915b97575ef2cf8cc150988eb0b0fae2fe61ad77", + "value": "6100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "42e97a774f87c61347e7283755a043a5a896d37e801045e8f5ce538b6d1ce8c8", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "3c025b285aab5e23d355e104b29cb021a7581c1485c4aee6f93c3a37569636ef", + "value": "6161616161000000000000000000000000000000000000000000000000000000" }, { - "key": "78dabd24c80fc40f05bae92654874f2f77bd13ef803fd55ccf014ff5849cdfd0", - "value": "6161616161610000000000000000000000000000000000000000000000000000" + "key": "533dcc8c8bc47b384931e0bdab958e580a48b65d633991b87ecf6f035a2ec53a", + "value": "0000000000000002000000000000000000000000000000000000000000000000" }, { - "key": "848a0a618b9c374a4b1b47c59ef2f0a01f5c42bb5e805ffd669412ce283b992a", - "value": "6161616161616161000000000000000000000000000000000000000000000000" + "key": "67572eb5ab2c5a6c11d8a7217f617a380ad7adbe7e7fed0ffa18be2a11ae78fc", + "value": "6161000000000000000000000000000000000000000000000000000000000000" }, { - "key": "84e44dc0900861559343f0fc02dc0d92f7e87872a50e730a85740b701b162863", - "value": "6161616161616100000000000000000000000000000000000000000000000000" + "key": "6c1f46e5e38cfa9767a552ab89186da5647f603b447e226eb8b0fdbdefb97f0e", + "value": "6161616161616161616100000000000000000000000000000000000000000000" }, { "key": "933a534d4af4c376b0b569e8d8a2c62e635e26f403e124cb91d9c42e83d54373", "value": "0100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "976540acfef542cb328d6679def3e281cdb1a5bbaca7d9e59a30aa74f3952d90", - "value": "6100000000000000000000000000000000000000000000000000000000000000" + "key": "98ba41aa317c3ee2a207b8deaf0a3386a1705b2548777944f29d8a288999c460", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "9d3f8eb1f2d99b97a2fd6fa68fe7e5a9c5b6734739f8dd84f2ae3da221206a80", - "value": "0000000000000002000000000000000000000000000000000000000000000000" + "key": "a605c78ce1b8f4b67230a55ea491e2b7c5f3d6099cbdcb67e8bf60c9678ae047", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "a42ed3ecc6aaf8d594f165e6c60cdaf172d59436167556f954e6559036736ceb", - "value": "6161610000000000000000000000000000000000000000000000000000000000" + "key": "c4085ef85fb993a44237f78f083c0e96be21522fa8d00bd74b8b8d51b8aa2e8a", + "value": "6161616100000000000000000000000000000000000000000000000000000000" }, { - "key": "d33763008c92b260fc4381d53aa5976de2b5f991798799fa5edf300bb4a40e02", - "value": "6161616161616161616100000000000000000000000000000000000000000000" + "key": "d40c4527ee86df5ab69139820872760c294318505804f4327672d6ce7ee2e15f", + "value": "6161616161616100000000000000000000000000000000000000000000000000" + }, + { + "key": "dc7ac8a34653cb050eb9eeb0792ed909ecaf9df17158e8c2a44820cada45805b", + "value": "6161610000000000000000000000000000000000000000000000000000000000" }, { - "key": "f8fde9e56bb5ab545fdfe17edabb876e6f4cd1b3296d92b266d4acb9ca0b5f79", + "key": "eafb8114029f277e266bedc3d0b60a5576e8476bc97b96ea42482e20ad15e051", "value": "6161616161616161610000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.storage_domains.json new file mode 100644 index 00000000000..8c0169567bb --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/json_storage_slots_oracle.storage_domains.json @@ -0,0 +1,58 @@ +[ + { + "key": "040f131e97eaba9c2d25f5c1d6ea9489ce530940dd87d486f8cd9c7ff5360f6c", + "value": "6161616161000000000000000000000000000000000000000000000000000000" + }, + { + "key": "077f64b0ca598a020551265c0faf95f8e860b45700f27c06af3640a123818b17", + "value": "6161000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "2b46310c8d886cf7d9e4339837ecc696ecfaf2c431e56e725c552b92b11c3bc8", + "value": "0000000000000000000000000000000000000000000000000000000001234567" + }, + { + "key": "30226b031f925fbb2a1ad161ce31b798a684c6f52ed49cf84e244d324eceaf58", + "value": "6161616100000000000000000000000000000000000000000000000000000000" + }, + { + "key": "42e97a774f87c61347e7283755a043a5a896d37e801045e8f5ce538b6d1ce8c8", + "value": "0000000000000000000000000000000000000000000000000000000001234567" + }, + { + "key": "78dabd24c80fc40f05bae92654874f2f77bd13ef803fd55ccf014ff5849cdfd0", + "value": "6161616161610000000000000000000000000000000000000000000000000000" + }, + { + "key": "848a0a618b9c374a4b1b47c59ef2f0a01f5c42bb5e805ffd669412ce283b992a", + "value": "6161616161616161000000000000000000000000000000000000000000000000" + }, + { + "key": "84e44dc0900861559343f0fc02dc0d92f7e87872a50e730a85740b701b162863", + "value": "6161616161616100000000000000000000000000000000000000000000000000" + }, + { + "key": "933a534d4af4c376b0b569e8d8a2c62e635e26f403e124cb91d9c42e83d54373", + "value": "0100000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "976540acfef542cb328d6679def3e281cdb1a5bbaca7d9e59a30aa74f3952d90", + "value": "6100000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "9d3f8eb1f2d99b97a2fd6fa68fe7e5a9c5b6734739f8dd84f2ae3da221206a80", + "value": "0000000000000002000000000000000000000000000000000000000000000000" + }, + { + "key": "a42ed3ecc6aaf8d594f165e6c60cdaf172d59436167556f954e6559036736ceb", + "value": "6161610000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "d33763008c92b260fc4381d53aa5976de2b5f991798799fa5edf300bb4a40e02", + "value": "6161616161616161616100000000000000000000000000000000000000000000" + }, + { + "key": "f8fde9e56bb5ab545fdfe17edabb876e6f4cd1b3296d92b266d4acb9ca0b5f79", + "value": "6161616161616161610000000000000000000000000000000000000000000000" + } +] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw index 768a3c6d7e3..251577caf5b 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/src/main.sw @@ -296,8 +296,6 @@ fn test_storage() { assert_eq(storage::ns1::ns2.c1.read(), NS1_NS2_C1); assert_eq(storage.c1.slot(), C1KEY); - assert_eq(storage.const_b256.slot(), sha256((0u8,"storage.const_b256"))); - assert_eq(storage::ns1::ns2.c1.slot(), sha256((0u8,"storage::ns1::ns2.c1"))); } // If these comparisons are done inline just above then it blows out the register allocator due to diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.storage_domains.toml new file mode 100644 index 00000000000..0890b8a8510 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/basic_storage/test.storage_domains.toml @@ -0,0 +1 @@ +experimental = { storage_domains = true } diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_abi_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_abi_oracle.storage_domains.json new file mode 100644 index 00000000000..edd98a1f3d1 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_abi_oracle.storage_domains.json @@ -0,0 +1,102 @@ +{ + "concreteTypes": [ + { + "concreteTypeId": "d852149004cc9ec0bbe7dc4e37bffea1d41469b759512b6136f2e865a4c06e7d", + "metadataTypeId": 1, + "type": "enum std::option::Option", + "typeArguments": [ + "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + ] + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "type": "u64" + } + ], + "configurables": [], + "encodingVersion": "1", + "functions": [ + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read", + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "increment_by" + } + ], + "name": "increment", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read", + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "d852149004cc9ec0bbe7dc4e37bffea1d41469b759512b6136f2e865a4c06e7d", + "name": "initial_value" + } + ], + "name": "increment_or_not", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "loggedTypes": [], + "messagesTypes": [], + "metadataTypes": [ + { + "metadataTypeId": 0, + "type": "()" + }, + { + "components": [ + { + "name": "None", + "typeId": 0 + }, + { + "name": "Some", + "typeId": 2 + } + ], + "metadataTypeId": 1, + "type": "enum std::option::Option", + "typeParameters": [ + 2 + ] + }, + { + "metadataTypeId": 2, + "type": "generic T" + } + ], + "programType": "contract", + "specVersion": "1" +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json index efa6132760a..27d01be9eb2 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.json @@ -1,6 +1,6 @@ [ { - "key": "d810923c0d6cc6ed49622594d7368eb1e124753474e3ebd52a66c6c2ecb42642", + "key": "1f5327d8b018fe8a341aec49e087546980b521535a650107a53efdc5e7038723", "value": "0000000000000000000000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.storage_domains.json new file mode 100644 index 00000000000..efa6132760a --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/json_storage_slots_oracle.storage_domains.json @@ -0,0 +1,6 @@ +[ + { + "key": "d810923c0d6cc6ed49622594d7368eb1e124753474e3ebd52a66c6c2ecb42642", + "value": "0000000000000000000000000000000000000000000000000000000000000000" + } +] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/test.storage_domains.toml new file mode 100644 index 00000000000..24be96bbf31 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/increment_contract/test.storage_domains.toml @@ -0,0 +1 @@ +experimental = { storage_domains = true } \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle.storage_domains.json new file mode 100644 index 00000000000..9a1f9ebd31e --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_abi_oracle.storage_domains.json @@ -0,0 +1,769 @@ +{ + "concreteTypes": [ + { + "concreteTypeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d", + "type": "()" + }, + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "type": "b256" + }, + { + "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", + "type": "bool" + }, + { + "concreteTypeId": "35b24140807b67d1f1675de36775d5d6c62b04f3721f616a9adee739e24c9c15", + "metadataTypeId": 0, + "type": "enum storage_access_abi::E" + }, + { + "concreteTypeId": "893a66eb2f595d7e0cc15e2253da1b6e53fd634ad542b2f1a198a8ae3d8d92b2", + "type": "str[40]" + }, + { + "concreteTypeId": "427fd62288add8763eb5e0c4facf553d877489a3038b29a8a1045e9a853660f0", + "metadataTypeId": 1, + "type": "struct storage_access_abi::S" + }, + { + "concreteTypeId": "74df8abb4a65a07ec7420c0f167703fc6e26c9e43b8036ffacb89d399f13db73", + "metadataTypeId": 2, + "type": "struct storage_access_abi::T" + }, + { + "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", + "type": "u16" + }, + { + "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", + "type": "u32" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "type": "u64" + }, + { + "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", + "type": "u8" + } + ], + "configurables": [], + "encodingVersion": "1", + "functions": [ + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_boolean", + "output": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_e", + "output": "35b24140807b67d1f1675de36775d5d6c62b04f3721f616a9adee739e24c9c15" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_e2", + "output": "35b24140807b67d1f1675de36775d5d6c62b04f3721f616a9adee739e24c9c15" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_int16", + "output": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_int32", + "output": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_int8", + "output": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s", + "output": "427fd62288add8763eb5e0c4facf553d877489a3038b29a8a1045e9a853660f0" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t", + "output": "74df8abb4a65a07ec7420c0f167703fc6e26c9e43b8036ffacb89d399f13db73" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_boolean", + "output": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_int16", + "output": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_int32", + "output": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_int8", + "output": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_x", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_y", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_t_dot_z", + "output": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_x", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_y", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_s_dot_z", + "output": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_string", + "output": "893a66eb2f595d7e0cc15e2253da1b6e53fd634ad542b2f1a198a8ae3d8d92b2" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_x", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "get_y", + "output": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", + "name": "boolean" + } + ], + "name": "set_boolean", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "35b24140807b67d1f1675de36775d5d6c62b04f3721f616a9adee739e24c9c15", + "name": "e" + } + ], + "name": "set_e", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", + "name": "int16" + } + ], + "name": "set_int16", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", + "name": "int32" + } + ], + "name": "set_int32", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", + "name": "int8" + } + ], + "name": "set_int8", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "427fd62288add8763eb5e0c4facf553d877489a3038b29a8a1045e9a853660f0", + "name": "s" + } + ], + "name": "set_s", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "74df8abb4a65a07ec7420c0f167703fc6e26c9e43b8036ffacb89d399f13db73", + "name": "t" + } + ], + "name": "set_s_dot_t", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", + "name": "boolean" + } + ], + "name": "set_s_dot_t_dot_boolean", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef", + "name": "int16" + } + ], + "name": "set_s_dot_t_dot_int16", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc", + "name": "int32" + } + ], + "name": "set_s_dot_t_dot_int32", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b", + "name": "int8" + } + ], + "name": "set_s_dot_t_dot_int8", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "x" + } + ], + "name": "set_s_dot_t_dot_x", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "y" + } + ], + "name": "set_s_dot_t_dot_y", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "z" + } + ], + "name": "set_s_dot_t_dot_z", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "x" + } + ], + "name": "set_s_dot_x", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "y" + } + ], + "name": "set_s_dot_y", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "z" + } + ], + "name": "set_s_dot_z", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "893a66eb2f595d7e0cc15e2253da1b6e53fd634ad542b2f1a198a8ae3d8d92b2", + "name": "string" + } + ], + "name": "set_string", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "x" + } + ], + "name": "set_x", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "y" + } + ], + "name": "set_y", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + } + ], + "loggedTypes": [ + { + "concreteTypeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903", + "logId": "13213829929622723620" + } + ], + "messagesTypes": [], + "metadataTypes": [ + { + "components": [ + { + "name": "A", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "B", + "typeId": 2 + } + ], + "metadataTypeId": 0, + "type": "enum storage_access_abi::E" + }, + { + "components": [ + { + "name": "x", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "y", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "z", + "typeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b" + }, + { + "name": "t", + "typeId": 2 + } + ], + "metadataTypeId": 1, + "type": "struct storage_access_abi::S" + }, + { + "components": [ + { + "name": "x", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "y", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "z", + "typeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b" + }, + { + "name": "boolean", + "typeId": "b760f44fa5965c2474a3b471467a22c43185152129295af588b022ae50b50903" + }, + { + "name": "int8", + "typeId": "c89951a24c6ca28c13fd1cfdc646b2b656d69e61a92b91023be7eb58eb914b6b" + }, + { + "name": "int16", + "typeId": "29881aad8730c5ab11d275376323d8e4ff4179aae8ccb6c13fe4902137e162ef" + }, + { + "name": "int32", + "typeId": "d7649d428b9ff33d188ecbf38a7e4d8fd167fa01b2e10fe9a8f9308e52f1d7cc" + } + ], + "metadataTypeId": 2, + "type": "struct storage_access_abi::T" + } + ], + "programType": "contract", + "specVersion": "1" +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json index ff1eae7956b..24a5f2c6daf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.json @@ -1,74 +1,74 @@ [ { - "key": "419b1120ea993203d7e223dfbe76184322453d6f8de946e827a8669102ab395b", - "value": "0000000000000040000000000000000000000000000000000000000000000000" - }, - { - "key": "4b06f7ce27bc88217a7c9d4300619d2900cef25ecb29a790ec869b02e4191275", - "value": "4141414141414141414141414141414141414141414141414141414141414141" + "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87cb", + "value": "0000000000000001000000000000000200000000000000000000000000000000" }, { - "key": "4b06f7ce27bc88217a7c9d4300619d2900cef25ecb29a790ec869b02e4191276", - "value": "4141414141414141000000000000000000000000000000000000000000000000" + "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87cc", + "value": "0000000000000000000000000000000300000000000000040000000000000005" }, { - "key": "7299da45c4430837636de04fb23f3343a80d88c1dc0455562b3066913f0d7745", - "value": "0000000000000020000000000000000000000000000000000000000000000000" + "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87cd", + "value": "0000000000000000000000000000000000000000000000000000000000000006" }, { - "key": "865b6b6b53f4babe503029163d7076d649da88a10c4ed333d19c645d271f495c", - "value": "0000000000000010000000000000000000000000000000000000000000000000" + "key": "06ee74b45a12fd83e7df88440f9b3aef7a275760bf6742de13f2007316af87ce", + "value": "0100000000000000070000000000000000000000000000080000000000000009" }, { - "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0c", - "value": "0000000000000001000000000000000100000000000000020000000000000000" + "key": "5dc4bb371cab39153d3503dc677662a2c02b616d1789ffc8c7f11cd6838a5b8d", + "value": "0000000000000020000000000000000000000000000000000000000000000000" }, { - "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0d", - "value": "0000000000000000000000000000000000000000000000030100000000000000" + "key": "9a1c37d22e51c475d6284f621e29ad5753c418595c5d7b24a7d1684f11f31adf", + "value": "0100000000000000000000000000000000000000000000000000000000000000" }, { - "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0e", - "value": "0400000000000000000000000000000500000000000000060000000000000000" + "key": "a87982353688625e3011294e19aa0a5c027b02e2045c8df73c59cf2142416a37", + "value": "0000000000000010000000000000000000000000000000000000000000000000" }, { - "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f2", + "key": "aa834639bd045ecb5b8644fda6256196e090c28df31665d3ab8516fb89fb39cd", "value": "0000000000000000000000000000000000000000000000000000000000000000" }, { - "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f3", + "key": "aa834639bd045ecb5b8644fda6256196e090c28df31665d3ab8516fb89fb39ce", "value": "0000000000000000000000000000000000000000000000000000000000000000" }, { - "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f4", + "key": "aa834639bd045ecb5b8644fda6256196e090c28df31665d3ab8516fb89fb39cf", "value": "0000000000000000000000000000000000000000000003090000000000000000" }, { - "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c86", - "value": "0000000000000001000000000000000200000000000000000000000000000000" + "key": "ae4a9d6171099362a9d5a398016d7bf8555a8ba706d68ef7c879d4a439c8a6d5", + "value": "4141414141414141414141414141414141414141414141414141414141414141" }, { - "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c87", - "value": "0000000000000000000000000000000300000000000000040000000000000005" + "key": "ae4a9d6171099362a9d5a398016d7bf8555a8ba706d68ef7c879d4a439c8a6d6", + "value": "4141414141414141000000000000000000000000000000000000000000000000" }, { - "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c88", - "value": "0000000000000000000000000000000000000000000000000000000000000006" + "key": "b9ffa363d401358f328bb44e635cded3208652b383e46c121afb23d599356f41", + "value": "0800000000000000000000000000000000000000000000000000000000000000" }, { - "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c89", - "value": "0100000000000000070000000000000000000000000000080000000000000009" + "key": "c979570128d5f52725e9a343a7f4992d8ed386d7c8cfd25f1c646c51c2ac6b4b", + "value": "0000000000000040000000000000000000000000000000000000000000000000" }, { - "key": "d871d81721e9905a5cafe5b82dfde0ddb930f96a8e6deb44f92a8c9ce4d24ac1", - "value": "0800000000000000000000000000000000000000000000000000000000000000" + "key": "d95f4c8d717d52323d34c1118b3f0598a5ec3cabae386887507cabd6dd546a43", + "value": "0101010101010101010101010101010101010101010101010101010101010101" }, { - "key": "e8aaf9a6b72b4eee2bcb2315773bc50e9166ff05c4221843637e25f0424a5dd5", - "value": "0100000000000000000000000000000000000000000000000000000000000000" + "key": "e153542f820f1e716d34120d0ea017c2fab2e2545c0556584bc7462f2dafb3bd", + "value": "0000000000000001000000000000000100000000000000020000000000000000" }, { - "key": "eb390d9f85c8c849ff8aeb05c865ca66b37ba69a7bec8489b1c467f029b650af", - "value": "0101010101010101010101010101010101010101010101010101010101010101" + "key": "e153542f820f1e716d34120d0ea017c2fab2e2545c0556584bc7462f2dafb3be", + "value": "0000000000000000000000000000000000000000000000030100000000000000" + }, + { + "key": "e153542f820f1e716d34120d0ea017c2fab2e2545c0556584bc7462f2dafb3bf", + "value": "0400000000000000000000000000000500000000000000060000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.storage_domains.json new file mode 100644 index 00000000000..ff1eae7956b --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/json_storage_slots_oracle.storage_domains.json @@ -0,0 +1,74 @@ +[ + { + "key": "419b1120ea993203d7e223dfbe76184322453d6f8de946e827a8669102ab395b", + "value": "0000000000000040000000000000000000000000000000000000000000000000" + }, + { + "key": "4b06f7ce27bc88217a7c9d4300619d2900cef25ecb29a790ec869b02e4191275", + "value": "4141414141414141414141414141414141414141414141414141414141414141" + }, + { + "key": "4b06f7ce27bc88217a7c9d4300619d2900cef25ecb29a790ec869b02e4191276", + "value": "4141414141414141000000000000000000000000000000000000000000000000" + }, + { + "key": "7299da45c4430837636de04fb23f3343a80d88c1dc0455562b3066913f0d7745", + "value": "0000000000000020000000000000000000000000000000000000000000000000" + }, + { + "key": "865b6b6b53f4babe503029163d7076d649da88a10c4ed333d19c645d271f495c", + "value": "0000000000000010000000000000000000000000000000000000000000000000" + }, + { + "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0c", + "value": "0000000000000001000000000000000100000000000000020000000000000000" + }, + { + "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0d", + "value": "0000000000000000000000000000000000000000000000030100000000000000" + }, + { + "key": "8e06966f123f8d6e298f853c70d34036061474c4674b7960119ac4a08a557f0e", + "value": "0400000000000000000000000000000500000000000000060000000000000000" + }, + { + "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f2", + "value": "0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f3", + "value": "0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "9538bea0a4c2601b6bd45782e4c10df5728427e310421d9a5d93f85a1f3704f4", + "value": "0000000000000000000000000000000000000000000003090000000000000000" + }, + { + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c86", + "value": "0000000000000001000000000000000200000000000000000000000000000000" + }, + { + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c87", + "value": "0000000000000000000000000000000300000000000000040000000000000005" + }, + { + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c88", + "value": "0000000000000000000000000000000000000000000000000000000000000006" + }, + { + "key": "ae10a55cca3f364be094340b109ccf393d12c2c07417ff2e719b1816ac793c89", + "value": "0100000000000000070000000000000000000000000000080000000000000009" + }, + { + "key": "d871d81721e9905a5cafe5b82dfde0ddb930f96a8e6deb44f92a8c9ce4d24ac1", + "value": "0800000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "e8aaf9a6b72b4eee2bcb2315773bc50e9166ff05c4221843637e25f0424a5dd5", + "value": "0100000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "eb390d9f85c8c849ff8aeb05c865ca66b37ba69a7bec8489b1c467f029b650af", + "value": "0101010101010101010101010101010101010101010101010101010101010101" + } +] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/test.storage_domains.toml new file mode 100644 index 00000000000..24be96bbf31 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_access_contract/test.storage_domains.toml @@ -0,0 +1 @@ +experimental = { storage_domains = true } \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_abi_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_abi_oracle.storage_domains.json new file mode 100644 index 00000000000..32bd4e374ca --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_abi_oracle.storage_domains.json @@ -0,0 +1,31 @@ +{ + "concreteTypes": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "type": "u64" + } + ], + "configurables": [], + "encodingVersion": "1", + "functions": [ + { + "attributes": [ + { + "arguments": [ + "read", + "write" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "read_write_enums", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "loggedTypes": [], + "messagesTypes": [], + "metadataTypes": [], + "programType": "contract", + "specVersion": "1" +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json index f2d1ca396cb..569da2a8bea 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.json @@ -1,62 +1,62 @@ [ { - "key": "12f9e955b5b2b5a00c0ebd1320f2cbd0e66c39396b3b3d7ff95c87f4b6e48c0d", - "value": "000000000000000000000000000000cd00000000000000000000000000000000" + "key": "07692c5e306e34754c8507b83507787cd816e26e21a73f984267468c6a858c5f", + "value": "00000000000000000000000000000000000000000000000000000000000000ee" }, { - "key": "23e09d7a09a27d7d9c5c9d0f5191084c19a0a668c60b804a94e99234e6069c7b", + "key": "093917a687c53cb2abc027cec98a5bbf66c8ae7f5cd58a0880fc9c79617ce148", "value": "0000000000000001000000000000aa00000000000000bb00000000000000cc00" }, { - "key": "2e7251f5b28dbe052a7f5113d45f3cc2faccf7c955cbc0966089aa0d0059beab", - "value": "0000000000000001000000000000ab00000000000000bc00000000000000cd00" + "key": "1381e00cddf07f6fb1d14cdcb956f38a498a20369226d4528826287fd98e6d33", + "value": "0000000000000000000000000000000100000000000000000000000000000000" }, { - "key": "2e7251f5b28dbe052a7f5113d45f3cc2faccf7c955cbc0966089aa0d0059beac", - "value": "000000000000de00000000000000ef0000000000000000000000000000000000" + "key": "163670615ae62a8f957b50ab4ce2c32b22427e70577a54b971439c44f1c4f6ac", + "value": "0000000000000001000000000000bb0000000000000000000000000000000000" }, { - "key": "2f02e964cd75fddf505a740d9daa11fef5f09b4d17058f893fc0f4e8b2244f53", - "value": "0000000000000000000000000000000100000000000000000000000000000000" + "key": "306d92806670cbeca4a1dcd450149e8aac249b1446ab7a4360b511de83dc031c", + "value": "0000000000000001000000000000ab00000000000000bc00000000000000cd00" }, { - "key": "50010301032c3383ef066fbb9ac7c25e3de42bdd5ccaec2d6e0bd26b6531bb0f", - "value": "0000000000000000000000000000000100000000000000000000000000000000" + "key": "306d92806670cbeca4a1dcd450149e8aac249b1446ab7a4360b511de83dc031d", + "value": "000000000000de00000000000000ef0000000000000000000000000000000000" }, { - "key": "6b765908aa8ec7bc3a1d73cd252e40fb055de29fb0e9486a16e388cba9fa7c9f", - "value": "00000000000000000000000000000000000000000000000000000000000000ee" + "key": "919b268af8b1d0e73ebd666050f0d8ca91c4a57c1f07de173500c1204f12b4b5", + "value": "0000000000000002000000000000000000000000000000000000000000000000" }, { - "key": "728df923e281e7cb9793c2c2d6419b735161b5e1b8d5ca2065569611418fc194", - "value": "000000000000000100000000000000cd00000000000000000000000000000000" + "key": "b1852fd03d24006ecb20b244b4a807a5cc1901e1615b4c2cf38ad968da5778a3", + "value": "0000000000000002000000000000000000000000000000000000000000000000" }, { - "key": "7ddacb90e6ff09ed9aa4fde095854476123392aab8c73165cc65097b0a2a2578", - "value": "0000000000000000000000000000000000000000000000000000000000000000" + "key": "b791faa009af5f959cb5b1e527897b5445b819ad012dbcdb4e6747fc67a74abf", + "value": "000000000000000000000000000000ab00000000000000000000000000000000" }, { - "key": "7ddacb90e6ff09ed9aa4fde095854476123392aab8c73165cc65097b0a2a2579", - "value": "000000000000000000000000000000ff00000000000000000000000000000000" + "key": "ca79befa366adbeb06bd973bbb1c4edf732df97bfec0caf094cf9f83fee6dead", + "value": "0000000000000000000000000000000100000000000000000000000000000000" }, { - "key": "c20357da738934c36211a22c69d4c44bc7a3b500b07d9e7328c3f0a7c2c426c0", - "value": "0000000000000002000000000000000000000000000000000000000000000000" + "key": "d44c3a30232bc40cbe5f573493a6951cd072404880b4dde75e10903d0b0a5256", + "value": "000000000000000000000000000000aa00000000000000000000000000000000" }, { - "key": "d60810fb854958d678015228bfbd5a23a3e1763c1ff90f6790f69fbb85b413c6", - "value": "000000000000000000000000000000ab00000000000000000000000000000000" + "key": "e487c22c16cab65d2a63a26de30fd41df1586b5abbad6746cacdf958aa539d49", + "value": "000000000000000000000000000000cd00000000000000000000000000000000" }, { - "key": "d71ff2e9ac87ec91301ee89d18b1dc8991b79753f004ce0810661bd5bfa92bd2", - "value": "0000000000000001000000000000bb0000000000000000000000000000000000" + "key": "fb07f807a63ddfd1422b1cba4ed39940c50eade2002542e1faccea5c64d5b087", + "value": "000000000000000100000000000000cd00000000000000000000000000000000" }, { - "key": "d9149ae8e217ec10a045c9f83c5bc9d227285fe76b9bcdc8245e6a57a23d0229", - "value": "000000000000000000000000000000aa00000000000000000000000000000000" + "key": "fdfd23cb7462d11986f91b4f130b7ddb400b7bbc388ad6754175d93c2b00bd25", + "value": "0000000000000000000000000000000000000000000000000000000000000000" }, { - "key": "e7af73ebbf0ab36c9e30283a504e1326febe010a1b2d0deae9252af8302526a1", - "value": "0000000000000002000000000000000000000000000000000000000000000000" + "key": "fdfd23cb7462d11986f91b4f130b7ddb400b7bbc388ad6754175d93c2b00bd26", + "value": "000000000000000000000000000000ff00000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.storage_domains.json new file mode 100644 index 00000000000..f2d1ca396cb --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/json_storage_slots_oracle.storage_domains.json @@ -0,0 +1,62 @@ +[ + { + "key": "12f9e955b5b2b5a00c0ebd1320f2cbd0e66c39396b3b3d7ff95c87f4b6e48c0d", + "value": "000000000000000000000000000000cd00000000000000000000000000000000" + }, + { + "key": "23e09d7a09a27d7d9c5c9d0f5191084c19a0a668c60b804a94e99234e6069c7b", + "value": "0000000000000001000000000000aa00000000000000bb00000000000000cc00" + }, + { + "key": "2e7251f5b28dbe052a7f5113d45f3cc2faccf7c955cbc0966089aa0d0059beab", + "value": "0000000000000001000000000000ab00000000000000bc00000000000000cd00" + }, + { + "key": "2e7251f5b28dbe052a7f5113d45f3cc2faccf7c955cbc0966089aa0d0059beac", + "value": "000000000000de00000000000000ef0000000000000000000000000000000000" + }, + { + "key": "2f02e964cd75fddf505a740d9daa11fef5f09b4d17058f893fc0f4e8b2244f53", + "value": "0000000000000000000000000000000100000000000000000000000000000000" + }, + { + "key": "50010301032c3383ef066fbb9ac7c25e3de42bdd5ccaec2d6e0bd26b6531bb0f", + "value": "0000000000000000000000000000000100000000000000000000000000000000" + }, + { + "key": "6b765908aa8ec7bc3a1d73cd252e40fb055de29fb0e9486a16e388cba9fa7c9f", + "value": "00000000000000000000000000000000000000000000000000000000000000ee" + }, + { + "key": "728df923e281e7cb9793c2c2d6419b735161b5e1b8d5ca2065569611418fc194", + "value": "000000000000000100000000000000cd00000000000000000000000000000000" + }, + { + "key": "7ddacb90e6ff09ed9aa4fde095854476123392aab8c73165cc65097b0a2a2578", + "value": "0000000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "7ddacb90e6ff09ed9aa4fde095854476123392aab8c73165cc65097b0a2a2579", + "value": "000000000000000000000000000000ff00000000000000000000000000000000" + }, + { + "key": "c20357da738934c36211a22c69d4c44bc7a3b500b07d9e7328c3f0a7c2c426c0", + "value": "0000000000000002000000000000000000000000000000000000000000000000" + }, + { + "key": "d60810fb854958d678015228bfbd5a23a3e1763c1ff90f6790f69fbb85b413c6", + "value": "000000000000000000000000000000ab00000000000000000000000000000000" + }, + { + "key": "d71ff2e9ac87ec91301ee89d18b1dc8991b79753f004ce0810661bd5bfa92bd2", + "value": "0000000000000001000000000000bb0000000000000000000000000000000000" + }, + { + "key": "d9149ae8e217ec10a045c9f83c5bc9d227285fe76b9bcdc8245e6a57a23d0229", + "value": "000000000000000000000000000000aa00000000000000000000000000000000" + }, + { + "key": "e7af73ebbf0ab36c9e30283a504e1326febe010a1b2d0deae9252af8302526a1", + "value": "0000000000000002000000000000000000000000000000000000000000000000" + } +] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/test.storage_domains.toml new file mode 100644 index 00000000000..24be96bbf31 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_enum_contract/test.storage_domains.toml @@ -0,0 +1 @@ +experimental = { storage_domains = true } \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.storage_domains.json new file mode 100644 index 00000000000..a7b039e5eeb --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_abi_oracle.storage_domains.json @@ -0,0 +1,289 @@ +{ + "concreteTypes": [ + { + "concreteTypeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d", + "type": "()" + }, + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "type": "b256" + }, + { + "concreteTypeId": "d852149004cc9ec0bbe7dc4e37bffea1d41469b759512b6136f2e865a4c06e7d", + "metadataTypeId": 0, + "type": "enum std::option::Option", + "typeArguments": [ + "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + ] + }, + { + "concreteTypeId": "6906df92e2e485dde893b7d719d621b8910422e7c468f99caa5920e6ac19d9c6", + "metadataTypeId": 3, + "type": "struct basic_storage_abi::Quad" + }, + { + "concreteTypeId": "7880d311d30802b48bd6a100a31adb5af17f94bff12daee556d4f02c1ac5b2ff", + "metadataTypeId": 5, + "type": "struct std::vec::Vec", + "typeArguments": [ + "6906df92e2e485dde893b7d719d621b8910422e7c468f99caa5920e6ac19d9c6" + ] + }, + { + "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", + "type": "u256" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "type": "u64" + } + ], + "configurables": [], + "encodingVersion": "1", + "functions": [ + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "storage_key" + } + ], + "name": "get_u64", + "output": "d852149004cc9ec0bbe7dc4e37bffea1d41469b759512b6136f2e865a4c06e7d" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "slots" + } + ], + "name": "intrinsic_load_quad", + "output": "7880d311d30802b48bd6a100a31adb5af17f94bff12daee556d4f02c1ac5b2ff" + }, + { + "attributes": [ + { + "arguments": [ + "read" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + } + ], + "name": "intrinsic_load_word", + "output": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "7880d311d30802b48bd6a100a31adb5af17f94bff12daee556d4f02c1ac5b2ff", + "name": "values" + } + ], + "name": "intrinsic_store_quad", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "value" + } + ], + "name": "intrinsic_store_word", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "write" + ], + "name": "storage" + } + ], + "inputs": [ + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "name": "key" + }, + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "name": "value" + } + ], + "name": "store_u64", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "attributes": [ + { + "arguments": [ + "read", + "write" + ], + "name": "storage" + } + ], + "inputs": [], + "name": "test_storage_exhaustive", + "output": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + } + ], + "loggedTypes": [ + { + "concreteTypeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0", + "logId": "1515152261580153489" + }, + { + "concreteTypeId": "1b5759d94094368cfd443019e7ca5ec4074300e544e5ea993a979f5da627261e", + "logId": "1970142151624111756" + }, + { + "concreteTypeId": "7c5ee1cecf5f8eacd1284feb5f0bf2bdea533a51e2f0c9aabe9236d335989f3b", + "logId": "8961848586872524460" + } + ], + "messagesTypes": [], + "metadataTypes": [ + { + "components": [ + { + "name": "None", + "typeId": "2e38e77b22c314a449e91fafed92a43826ac6aa403ae6a8acb6cf58239fbaf5d" + }, + { + "name": "Some", + "typeId": 1 + } + ], + "metadataTypeId": 0, + "type": "enum std::option::Option", + "typeParameters": [ + 1 + ] + }, + { + "metadataTypeId": 1, + "type": "generic T" + }, + { + "metadataTypeId": 2, + "type": "raw untyped ptr" + }, + { + "components": [ + { + "name": "v1", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "v2", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "v3", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + }, + { + "name": "v4", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "metadataTypeId": 3, + "type": "struct basic_storage_abi::Quad" + }, + { + "components": [ + { + "name": "ptr", + "typeId": 2 + }, + { + "name": "cap", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "metadataTypeId": 4, + "type": "struct std::vec::RawVec", + "typeParameters": [ + 1 + ] + }, + { + "components": [ + { + "name": "buf", + "typeArguments": [ + { + "name": "", + "typeId": 1 + } + ], + "typeId": 4 + }, + { + "name": "len", + "typeId": "1506e6f44c1d6291cdf46395a8e573276a4fa79e8ace3fc891e092ef32d1b0a0" + } + ], + "metadataTypeId": 5, + "type": "struct std::vec::Vec", + "typeParameters": [ + 1 + ] + } + ], + "programType": "contract", + "specVersion": "1" +} \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json index 30e9e240f7c..0b71f7ba584 100644 --- a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.json @@ -1,54 +1,54 @@ [ { - "key": "130875c838ab7f4f039a63d56d8173198d6edade9a61967c93b9d32d93547979", - "value": "6161000000000000000000000000000000000000000000000000000000000000" + "key": "156750d12322b9d55699e5f250927c45dbc5a716ed514e5d5c6e001c72743958", + "value": "6161616161616161610000000000000000000000000000000000000000000000" }, { - "key": "1997c0b14a3944421bc909d65cdb7f96023661790725e7a06d0bdf211002f9c0", - "value": "6161610000000000000000000000000000000000000000000000000000000000" + "key": "1900d3c5816770f72962fcc1c2903deaef383aad2245f8dce3ea438edb50d5be", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "1cb08489095e2318cabf34c2c00b0f2b78c151bf4e3caf2a1762778c1b79c052", - "value": "0000000000000001000000000000000000000000000000000000000000000000" + "key": "316435c84dec635a59eafe5c7bbe948529d9b334642e3042790ccc24a48d020f", + "value": "6161610000000000000000000000000000000000000000000000000000000000" }, { - "key": "35338f6734c20524ba70780eae61e4dc5398122eab4a3cad9509a3d3ddc1551b", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "75c8aa025fcadccc0595011724f38d1c4502877ab67e96c2d5ac4e28c7c067d2", + "value": "6161616161000000000000000000000000000000000000000000000000000000" }, { - "key": "55279c57558d3bb1938f803552769ed7dcb3efacd74d9a16cf71d0cfbaab6c0a", + "key": "8d03529726cb560c58c7c256daa265105ab1657cc58f285a4e450ade5e3b99b9", "value": "6161616161616161616100000000000000000000000000000000000000000000" }, { - "key": "5d5895256cdf173ecc135c1a18de5133b00b36e5caae538407a883dd44cc0dac", - "value": "0000000000000000000000000000000000000000000000000000000001234567" + "key": "8e2eedb0198112b5758b3ca68ff81ccf74f35bde89f59324c6349834b7446d42", + "value": "6161616161610000000000000000000000000000000000000000000000000000" }, { - "key": "5dbeb0e7fc4c2fa3b01b9873d2a4e23488fb486046b6074b4ae463b7bbacbe89", - "value": "6161616161000000000000000000000000000000000000000000000000000000" + "key": "96f53fe759d3f6112e66216565e101a4e3ad50e0b67047a2b1bc71f58e838b3b", + "value": "6161000000000000000000000000000000000000000000000000000000000000" }, { - "key": "659790a8d5d87a599ab69d1a3e6f48ff00c850fb7d24ccd782b209a52e4be83c", - "value": "6161616161616100000000000000000000000000000000000000000000000000" + "key": "9cd3727531d07180cf222a86ab51e4d6933e82ffa5a846a51ee7554929eec408", + "value": "0000000000000001000000000000000000000000000000000000000000000000" }, { - "key": "7aac1eb5fdc9d977b39721c2ccddb3ae405eecac0d8570e3be2d70fe677db4bd", - "value": "6161616161616161610000000000000000000000000000000000000000000000" + "key": "b48939b669452acd21e7e052008441cf16898ebecad0cf50ea5d1022cc91683d", + "value": "6161616161616100000000000000000000000000000000000000000000000000" }, { - "key": "8449d22802f944884dd98b791627c4265f4303014d1975f3da48fde003d77936", - "value": "6161616161616161000000000000000000000000000000000000000000000000" + "key": "c2cec376bf7389162e8706fbb83f4c7d322150bbae540c4d7a89711e86a54d0b", + "value": "6161616100000000000000000000000000000000000000000000000000000000" }, { - "key": "c2f546e9b4a2a37895f7f563be4610aa580468ddd8ba5d3544513965d79eac8a", - "value": "6100000000000000000000000000000000000000000000000000000000000000" + "key": "c47aaa0a4460ad82387b70843b35804e6526ec4a4094793064abda38e789d70b", + "value": "0000000000000000000000000000000000000000000000000000000001234567" }, { - "key": "e1ba0adcc27d3a21cfe72cc296e282f1c4b9f6798f89ac4e4b8ac95e3ee16d81", - "value": "6161616161610000000000000000000000000000000000000000000000000000" + "key": "dbaf1317f4011ad87979853011781f2088cdd8422250f19f27a90b5ce8037cac", + "value": "6161616161616161000000000000000000000000000000000000000000000000" }, { - "key": "fdcf008347ae968111d6837c46f05f1a9943e76f6998d51ee1220b4069709a51", - "value": "6161616100000000000000000000000000000000000000000000000000000000" + "key": "f665e43dbe17620f6ef1e4beb22f9d4f1e2bb711e20c003a09dad812801f59e0", + "value": "6100000000000000000000000000000000000000000000000000000000000000" } ] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.storage_domains.json b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.storage_domains.json new file mode 100644 index 00000000000..30e9e240f7c --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/json_storage_slots_oracle.storage_domains.json @@ -0,0 +1,54 @@ +[ + { + "key": "130875c838ab7f4f039a63d56d8173198d6edade9a61967c93b9d32d93547979", + "value": "6161000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "1997c0b14a3944421bc909d65cdb7f96023661790725e7a06d0bdf211002f9c0", + "value": "6161610000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "1cb08489095e2318cabf34c2c00b0f2b78c151bf4e3caf2a1762778c1b79c052", + "value": "0000000000000001000000000000000000000000000000000000000000000000" + }, + { + "key": "35338f6734c20524ba70780eae61e4dc5398122eab4a3cad9509a3d3ddc1551b", + "value": "0000000000000000000000000000000000000000000000000000000001234567" + }, + { + "key": "55279c57558d3bb1938f803552769ed7dcb3efacd74d9a16cf71d0cfbaab6c0a", + "value": "6161616161616161616100000000000000000000000000000000000000000000" + }, + { + "key": "5d5895256cdf173ecc135c1a18de5133b00b36e5caae538407a883dd44cc0dac", + "value": "0000000000000000000000000000000000000000000000000000000001234567" + }, + { + "key": "5dbeb0e7fc4c2fa3b01b9873d2a4e23488fb486046b6074b4ae463b7bbacbe89", + "value": "6161616161000000000000000000000000000000000000000000000000000000" + }, + { + "key": "659790a8d5d87a599ab69d1a3e6f48ff00c850fb7d24ccd782b209a52e4be83c", + "value": "6161616161616100000000000000000000000000000000000000000000000000" + }, + { + "key": "7aac1eb5fdc9d977b39721c2ccddb3ae405eecac0d8570e3be2d70fe677db4bd", + "value": "6161616161616161610000000000000000000000000000000000000000000000" + }, + { + "key": "8449d22802f944884dd98b791627c4265f4303014d1975f3da48fde003d77936", + "value": "6161616161616161000000000000000000000000000000000000000000000000" + }, + { + "key": "c2f546e9b4a2a37895f7f563be4610aa580468ddd8ba5d3544513965d79eac8a", + "value": "6100000000000000000000000000000000000000000000000000000000000000" + }, + { + "key": "e1ba0adcc27d3a21cfe72cc296e282f1c4b9f6798f89ac4e4b8ac95e3ee16d81", + "value": "6161616161610000000000000000000000000000000000000000000000000000" + }, + { + "key": "fdcf008347ae968111d6837c46f05f1a9943e76f6998d51ee1220b4069709a51", + "value": "6161616100000000000000000000000000000000000000000000000000000000" + } +] \ No newline at end of file diff --git a/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.storage_domains.toml b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.storage_domains.toml new file mode 100644 index 00000000000..24be96bbf31 --- /dev/null +++ b/test/src/e2e_vm_tests/test_programs/should_pass/test_contracts/storage_namespace/test.storage_domains.toml @@ -0,0 +1 @@ +experimental = { storage_domains = true } \ No newline at end of file diff --git a/test/src/ir_generation/mod.rs b/test/src/ir_generation/mod.rs index 8313845fe39..6969ef1c689 100644 --- a/test/src/ir_generation/mod.rs +++ b/test/src/ir_generation/mod.rs @@ -223,7 +223,9 @@ pub(super) async fn run( tracing::info!("Testing {} ...", test_file_name.bold()); let experimental = ExperimentalFeatures { - new_encoding: false, // IR tests still need encoding v1 off + new_encoding: false, // IR tests still need encoding v1 off. + // TODO: Properly support experimental features in IR tests. + ..Default::default() }; // Compile to AST. We need to provide a faux build config otherwise the IR will have From fe2965a5cb499c147f45089030b323297ffbc54a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 17:03:21 +0100 Subject: [PATCH 3/8] Fix failing `require_contract_deployment` tests --- sway-core/src/language/ty/declaration/storage.rs | 2 +- .../require_contract_deployment/call_basic_storage/src/main.sw | 2 +- .../require_contract_deployment/call_storage_enum/src/main.sw | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/sway-core/src/language/ty/declaration/storage.rs b/sway-core/src/language/ty/declaration/storage.rs index abda5ed1e84..3fca567d618 100644 --- a/sway-core/src/language/ty/declaration/storage.rs +++ b/sway-core/src/language/ty/declaration/storage.rs @@ -9,7 +9,7 @@ use sway_types::{Ident, Named, Span, Spanned}; use crate::{ engine_threading::*, ir_generation::storage::get_storage_key_string, - language::{parsed::StorageDeclaration, ty::*, Visibility}, + language::parsed::StorageDeclaration, ty::*, transform::{self}, type_system::*, Namespace, 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 3e775aa38ad..d7218234e92 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 = 0x918deef6932aa65b243a70e1abddc4fa07964038270f137e1759f797dcbc9422; // AUTO-CONTRACT-ID ../../test_contracts/basic_storage --release +const CONTRACT_ID = 0x27857d650234acd05b5fa9a9bc34abf76fa66d2e6ce8c8b24416805b75005bd0; // 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_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 02b20a7db63..06673118a96 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 = 0x3eb4e52446444c5b4450aa5b88f68e971aef07d4a0f62147810f5a0fa0e763cf; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release +const CONTRACT_ID = 0x47084a8c1eb453b655842e1b3067ee1f0d9081052bd74ac606efa6ae9a56d901; // AUTO-CONTRACT-ID ../../test_contracts/storage_enum_contract --release fn main() -> u64 { let caller = abi(StorageEnum, CONTRACT_ID); From 8c7ad2febbca5baa0152cd201bcca9bdae4a656e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 17:04:59 +0100 Subject: [PATCH 4/8] Fix fmt issues --- sway-core/src/ir_generation/function.rs | 11 +++++- sway-core/src/ir_generation/storage.rs | 11 +++++- .../src/language/ty/declaration/storage.rs | 3 +- .../ast_node/declaration/storage.rs | 4 +- test/src/e2e_vm_tests/harness.rs | 38 ++++++++++++------- test/src/e2e_vm_tests/mod.rs | 24 +++++++++--- 6 files changed, 66 insertions(+), 25 deletions(-) diff --git a/sway-core/src/ir_generation/function.rs b/sway-core/src/ir_generation/function.rs index 7fc7289ff86..31996221796 100644 --- a/sway-core/src/ir_generation/function.rs +++ b/sway-core/src/ir_generation/function.rs @@ -4268,7 +4268,11 @@ impl<'eng> FnCompiler<'eng> { ) -> Result { // Use the `struct_field_names` to get a field id that is unique even for zero-sized values that live in the same slot. // We calculate the `unique_field_id` early, here, before the `storage_filed_names` get consumed by `get_storage_key` below. - let unique_field_id = get_storage_field_id(&storage_field_names, &struct_field_names, context.experimental); + let unique_field_id = get_storage_field_id( + &storage_field_names, + &struct_field_names, + context.experimental, + ); // Get the actual storage key as a `Bytes32` as well as the offset, in words, // within the slot. The offset depends on what field of the top level storage @@ -4302,7 +4306,10 @@ impl<'eng> FnCompiler<'eng> { // plus the offset, in number of slots, computed above. The offset within this // particular slot is the remaining offset, in words. ( - add_to_b256(get_storage_key(storage_field_names, key, context.experimental), offset_in_slots), + add_to_b256( + get_storage_key(storage_field_names, key, context.experimental), + offset_in_slots, + ), offset_remaining, ) }; diff --git a/sway-core/src/ir_generation/storage.rs b/sway-core/src/ir_generation/storage.rs index a069bfd406c..4f42a74a2e8 100644 --- a/sway-core/src/ir_generation/storage.rs +++ b/sway-core/src/ir_generation/storage.rs @@ -23,7 +23,11 @@ enum InByte8Padding { /// Hands out storage keys using storage field names or an existing key. /// Basically returns sha256((0u8, "storage::::.")) /// or key if defined. -pub(super) fn get_storage_key(storage_field_names: Vec, key: Option, experimental: ExperimentalFeatures) -> Bytes32 { +pub(super) fn get_storage_key( + storage_field_names: Vec, + key: Option, + experimental: ExperimentalFeatures, +) -> Bytes32 { match key { Some(key) => key.to_be_bytes().into(), None => hash_storage_key_string(get_storage_key_string(&storage_field_names), experimental), @@ -79,7 +83,10 @@ pub(super) fn get_storage_field_id( hash_storage_key_string(data, experimental) } -fn hash_storage_key_string(storage_key_string: String, experimental: ExperimentalFeatures) -> Bytes32 { +fn hash_storage_key_string( + storage_key_string: String, + experimental: ExperimentalFeatures, +) -> Bytes32 { let mut hasher = Hasher::default(); // Certain storage types, like, e.g., `StorageMap` allow // storage slots of their contained elements to be defined diff --git a/sway-core/src/language/ty/declaration/storage.rs b/sway-core/src/language/ty/declaration/storage.rs index 3fca567d618..abc5a67b20c 100644 --- a/sway-core/src/language/ty/declaration/storage.rs +++ b/sway-core/src/language/ty/declaration/storage.rs @@ -9,8 +9,9 @@ use sway_types::{Ident, Named, Span, Spanned}; use crate::{ engine_threading::*, ir_generation::storage::get_storage_key_string, - language::parsed::StorageDeclaration, ty::*, + language::parsed::StorageDeclaration, transform::{self}, + ty::*, type_system::*, Namespace, }; diff --git a/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs b/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs index 63c971487f8..7df2bb722d4 100644 --- a/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs +++ b/sway-core/src/semantic_analysis/ast_node/declaration/storage.rs @@ -71,7 +71,9 @@ impl ty::TyStorageDecl { .key_expression .is_none(), key: format!("0x{:x}", s.key()), - experimental_storage_domains: context.experimental.storage_domains, + experimental_storage_domains: context + .experimental + .storage_domains, }, }) } diff --git a/test/src/e2e_vm_tests/harness.rs b/test/src/e2e_vm_tests/harness.rs index 7ed8ab0353d..31dbcda4b48 100644 --- a/test/src/e2e_vm_tests/harness.rs +++ b/test/src/e2e_vm_tests/harness.rs @@ -398,17 +398,24 @@ pub(crate) fn test_json_abi( } if fs::metadata(oracle_path.clone()).is_err() { - bail!("JSON ABI oracle file does not exist for this test\nExpected oracle path: {}", &oracle_path); + bail!( + "JSON ABI oracle file does not exist for this test\nExpected oracle path: {}", + &oracle_path + ); } if fs::metadata(output_path.clone()).is_err() { - bail!("JSON ABI output file does not exist for this test\nExpected output path: {}", &output_path); + bail!( + "JSON ABI output file does not exist for this test\nExpected output path: {}", + &output_path + ); } - let oracle_contents = - fs::read_to_string(&oracle_path).expect("Something went wrong reading the JSON ABI oracle file."); - let output_contents = - fs::read_to_string(&output_path).expect("Something went wrong reading the JSON ABI output file."); + let oracle_contents = fs::read_to_string(&oracle_path) + .expect("Something went wrong reading the JSON ABI oracle file."); + let output_contents = fs::read_to_string(&output_path) + .expect("Something went wrong reading the JSON ABI output file."); if oracle_contents != output_contents { - bail!("Mismatched ABI JSON output.\nOracle path: {}\nOutput path: {}\n{}", + bail!( + "Mismatched ABI JSON output.\nOracle path: {}\nOutput path: {}\n{}", oracle_path, output_path, prettydiff::diff_lines(&oracle_contents, &output_contents) @@ -434,7 +441,11 @@ fn emit_json_abi(file_name: &str, built_package: &BuiltPackage) -> Result<()> { Ok(()) } -pub(crate) fn test_json_storage_slots(file_name: &str, built_package: &BuiltPackage, suffix: &Option,) -> Result<()> { +pub(crate) fn test_json_storage_slots( + file_name: &str, + built_package: &BuiltPackage, + suffix: &Option, +) -> Result<()> { emit_json_storage_slots(file_name, built_package)?; let manifest_dir = env!("CARGO_MANIFEST_DIR"); let oracle_path = format!( @@ -460,12 +471,13 @@ pub(crate) fn test_json_storage_slots(file_name: &str, built_package: &BuiltPack if fs::metadata(output_path.clone()).is_err() { bail!("JSON storage slots output file does not exist for this test.\nExpected output path: {}", &output_path); } - let oracle_contents = - fs::read_to_string(oracle_path.clone()).expect("Something went wrong reading the JSON storage slots oracle file."); - let output_contents = - fs::read_to_string(output_path.clone()).expect("Something went wrong reading the JSON storage slots output file."); + let oracle_contents = fs::read_to_string(oracle_path.clone()) + .expect("Something went wrong reading the JSON storage slots oracle file."); + let output_contents = fs::read_to_string(output_path.clone()) + .expect("Something went wrong reading the JSON storage slots output file."); if oracle_contents != output_contents { - bail!("Mismatched storage slots JSON output.\nOracle path: {}\nOutput path: {}\n{}", + bail!( + "Mismatched storage slots JSON output.\nOracle path: {}\nOutput path: {}\n{}", oracle_path, output_path, prettydiff::diff_lines(&oracle_contents, &output_contents) diff --git a/test/src/e2e_vm_tests/mod.rs b/test/src/e2e_vm_tests/mod.rs index 6fc6ff8ae04..725056b9ac7 100644 --- a/test/src/e2e_vm_tests/mod.rs +++ b/test/src/e2e_vm_tests/mod.rs @@ -602,9 +602,15 @@ impl TestContext { ))); } } - TestResult::ReturnData(_) => todo!("Test result `ReturnData` is currently not implemented."), - TestResult::Return(_) => todo!("Test result `Return` is currently not implemented."), - TestResult::Revert(_) => todo!("Test result `Revert` is currently not implemented."), + TestResult::ReturnData(_) => { + todo!("Test result `ReturnData` is currently not implemented.") + } + TestResult::Return(_) => { + todo!("Test result `Return` is currently not implemented.") + } + TestResult::Revert(_) => { + todo!("Test result `Revert` is currently not implemented.") + } }, Receipt::ReturnData { data, .. } => match expected_result.unwrap() { TestResult::ReturnData(v) => { @@ -614,9 +620,15 @@ impl TestContext { ))); } } - TestResult::Result(_) => todo!("Test result `Result` is currently not implemented."), - TestResult::Return(_) => todo!("Test result `Return` is currently not implemented."), - TestResult::Revert(_) => todo!("Test result `Revert` is currently not implemented."), + TestResult::Result(_) => { + todo!("Test result `Result` is currently not implemented.") + } + TestResult::Return(_) => { + todo!("Test result `Return` is currently not implemented.") + } + TestResult::Revert(_) => { + todo!("Test result `Revert` is currently not implemented.") + } }, _ => {} }; From ab74d6311d19e8924407f4400b7b60fa3941eb15 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 17:15:19 +0100 Subject: [PATCH 5/8] Expand `forc-unit-tests` to test with `storage_domains` set on --- .github/workflows/ci.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a6b251402bc..5635f4c7791 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -493,6 +493,12 @@ jobs: run: forc build --path sway-lib-std && forc test --path sway-lib-std - name: Run In Language Unit Tests run: forc build --path test/src/in_language_tests && forc test --path test/src/in_language_tests + - name: Run Core Unit Tests - Experimental feature: storage_domains + run: forc build --path sway-lib-core && forc test --experimental storage_domains --path sway-lib-core + - name: Run Std Unit Tests - Experimental feature: storage_domains + run: forc build --path sway-lib-std && forc test --experimental storage_domains --path sway-lib-std + - name: Run In Language Unit Tests - Experimental feature: storage_domains + run: forc build --path test/src/in_language_tests && forc test --experimental storage_domains --path test/src/in_language_tests forc-pkg-fuels-deps-check: runs-on: buildjet-4vcpu-ubuntu-2204 From d828599743f4fe2259d7650808105bab5a940a43 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 20:33:17 +0100 Subject: [PATCH 6/8] Revert "Expand `forc-unit-tests` to test with `storage_domains` set on" This reverts commit ab74d6311d19e8924407f4400b7b60fa3941eb15. --- .github/workflows/ci.yml | 6 ------ 1 file changed, 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5635f4c7791..a6b251402bc 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -493,12 +493,6 @@ jobs: run: forc build --path sway-lib-std && forc test --path sway-lib-std - name: Run In Language Unit Tests run: forc build --path test/src/in_language_tests && forc test --path test/src/in_language_tests - - name: Run Core Unit Tests - Experimental feature: storage_domains - run: forc build --path sway-lib-core && forc test --experimental storage_domains --path sway-lib-core - - name: Run Std Unit Tests - Experimental feature: storage_domains - run: forc build --path sway-lib-std && forc test --experimental storage_domains --path sway-lib-std - - name: Run In Language Unit Tests - Experimental feature: storage_domains - run: forc build --path test/src/in_language_tests && forc test --experimental storage_domains --path test/src/in_language_tests forc-pkg-fuels-deps-check: runs-on: buildjet-4vcpu-ubuntu-2204 From 840dab099376ca87c4c14fc765d97de7c2423d86 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 20:41:28 +0100 Subject: [PATCH 7/8] Fix failing build --- sway-ir/tests/tests.rs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/sway-ir/tests/tests.rs b/sway-ir/tests/tests.rs index 743b3523977..5e6ccaeaa8f 100644 --- a/sway-ir/tests/tests.rs +++ b/sway-ir/tests/tests.rs @@ -29,6 +29,8 @@ fn run_tests bool>(sub_dir: &str, opt_fn: F) { let experimental = ExperimentalFeatures { new_encoding: false, + // TODO: Properly support experimental features in IR tests. + ..Default::default() }; let mut ir = sway_ir::parser::parse(&input, &source_engine, experimental).unwrap_or_else( From 89b37bc60ac84918f4eb7a8346bc3b649a5e32ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Igor=20Ron=C4=8Devi=C4=87?= Date: Wed, 6 Nov 2024 21:28:43 +0100 Subject: [PATCH 8/8] Update `invalid_cfg_arg` test --- .../test_programs/should_fail/invalid_cfg_arg/stdout.snap | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/src/e2e_vm_tests/test_programs/should_fail/invalid_cfg_arg/stdout.snap b/test/src/e2e_vm_tests/test_programs/should_fail/invalid_cfg_arg/stdout.snap index fee2b903ecd..84c0fa58caf 100644 --- a/test/src/e2e_vm_tests/test_programs/should_fail/invalid_cfg_arg/stdout.snap +++ b/test/src/e2e_vm_tests/test_programs/should_fail/invalid_cfg_arg/stdout.snap @@ -11,7 +11,7 @@ warning | 1 | predicate; 2 | #[cfg(c)] a - | --- Unexpected attribute value: "c" for attribute: "cfg" expected value "target" or "program_type" or "experimental_new_encoding" + | --- Unexpected attribute value: "c" for attribute: "cfg" expected value "target" or "program_type" or "experimental_new_encoding" or "experimental_storage_domains" | ____