-
Notifications
You must be signed in to change notification settings - Fork 196
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
fix(store): return zero for uninitialised static array elements #2613
Conversation
🦋 Changeset detectedLatest commit: 5663590 The changes in this PR will be included in the next version bump. This PR includes changesets to release 24 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
Co-authored-by: alvarius <[email protected]>
.changeset/popular-oranges-end.md
Outdated
"@latticexyz/cli": patch | ||
--- | ||
|
||
Fixed the behaviour of static arrays, so that they always return zero for uninitialised values. Previously they would revert with `Store_IndexOutOfBounds` if the index had not been set yet. |
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.
Should we make a note about this matching native solidity behavior?
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.
I like that! lemme think
// but ahead of the dynamic length, return zero | ||
typeWrappingData && typeWrappingData.kind === "staticArray" && field.arrayElement | ||
? ` | ||
uint256 _byteLength = ${_store}.getDynamicFieldLength(_tableId, _keyTuple, ${dynamicSchemaIndex}); |
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.
I would expect this to add gas but not seeing a gas report change. Are we not testing for gas on static-length array fields?
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.
I wondered that also. It seems like we don't report table libraries for this (or at all?)
Changes the behaviour of static arrays to return default values on "uninitialised" values. If an array index is less than the static length, but greater than the underlying dynamic length, we return zero.