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

fix(vm): Fix VM divergence in revert data #3570

Open
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

slowli
Copy link
Contributor

@slowli slowli commented Feb 6, 2025

What ❔

Fixes the result tracer of the legacy VM so that it doesn't return random-ish revert data in marginal cases.

Why ❔

The revert data should be correct.

Checklist

  • PR title corresponds to the body of PR (we generate changelog entries from PRs).
  • Tests for the changes have been added / updated.
  • Documentation comments have been added / updated.
  • Code has been formatted via zkstack dev fmt and zkstack dev lint.

Copy link
Contributor

github-actions bot commented Feb 6, 2025

Detected VM performance changes

Benchmark name Est. cycles Change in est. cycles
call_far/legacy 2474484422 +2.3%

@@ -460,15 +460,15 @@ jobs:

- name: Run integration tests
run: |
ci_run ./bin/run_on_all_chains.sh "zkstack dev test integration --no-deps --ignore-prerequisites" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }}
ci_run ./bin/run_on_all_chains.sh "zkstack dev test integration --verbose --no-deps --ignore-prerequisites" ${{ env.CHAINS }} ${{ env.INTEGRATION_TESTS_LOGS_DIR }}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Is the size of the generated log files a concern? If not, verbose output can significantly help with investigating integration test failures. And it doesn't seem to add that much; the logs artifact with verbose output is ~7.8 MB against ~7.5 MB before.

Comment on lines +7 to +8
- [`estimate_fee_for_transfer_to_self`](estimate_fee_for_transfer_to_self.json): Fee estimation step for a 0 base token
transfer to self with a low gas limit. The legacy VM previously returned the incorrect revert reason.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

JFYI, I haven't been able to reproduce the setup with pure code. May have to do with the account being previously active and/or block params.

Comment on lines -162 to +163
let returndata = self
.far_call_tracker
.get_latest_returndata()
.map(|ptr| read_pointer(memory, ptr))
.unwrap_or_default();
let return_ptr = FatPointer::from_u256(vm_hook_params[1]);
let returndata = read_pointer(memory, return_ptr);
Copy link
Contributor Author

@slowli slowli Feb 6, 2025

Choose a reason for hiding this comment

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

Without this change, running the VM dump adding in this PR (i.e., estimating fee for a 0 transfer to self with a low tx gas limit) on the legacy VM leads to a non-sensical 32-byte returndata, which looks like a non-zero big-endian uint from some other call.

This is how this hook is implemented in the fast VM:

let value = self.get_hook_params()[1];
let fp = FatPointer::from(value);
let return_data = self.read_bytes_from_heap(fp);

AFAICT, the 1st hook param is indeed set by the bootloader (and has been set for a long time), so the previous implementation looks like a legacy artifact. IIUC, the bootloader used with fee estimation has some optimizations enabled, which in this case led to call reordering (?), making the last returndata captured by the tracer (it's still used for the DebugReturnData hook, BTW) not match the returndata set by the PostResult hook.

@slowli slowli marked this pull request as ready for review February 6, 2025 12:53
@slowli slowli requested a review from a team as a code owner February 6, 2025 12:53
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.

1 participant