Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix!: fix storage layout export #8880

Merged
merged 7 commits into from
Sep 30, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions noir-projects/aztec-nr/aztec/src/macros/mod.nr
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ comptime fn generate_contract_interface(m: Module) -> Quoted {
let storage_layout_getter = if has_storage_layout {
let storage_layout_name = STORAGE_LAYOUT_NAME.get(m).unwrap();
quote {
pub fn storage_layout() -> StorageLayout {
$storage_layout_name
pub fn storage_layout() -> StorageLayoutFields {
$storage_layout_name.fields
}
}
} else {
Expand Down
13 changes: 10 additions & 3 deletions noir-projects/aztec-nr/aztec/src/macros/storage/mod.nr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::{collections::umap::UHashMap, hash::{BuildHasherDefault, poseidon2::Poseidon2Hasher}};
use std::{collections::umap::UHashMap, hash::{BuildHasherDefault, poseidon2::Poseidon2Hasher}, meta::unquote};

use super::utils::get_serialized_size;
use super::utils::is_note;
Expand Down Expand Up @@ -57,18 +57,25 @@ pub comptime fn storage(s: StructDefinition) -> Quoted {
let module = s.module();
let module_name = module.name();
let storage_layout_name = f"STORAGE_LAYOUT_{module_name}".quoted_contents();
let module_name_str = module_name.as_str_quote();
STORAGE_LAYOUT_NAME.insert(module, storage_layout_name);

quote {
$storage_impl

struct StorageLayout {
struct StorageLayoutFields {
$storage_layout_fields
}

struct StorageLayout<let N: u32> {
contract_name: str<N>,
fields: StorageLayoutFields
}

#[abi(storage)]
global $storage_layout_name = StorageLayout {
$storage_layout_constructors
contract_name: $module_name_str,
fields: StorageLayoutFields { $storage_layout_constructors }
};
}
}
Expand Down
17 changes: 14 additions & 3 deletions yarn-project/types/src/abi/contract_artifact.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import {
type ABIParameter,
type ABIParameterVisibility,
type AbiType,
type BasicValue,
type ContractArtifact,
type ContractNote,
type FieldLayout,
Expand Down Expand Up @@ -217,10 +218,20 @@ function hasKernelFunctionInputs(params: ABIParameter[]): boolean {
* @returns A storage layout for the contract.
*/
function getStorageLayout(input: NoirCompiledContract) {
const storage = input.outputs.globals.storage ? (input.outputs.globals.storage[0] as StructValue) : { fields: [] };
const storageFields = storage.fields as TypedStructFieldValue<StructValue>[];
const storageExports = input.outputs.globals.storage ? (input.outputs.globals.storage as StructValue[]) : [];
const storageForContract = storageExports.find(storageExport => {
Thunkar marked this conversation as resolved.
Show resolved Hide resolved
const contractNameField = storageExport.fields.find(field => field.name === 'contract_name')?.value as BasicValue<
'string',
string
>;
return contractNameField.value === input.name;
});
const storageFields = storageForContract
? ((storageForContract.fields.find(field => field.name == 'fields') as TypedStructFieldValue<StructValue>).value
.fields as TypedStructFieldValue<StructValue>[])
: [];

if (!storageFields) {
if (storageFields.length === 0) {
return {};
}

Expand Down
Loading