-
Notifications
You must be signed in to change notification settings - Fork 104
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
feat: add ByteArray to storage #229
Conversation
Are we storing 1 array / "cell" or are we storing 1 byte / "cell" ? |
In this proposed PR, the idea is to not rely on segments (perhaps we should?), and use one slot for each element of the ByteArray {
data: array![1, 2],
pending_word: 0,
pending_word_len: 0,
} This will use 5 slots:
And the slots addresses are all derived from the base address when Is this something that can work, or we should rework this approach? |
I'm just wondering the difference between that and the |
In a sense yes, agree on that. But on the other hand, the management of the pending word is then totally manual. |
Does the pending word make sense in this context ? |
To be sure I get you, you are talking about using the In any case, we do need to keep the exact state of the pending word, as it can be any content between 0 and 30 bytes long. And |
2nd option! |
I'm really not sure about the DevX in this situation. Users will want to use "strings" (aka ByteArray) in legacy maps too I guess, which means implementing the Let me know if there is something I'm missing, but it would be like this right? #[storage]
struct Storage {
my_string: List<bytes31>,
strings: List<List<bytes31>>,
} Where we also need to reconstruct / deconstruct the Where we can simply do the following: #[storage]
struct Storage {
my_string: ByteArray,
strings: List<ByteArray>,
} If it's a matter of efficiency by using the storage segment, I can adapt. |
I don't have a strong opinion, just want to understand the trade offs here |
I see where you're going, ok this pr makes sense (misunderstood it) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you need to make sure that you're not overwriting non zero cells. also i still see some unwrap syscalls in functions that return a result
Sorry I shouldn't have resolved the first change request you've made here where I added a comment to mention that |
And about not re-writing 0 cell, I'm not sure why we need to do that. We rely on poseidon and huge slot space, no? |
Yes ofc i just don't want that the byte array in cell |
Totally agree, that's why I've not use the segments, because in my understanding segments are a region of 256 consecutive slots. |
Now i think that the size isn't correct anymore and should be the length of the |
Here I have my doubt yes. Because the And the length of |
@LucasLvy did you have more inputs about the conformity in the storage for this solution? |
lol sorry for that they'll add it in the core lib so i guess we don't need to answer this question |
That even better! Thank you very much and sorry I didn't see it lately. |
Pull Request type
Please check the type of change your PR introduces:
What is the current behavior?
StarkWare is working on
ByteArray
support. Currently there is no support forByteArray
(akastring
) in storage of contracts.What is the new behavior?
This PR introduces a naive implementation for
ByteArray
support in storage.LegacyMap
(induces by the first).LegacyMap
by derivingLegacyHash
.Does this introduce a breaking change?
Other information
About the
Store
trait, I've a doubt on thesize
which returns1
currently. In the current design, we only store one felt at the base address. Other addresses are derived by a computation of keys.I bumped to
2.4.0
to have it compiling, all tests are in green. But if it's preferable to have a PR dedicated to the bump, I can rebase later.