Giter Site home page Giter Site logo

Comments (3)

Dominik1999 avatar Dominik1999 commented on July 29, 2024

I am starting this issue today.

I am not sure I understood 100% why this refactoring is needed. In my understanding, for every change in a StorageMap there is always a change, i.e. the root of the map in a StorageSlot.

This is what the MASM code in api.masm does.

# set the new map item
loc_load.0 exec.account::set_map_item swapw
# => [NEW_MAP_ROOT, OLD_MAP_VALUE, ...]
# set the root of the map in the respective account storage slot
loc_load.0 exec.account::set_item
# => [OLD_MAP_ROOT, OLD_MAP_VALUE, ...]

That means we have two updated entities, AccountStorageDelta.updated_items and AccountStorageDelta.updated_maps, because updated_items tracks changes in StorageSlots, and updated_maps tracks changes in StorageMaps.

Currently, there is also a check that whenever there is a updated_map, there must be a corresponding change in updated_items to ensure consistency.

// make sure storage map deltas are valid
for (index, storage_map_delta) in self.updated_maps.iter() {
if index > &MAX_MUTABLE_STORAGE_SLOT_IDX {
return Err(AccountDeltaError::ImmutableStorageSlot(*index as usize));
}
// for every storage map delta there should be one corresponding storage item update
if !self.updated_items.iter().any(|(idx, _)| idx == index) {
return Err(AccountDeltaError::StorageMapDeltaWithoutStorageItemChange(
*index as usize,
));
}
if !storage_map_delta.is_empty() {
storage_map_delta.validate()?;
}

It could be implemented differently, without question, but I don't know what the reason behind it is.

from miden-base.

bobbinth avatar bobbinth commented on July 29, 2024

The main reasons is that having both storage map updates and storage slot updates (for slots which contain storage maps) is redundant. This means:

  • The deltas are slightly bigger (this is very minor).
  • It is possible to encode data in the delta inconsistently (e.g., storage slot updates would indicate one root for a storage map, while corresponding storage map updates would result in a different root). It is possible to deal with this, but that means extra code in various places (e.g., during application of the delta, during deserialization of the delta etc.).

from miden-base.

bobbinth avatar bobbinth commented on July 29, 2024

Closed by #758.

from miden-base.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.