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

Slots documentation #315

Merged
merged 18 commits into from
May 31, 2024
Merged

Slots documentation #315

merged 18 commits into from
May 31, 2024

Conversation

aajj999
Copy link
Contributor

@aajj999 aajj999 commented May 27, 2024

  • Added README about Slots library
  • Added documentation of U256 in main README
  • Moved uin256.nr from misc to main part of library
  • Small refactoring to slot_test.nr and fixed wrong order of arguments given to dynamic_array function
  • Moved field_to_bytes32 function from field.nr to bytes32.nr file

vlayer/ethereum/circuits/lib/src/README.md Outdated Show resolved Hide resolved
ethereum/circuits/lib/src/misc/bytes32.nr Outdated Show resolved Hide resolved
ethereum/circuits/lib/README.md Outdated Show resolved Hide resolved
vlayer/ethereum/circuits/lib/src/README.md Outdated Show resolved Hide resolved
pub(crate) fn mapping(slot: Bytes32, key: Bytes32) -> Bytes32;
```

Calculates slot number of value corresponding to a mapping `key`. `Slot` argument is the storage location of the mapping calculated after applying storage layout rules.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Slot number doesn't make sense. Slot itself is a number.
Calculates THE slot
Of A value

Copy link
Collaborator

Choose a reason for hiding this comment

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

How slot if calculated is irrelevant in the context of this function. It deals with calculating it's return value. You can mention that it concatenates & hashes

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wanted to include the explanation of what is this slot argument, because we need to emphasise the difference between this argument and the one with the same name in the function mentioned later.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There will be a link to documentation about solidity storage layout where concatenation and hashing will be explained. So I don't think we need to repeat that here.


Calculates slot number where element at `index` in dynamic array is located. `Slot` argument is the storage location of the dynamic array calculated after applying storage layout rules. `Size` defines the size of elements in the array.

- There is an analogical function where `slot` argument is a precalculated slot of the first element in the array:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's describe - when is the other function useful. Some example code in Sol.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Actually there is an example of usage for this function below.

vlayer/ethereum/circuits/lib/src/README.md Outdated Show resolved Hide resolved
vlayer/ethereum/circuits/lib/src/README.md Outdated Show resolved Hide resolved
Copy link
Collaborator

@LogvinovLeon LogvinovLeon left a comment

Choose a reason for hiding this comment

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

Let's do the last sync round of review tomorrow morning

@@ -72,3 +72,11 @@ pub fn sub_array_equals<TItem, SUBARRAY_LEN, ARRAY_LEN>(
}
result
}

pub fn slice_to_array<LENGTH>(slice: [u8]) -> [u8; LENGTH] {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Comment on lines 211 to 216
U256 is a structure to use as a type for big numbers.
It is used when dealing with numbers up to 2<sup>256</sup>. They can exceed Field maximum value.

[There](.src/uint256.nr) is an unoptimized implementation of this type using two U128 structures. Optimized version will appear in Noir.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This should mention - why are U256 useful. That they are a word size in ETH and therefore a basic type used in both storage and slot values calculations

@aajj999 aajj999 force-pushed the ania/slots_docs branch from c61a477 to 049fdf6 Compare May 31, 2024 08:28
@aajj999 aajj999 added this pull request to the merge queue May 31, 2024
Merged via the queue into main with commit 2149904 May 31, 2024
6 checks passed
@aajj999 aajj999 deleted the ania/slots_docs branch May 31, 2024 09:24
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.

3 participants