# Storage slot hash calculation

**URL:** <https://forum.fuel.network/t/storage-slot-hash-calculation/6549>\
**Category:** Sway\
**Created:** [August 31, 2024, 7:56am UTC](https://forum.fuel.network/t/storage-slot-hash-calculation/6549 "2024-08-31T07:56:25Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jecikpo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/jecikpo/32/3440_2.png) [@jecikpo](https://forum.fuel.network/u/jecikpo)\
**Post date:** [August 31, 2024, 7:56am UTC](https://forum.fuel.network/t/storage-slot-hash-calculation/6549/1 "2024-08-31T07:56:26Z")

</div>

The storage slots for each storage variable that is defined in `storage` block, was created by hashing the `storage_X` string where X was the integer value starting from 0 based on the order of the variable in the storage block.

I noticed that after upgrading from 0.60.0 to 0.63.1 this is not the case anymore.

I have this simple contract:

```auto
contract;

storage {
    variable: u64 = 0,
}

abi MyContract {
    fn test_function() -> bool;
}

impl MyContract for Contract {
    fn test_function() -> bool {
        true
    }
}

```

and when I compile it the following slots.json gets generated:

```auto
[
  {
    "key": "7cee3037d9b2fdd229ca5800cdd80a341eaac931ca6d9619736c34428a54bf43",
    "value": "0000000000000000000000000000000000000000000000000000000000000000"
  }
]

```

which is not matching the sha256 value I would expect:

```auto
$ echo -n "storage_0" | shasum -a 256 -
f383b0ce51358be57daa3b725fe44acdb2d880604e367199080b4379c41bb6ed -

```

Could someone please provide an explanation how is the slot value calculated now, or provide a link to the relevant source code?

---

<div class="post-metadata">

**Author:** ![jecikpo](https://sea2.discourse-cdn.com/flex022/user_avatar/forum.fuel.network/jecikpo/32/3440_2.png) [@jecikpo](https://forum.fuel.network/u/jecikpo)\
**Post date:** [August 31, 2024, 12:40pm UTC](https://forum.fuel.network/t/storage-slot-hash-calculation/6549/2 "2024-08-31T12:40:55Z")

</div>

Ok, I found the relevant PR here: [Storage name based slots and namespaces. by esdrubal · Pull Request #6064 · FuelLabs/sway · GitHub](https://github.com/FuelLabs/sway/pull/6064)

It is clear how the slot value is computed, but not clear how the `field_id` is. The slot is based on the following string:  
`storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>`

But the `field_id` (as documented in the PR) based on this:  
`storage::<storage_namespace_name1>::<storage_namespace_name2>.<storage_field_name>.<struct_field_name1>.<struct_field_name2>`

It is not clear what the `struct_field_name` is representing here.

When I tried to list both the `slot` and `field_id` of my storage test contract above, they have the same value, which looks like the `struct_field_name` (whatever that is) is an empty string.

I also tried to create a `struct` variable in storage with some fields, but got the same result: slot == field\_id.
