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

Do not restore $hp when returning from a context #525

Merged
merged 8 commits into from
Jul 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Changed

- [#525](https://github.com/FuelLabs/fuel-vm/pull/525): The `$hp` register is no longer restored to it's previous value when returning from a call, making it possible to return heap-allocated types from `CALL`.


#### Breaking

- [#514](https://github.com/FuelLabs/fuel-vm/pull/514/): Add `ChainId` and `GasCosts` to `ConsensusParameters`.
Expand All @@ -29,7 +32,6 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

- [#499](https://github.com/FuelLabs/fuel-vm/pull/499/): The `wasm_bindgen` support of `fuel-asm` and `fuel-types`.
Each new release also publish a typescript analog of the `fuel-asm` and `fuel-types` crates to the npm.


## [Version 0.35.0]

Expand Down
2 changes: 2 additions & 0 deletions fuel-vm/src/interpreter/flow.rs
Original file line number Diff line number Diff line change
Expand Up @@ -208,13 +208,15 @@ impl RetCtx<'_> {
let ggas = registers[RegId::GGAS];
let ret = registers[RegId::RET];
let retl = registers[RegId::RETL];
let hp = registers[RegId::HP];

registers.copy_from_slice(frame.registers());

registers[RegId::CGAS] = cgas;
registers[RegId::GGAS] = ggas;
registers[RegId::RET] = ret;
registers[RegId::RETL] = retl;
registers[RegId::HP] = hp;

let fp = registers[RegId::FP];
set_frame_pointer(context, registers.fp_mut(), fp);
Expand Down
9 changes: 3 additions & 6 deletions fuel-vm/src/interpreter/flow/ret_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,7 @@ use super::*;

#[test]
fn test_return() {
let mut frame_reg: [Word; VM_REGISTER_COUNT] =
std::iter::successors(Some(0), |x| Some(x + 1))
.take(VM_REGISTER_COUNT)
.collect::<Vec<_>>()
.try_into()
.unwrap();
let mut frame_reg: [Word; VM_REGISTER_COUNT] = std::array::from_fn(|i| i as Word);
frame_reg[RegId::CGAS] = 100;
let mut expected = frame_reg;
let frame = CallFrame::new(
Expand All @@ -26,11 +21,13 @@ fn test_return() {
registers[RegId::GGAS] = 100;
registers[RegId::RET] = 101;
registers[RegId::RETL] = 102;
registers[RegId::HP] = 1234;

expected[RegId::CGAS] = 199;
expected[RegId::GGAS] = 100;
expected[RegId::RET] = 101;
expected[RegId::RETL] = 102;
expected[RegId::HP] = 1234;
expected[RegId::PC] += 4;
let mut context = Context::Call {
block_height: Default::default(),
Expand Down
Loading