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(vm): Implement call tracing for fast VM #2905

Merged
merged 21 commits into from
Jan 20, 2025
Merged

feat(vm): Implement call tracing for fast VM #2905

merged 21 commits into from
Jan 20, 2025

Conversation

joonazan
Copy link
Contributor

@joonazan joonazan commented Sep 17, 2024

What ❔

  • Implements call tracing for the fast VM.
  • Enables call tracing for the batch VM executor (i.e., one used in the state keeper) if it is requested. Compares produced traces in the shadow VM mode.

Why ❔

Call tracing is the last large missing part of the fast VM.

@joonazan joonazan force-pushed the jms-call-tracer branch 4 times, most recently from 1cc9ec9 to 6a0c824 Compare September 24, 2024 17:20
@joonazan joonazan changed the base branch from main to jms-pla-908-account-validation-properly-handle-when-out-of-gas November 15, 2024 13:42
@joonazan joonazan changed the base branch from jms-pla-908-account-validation-properly-handle-when-out-of-gas to main November 15, 2024 14:54
@joonazan joonazan marked this pull request as ready for review November 15, 2024 14:55
@joonazan
Copy link
Contributor Author

This does not turn enable call tracing in API because of the details of how that happens depend on #2863 so it is better to wait until both PRs are in.

@slowli slowli requested a review from perekopskiy January 14, 2025 13:52
@slowli slowli changed the title feat: vm2 call tracer feat(vm): Implement call tracing for fast VM Jan 14, 2025
Copy link
Member

@popzxc popzxc left a comment

Choose a reason for hiding this comment

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

This is certainly not the domain I'm comfortable with, but I've looked through the diff and it doesn't look suspicious. Not very helpful, but LGTM 😅

@slowli slowli added this pull request to the merge queue Jan 17, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 17, 2025
@slowli slowli added this pull request to the merge queue Jan 20, 2025
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Jan 20, 2025
@slowli slowli added this pull request to the merge queue Jan 20, 2025
Copy link
Contributor Author

@joonazan joonazan left a comment

Choose a reason for hiding this comment

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

Didn't find any serious issues. Two very confusing spots that can probably be fixed with comments.

@@ -191,15 +193,14 @@ impl CallTracer {
.farcall
.parent_gas
.saturating_sub(state.vm_local_state.callstack.current.ergs_remaining as u64);

self.save_output_latest(state, memory, ret_opcode, &mut current_call.farcall);

// If there is a parent call, push the current call to it
// Otherwise, push the current call to the stack, because it's the top level call
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This comment is outdated.

let output_ptr = FatPointer::from(maybe_output_ptr);
if output_ptr.length == 0 && output_ptr.offset == 0 {
// Trivial pointer, which is formally cannot be dereferenced. This only matters
// when extracting the revert reason; the legacy VM treats the trivial pointer specially.
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does this case require special handling? I'd imagine that reading a length zero pointer produces an empty array anyway.

Nit: extra is.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It seems to cause "Unknown revert reason". So length 0, offset 0 is unknown reason but offset 1 is not?

Copy link
Contributor

Choose a reason for hiding this comment

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

As you've noted, the reason for special handling is purely corresponding to traces produced by the legacy implementation. Subjectively, this special case makes little sense, but it's easy to implement and I assume that compatibility has higher priority.

So length 0, offset 0 is unknown reason but offset 1 is not?

Yep, this is how it works in the legacy VM:

if !fat_data_pointer.is_trivial() {
Some(memory.read_unaligned_bytes(
fat_data_pointer.memory_page as usize,
fat_data_pointer.start as usize,
fat_data_pointer.length as usize,
))
} else {
None
}

where is_trivial is defined as length 0, offset 0.

Merged via the queue into main with commit 731b824 Jan 20, 2025
33 checks passed
@slowli slowli deleted the jms-call-tracer branch January 20, 2025 11:42
github-merge-queue bot pushed a commit that referenced this pull request Jan 21, 2025
🤖 I have created a release *beep* *boop*
---


##
[26.1.0](core-v26.0.0...core-v26.1.0)
(2025-01-21)


### Features

* update l2 erc20 bridge address in updater as well
([#3500](#3500))
([fe3c7b2](fe3c7b2))
* **vm:** Implement call tracing for fast VM
([#2905](#2905))
([731b824](731b824))


### Bug Fixes

* copy special case to fast VM call tracer
([#3509](#3509))
([995e583](995e583))
* fix execute encoding for transactions
([#3501](#3501))
([4c381a8](4c381a8))
* **gateway:** erc20 workaround for gateway upgrade
([#3511](#3511))
([c140ba8](c140ba8))


### Performance Improvements

* optimize get_unsealed_l1_batch_inner
([#3491](#3491))
([9b121c9](9b121c9))

---
This PR was generated with [Release
Please](https://github.com/googleapis/release-please). See
[documentation](https://github.com/googleapis/release-please#release-please).

---------

Co-authored-by: zksync-era-bot <zksync-era-bot@users.noreply.github.com>
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.

4 participants