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: switch blob ID calculation from data offset to configurable offset #1593

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

Conversation

Salka1988
Copy link
Member

@Salka1988 Salka1988 commented Jan 31, 2025

Release notes

In this release, we:

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

Summary

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.

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)

@Salka1988 Salka1988 added the enhancement New feature or request label Jan 31, 2025
@Salka1988 Salka1988 self-assigned this Jan 31, 2025
# Conflicts:
#	packages/fuels-programs/src/executable.rs
@Salka1988 Salka1988 linked an issue Jan 31, 2025 that may be closed by this pull request
@hal3e hal3e changed the title feat: Switch blob ID calculation from data offset to configurable offset feat: switch blob ID calculation from data offset to configurable offset Feb 3, 2025
hal3e
hal3e previously approved these changes Feb 3, 2025
Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

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

LGTM

@Salka1988 Salka1988 requested review from xunilrj and hal3e February 4, 2025 11:04
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 also probably deprecate the data_section_offset on Executable<Loader> since that will no longer point to the data section offset but rather to the configurable offset.

so maybe add a #deprecated on it.

e2e/tests/binary_format.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Outdated Show resolved Hide resolved
digorithm
digorithm previously approved these changes Feb 5, 2025
Copy link
Member

@digorithm digorithm left a comment

Choose a reason for hiding this comment

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

LGTM. Great job, @Salka1988, and great suggestions, @segfault-magnet!

Copy link
Contributor

@hal3e hal3e left a comment

Choose a reason for hiding this comment

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

Great work. Left some comments

packages/fuels-programs/src/debug.rs Outdated Show resolved Hide resolved
e2e/tests/binary_format.rs Outdated Show resolved Hide resolved
e2e/tests/debug_utils.rs Outdated Show resolved Hide resolved
Comment on lines 357 to 380
pub fn has_configurables_section_offset(binary: &[u8]) -> Result<Option<bool>> {
if binary.len() < 8 {
return Err(fuels_core::error!(
Other,
"binary too short to check JMPF instruction, need at least 8 bytes but got: {}",
binary.len()
));
}

let instruction = Instruction::try_from([binary[4], binary[5], binary[6], binary[7]])
.map_err(|e| fuels_core::error!(Other, "Invalid instruction at byte 4: {:?}", e))?;

if let Instruction::JMPF(offset) = instruction {
let offset_val = offset.imm18().to_u32();
let result = match offset_val {
0x04 => Some(true),
0x02 => Some(false),
_ => None,
};
Ok(result)
} else {
Ok(None)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

That Result<Option<bool>> combo feels kinda awkward. It’s not immediately clear what it’s trying to communicate.

I think it’s doing something like this:

Ok(Some(true | false)) → "I know for sure whether the section is there or not."
Ok(None) → "I have no clue if the section is there."
Err → "The binary is too short, or I couldn't read the instruction."

Feels like this should just be Result<bool>, and we should fail if we don’t detect what we expect. Otherwise, if sway changes how they handle jmpf in that spot, we might unknowingly start messing up the configurables.

Also, do we actually have confirmation from the sway team that the 0x04 and 0x02 offsets are stable? If not, we need to decide on a fallback so that if they do change, the SDK doesn’t just break.

If we have to pick a default for the case when we cannot reliably detect whether the configurables offset is present, I'd default to assuming that there is a configurables offset.

Copy link
Member Author

Choose a reason for hiding this comment

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

We did this because of handwritten code. Previously it was Result<bool>. I'll revert it.

packages/fuels-programs/src/debug.rs Show resolved Hide resolved
packages/fuels-programs/src/debug.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Outdated Show resolved Hide resolved
packages/fuels-programs/src/executable.rs Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for verified ABIs
4 participants