Skip to content

Conversation

@igamigo
Copy link
Collaborator

@igamigo igamigo commented Jan 8, 2026

Adds StorageSchema::commitment(), which commits to most StorageSchema fields. Namely, it commits to the type of each slot and the description of such slot (or element of a composite type slot). This commitment disregards ordering in the TOML.
StorageSchema is explicitly associated to a single account component right now (since it's a part of AccountComponentMetadata). A follow-up (#2253) was created to expose a hash of an arbitrary number of these commitments to express the type of a full account.

@igamigo igamigo force-pushed the igamigo-schema-commit branch from d5da574 to b5ea229 Compare January 8, 2026 20:31
@igamigo igamigo force-pushed the igamigo-schema-commit branch from abbe163 to 9aa118c Compare January 9, 2026 21:42
@igamigo igamigo marked this pull request as ready for review January 12, 2026 17:48
@mmagician mmagician requested a review from Copilot January 13, 2026 10:13
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds a StorageSchema::commitment() method that computes a cryptographic commitment to the storage schema definition, excluding default values. The commitment enables schemas with different default values and slot orderings to produce identical commitments as long as their structural definitions match.

Changes:

  • Added StorageSchema::commitment() method that computes a hash of the serialized schema without default values
  • Implemented write_into_with_defaults() helper methods across all schema types to support conditional serialization
  • Added ASCII validation for component and slot descriptions (both in TOML parsing and deserialization)
  • Refactored parse_storage_value_with_schema() for clearer error handling
  • Added comprehensive test coverage for commitment behavior and ASCII validation

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.

Show a summary per file
File Description
crates/miden-protocol/src/account/component/storage/schema.rs Core implementation: added commitment() method, write_into_with_defaults() helpers, ASCII validation function, and refactored parse logic
crates/miden-protocol/src/account/component/storage/toml/mod.rs Added ASCII validation for component descriptions during TOML parsing and updated references from AccountStorageSchema to StorageSchema
crates/miden-protocol/src/account/component/storage/toml/tests.rs Added tests for ASCII validation and commitment behavior demonstrating that commitments ignore defaults and ordering
crates/miden-protocol/src/account/component/storage/init_storage_data.rs Minor reorganization of From implementations and updated documentation
crates/miden-protocol/src/account/component/mod.rs Updated test fixtures to use StorageSchema instead of AccountStorageSchema
crates/miden-protocol/src/account/component/metadata/mod.rs Updated type references and added ASCII validation during deserialization
CHANGELOG.md Added entry documenting the new StorageSchema::commitment() method

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

use core::error::Error;

use miden_core::{Felt, FieldElement, Word};
use miden_air::FieldElement;
Copy link

Copilot AI Jan 13, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The import FieldElement from miden_air is unused. Consider removing this import to reduce clutter.

Suggested change
use miden_air::FieldElement;

Copilot uses AI. Check for mistakes.
Copy link
Contributor

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good - I would see whether the serialization without defaults can be simplified, as per my comment below (if so, this will propagate into other uses of write_into_*)

Copy link
Contributor

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As described in #2104, the idea was to include the schema metadata, like user-provided names & descriptions, as part of the commitment computation, which AFAICS are not included right now.

@igamigo igamigo changed the title feat: AccountStorageSchema::commitment feat: StorageSchema::commitment Jan 13, 2026
@igamigo
Copy link
Collaborator Author

igamigo commented Jan 13, 2026

As described in #2104, the idea was to include the schema metadata, like user-provided names & descriptions, as part of the commitment computation, which AFAICS are not included right now.

User-provided names and descriptions are both committed to. Added a small test that verifies this. Or did you mean the component's metadata?

@mmagician
Copy link
Contributor

User-provided names and descriptions are both committed to.

Perfect, that's what I meant 👍🏼 I think I got lost in the nested write_into_*s, thanks for the test also.

Copy link
Contributor

@mmagician mmagician left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall LGTM, great work!
I would want to think through the consumers of StorageSchema::commitment to see how easy it would be for them to replicate this computation.

Copy link
Contributor

@bobbinth bobbinth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good! Thank you! Not a super detailed review from my end, but I left one question inline.

Base automatically changed from igamigo-init-refactor to next January 16, 2026 17:46
@bobbinth
Copy link
Contributor

Now that #2230 is merged, @igamigo - could you bring this branch up to date?

@igamigo
Copy link
Collaborator Author

igamigo commented Jan 16, 2026

Now that #2230 is merged, @igamigo - could you bring this branch up to date?

Done! Merging once the CI passes

@igamigo igamigo merged commit 27c2a99 into next Jan 16, 2026
17 checks passed
@igamigo igamigo deleted the igamigo-schema-commit branch January 16, 2026 18:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants