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

feat!: add support for dynamic configurables #1555

Open
wants to merge 43 commits into
base: master
Choose a base branch
from

Conversation

hal3e
Copy link
Contributor

@hal3e hal3e commented Dec 9, 2024

closes: #1481
closes: #1328 as we can read the configurables directly from the binary

Release notes

In this release, we:

  • Added support for dynamic str configurables.
  • Added a new configurables reader to contract, script and predicateabigen that can read configurables directly form the binary.
  • Added struct ConfigurablesReader that can be used to read direct and indirect configurables at runtime and compile time.
  • Added tests for configurables with loades for contracts, scripts and predicates.
  • Updated documentation.

Summary

Breaking Changes

  • Contract Regular and Loader methods code(), contract_id(), code_root, state_root return Result
  • Executable Regular and Loader methods code(), data_offset_in_code, loader_code return Result
  • Configurables's update_constants_in returns Result
  • Predicate's with_configurable returns Result
  • AbiFormatter's decode_configurables argument configurable_data now accepts a &[u8]

Checklist

  • All changes are covered by tests (or not applicable)
  • All changes are documented (or not applicable)
  • I reviewed the entire PR myself (preferably, on GH UI)
  • I described all Breaking Changes (or there's none)

@hal3e hal3e added the blocked label Dec 9, 2024
@hal3e hal3e self-assigned this Dec 9, 2024
@hal3e hal3e removed the blocked label Feb 6, 2025
@hal3e hal3e marked this pull request as ready for review February 6, 2025 14:12
@hal3e hal3e requested a review from xunilrj February 6, 2025 14:14
hal3e and others added 9 commits February 10, 2025 14:02
…set (#1593)

<!--
List the issues this PR closes (if any) in a bullet list format, e.g.:
- Closes #ABCD
- Closes #EFGH
-->

<!--
Use this only if this PR requires a mention in the Release
Notes Summary. Valuable features and critical fixes are good
examples. For everything else, please delete the whole section.
-->

In this release, we:

~~- Previously deployed blobs are no longer accessible due to changes in
blob ID calculation. Redeployment is required.~~

Updates blob ID calculation to use the configurable offset instead of
the data offset, aligning with the updated design for scripts and
predicates.

`has_configurable_section_offset` function checks bytes 4 and 7 to
distinguish binary versions. If byte 4 is 0x74 (JMPF), it considers byte
7: 0x02 means legacy, 0x04 means new, and any other value results in an
error.

<!--
Please write a summary of your changes and why you made them.
Not all PRs will be complex or substantial enough to require this
section, so you can remove it if you think it's unnecessary.
-->

- [x] All **changes** are **covered** by **tests** (or not applicable)
- [x] All **changes** are **documented** (or not applicable)
- [x] I **reviewed** the **entire PR** myself (preferably, on GH UI)
- [x] I **described** all **Breaking Changes** (or there's none)

---------

Co-authored-by: hal3e <[email protected]>
Co-authored-by: Ahmed Sagdati <[email protected]>
Updated the way we access storage slots in the example.

#[tokio::test]
async fn contract_configurables_reader_manual() -> Result<()> {
// TODO: add documentatio
Copy link
Contributor

Choose a reason for hiding this comment

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

todo


#[tokio::test]
async fn contract_configurables_reader_runtime() -> Result<()> {
// TODO: add documentatio
Copy link
Contributor

Choose a reason for hiding this comment

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

.

Ok(())
}

fn dynamic_section_start(&self, binary: &[u8], data_offset: usize) -> Result<Option<usize>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

A short docstring here would be helpful

Copy link
Contributor Author

@hal3e hal3e Feb 27, 2025

Choose a reason for hiding this comment

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

added docstring 40afe0e

Copy link
Contributor

@segfault-magnet segfault-magnet left a comment

Choose a reason for hiding this comment

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

We should probably hold off on merging this until the sway branch catches up with sway master.

I have a feeling it's a bit behind seeing how the configurables offset is 8..16 and not 16..24 seeing as we already support the latter.

Either wait or integrate with the work done in the PR mentioned above so that we detect the compiler version used to generate the sway binary and use 16..24 if it is a modern compiler or 8..16 if it is the older one.


#[tokio::test]
async fn contract_configurables_reader_manual() -> Result<()> {
// TODO: add documentatio
Copy link
Contributor

Choose a reason for hiding this comment

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

?


#[tokio::test]
async fn contract_configurables_reader_runtime() -> Result<()> {
// TODO: add documentatio
Copy link
Contributor

Choose a reason for hiding this comment

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

?

@@ -51,10 +51,11 @@ mod code_types {
}
}

pub(crate) fn code(&self) -> Vec<u8> {
pub(crate) fn code(&self) -> Result<Vec<u8>> {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wdyt about having with_code and with_configurables return a Result, trying to apply the old configurables to the new code or the new configurables to the old code.

If that passes then we can .expect on all the getters and not have Result everywhere.

Nice consequence is that it will fail closer to the thing that made it fail -- ie the code or the configurables that were invalid, not later on when you try and calculate the contract id.

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 like the idea.

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.

Invalid configurables lead to panic Querying configurable constants and storage from SDK
5 participants