Skip to content

Conversation

@shemnon
Copy link
Contributor

@shemnon shemnon commented Jan 25, 2025

Add (for eof) section and funcion depth fields, and make pc container relative instead of code section relative.

Add (for eof) section and funcion depth fields, and make pc container
relative instead of code section relative.

// ExtDelegateCall is not allowed to call non-EOF contracts.
if is_ext_delegate_call && !bytecode.bytes_slice().starts_with(&EOF_MAGIC_BYTES) {
context.journal().checkpoint_revert(checkpoint);
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 was causing the depth field to read incorrectly when this case triggered. Not sure if here was any way to leverage it. Also, EOF only.

Copy link
Member

Choose a reason for hiding this comment

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

Good find! Yeah it is good fix and it is EOF only

@codspeed-hq
Copy link

codspeed-hq bot commented Jan 25, 2025

CodSpeed Performance Report

Merging #2023 will improve performances by 4.6%

Comparing shemnon:eof/tracing (21de630) with main (a8f9824)

Summary

⚡ 1 improvements
✅ 7 untouched benchmarks

Benchmarks breakdown

Benchmark BASE HEAD Change
precompile bench | ecrecover precompile 201.8 µs 192.9 µs +4.6%

// SAFETY: `instruction_pointer` should be at an offset from the start of the bytecode.
// In practice this is always true unless a caller modifies the `instruction_pointer` field manually.
self.instruction_pointer
.offset_from(self.base.eof().unwrap().raw.as_ptr()) as usize
Copy link
Member

Choose a reason for hiding this comment

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

I have already made a change so current pc is doing the same thing as trace_pc

fn pc(&self) -> usize {
// SAFETY: `instruction_pointer` should be at an offset from the start of the bytecode.
// In practice this is always true unless a caller modifies the `instruction_pointer` field manually.
unsafe {
self.instruction_pointer
.offset_from(self.base.bytecode().as_ptr()) as usize
}
}
}

and bytecode() gives self.base.eof().raw here:

pub fn bytecode(&self) -> &Bytes {
match self {
Self::LegacyAnalyzed(analyzed) => analyzed.bytecode(),
Self::Eof(eof) => &eof.body.code,
Self::Eip7702(code) => code.raw(),
}
}

Copy link
Member

Choose a reason for hiding this comment

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

Okay my mistake, will see to change the fn pc to become trace_pc it is not used in any other place for EOF.

@rakita rakita merged commit 773b909 into bluealloy:main Jan 27, 2025
27 checks passed
This was referenced Jan 27, 2025
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.

2 participants