Skip to content

fix: remove ineffective witness assignment#463

Open
gballet wants to merge 1 commit intokaustinen-with-shapellafrom
fix-ineffecive-witness-alloc
Open

fix: remove ineffective witness assignment#463
gballet wants to merge 1 commit intokaustinen-with-shapellafrom
fix-ineffecive-witness-alloc

Conversation

@gballet
Copy link
Copy Markdown
Owner

@gballet gballet commented Jul 19, 2024

I noticed that there was an ineffectual witness creation, as well as a misplaced check for the existence of the witness, I am removing them for cleanup - they clash with some changes introduced by FILL_COST

@gballet gballet requested a review from jsign July 19, 2024 11:15
Comment thread core/vm/evm.go Outdated
Comment on lines -140 to -142
if txCtx.Accesses == nil && chainConfig.IsPrague(blockCtx.BlockNumber, blockCtx.Time) {
evm.Accesses = evm.StateDB.(*state.StateDB).NewAccessWitness()
}
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

this stuff is recreated in applyTransaction and isn't needed before, so this is a redundant creation.

Copy link
Copy Markdown
Collaborator

@jsign jsign Jul 22, 2024

Choose a reason for hiding this comment

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

I've checked all references to NewEVM and there're many places that call this method that aren't applyTransaction.

I feel it would be much safer to maybe move that initialization inside NewEVMTxContext(...)? I'm not sure why it makes sense to initialize one of its attributes outside the ctor creating these kind of situations.

Also noted that that referenced line doesn't do the chainConfig.IsPrague(blockCtx.BlockNumber, blockCtx.Time) style check that we did here. I guess that's just creating a little extra garbage for block ranges that the witness doesn't apply, but just mentioning.

If we're always fine with doing it ignoring the right fork (as done today in applyTransaction), then moving it to NewEVMTxContext is possible since that method doesn't have block num.

Copy link
Copy Markdown
Collaborator

@jsign jsign left a comment

Choose a reason for hiding this comment

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

LGMT, but left some comments if we can simplify further.

Comment thread core/state/statedb.go
func (s *StateDB) Witness() *AccessWitness {
if s.witness == nil {
s.witness = s.NewAccessWitness()
panic("witness wasn't initialized")
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I had the feeling this removed logic was intentionally trying to lazily initialize in some cases.

Thing is that if we remove this, we could panic "for a while" but eventually this method will have to change to returning *AccessWitnes, error. (Or avoid the if check?)

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

yes the if check should not be necessary, I am just setting the panic to catch a rebase issue. I'll add a TODO here.

Comment thread core/vm/evm.go Outdated
Comment on lines -140 to -142
if txCtx.Accesses == nil && chainConfig.IsPrague(blockCtx.BlockNumber, blockCtx.Time) {
evm.Accesses = evm.StateDB.(*state.StateDB).NewAccessWitness()
}
Copy link
Copy Markdown
Collaborator

@jsign jsign Jul 22, 2024

Choose a reason for hiding this comment

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

I've checked all references to NewEVM and there're many places that call this method that aren't applyTransaction.

I feel it would be much safer to maybe move that initialization inside NewEVMTxContext(...)? I'm not sure why it makes sense to initialize one of its attributes outside the ctor creating these kind of situations.

Also noted that that referenced line doesn't do the chainConfig.IsPrague(blockCtx.BlockNumber, blockCtx.Time) style check that we did here. I guess that's just creating a little extra garbage for block ranges that the witness doesn't apply, but just mentioning.

If we're always fine with doing it ignoring the right fork (as done today in applyTransaction), then moving it to NewEVMTxContext is possible since that method doesn't have block num.

Comment thread core/state/statedb.go
func (s *StateDB) Witness() *AccessWitness {
if s.witness == nil {
s.witness = s.NewAccessWitness()
panic("witness wasn't initialized")
Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Suggested change
panic("witness wasn't initialized")
// TODO this is meant to catch rebase errors, replace with error return when stabilized
panic("witness wasn't initialized")

@gballet gballet force-pushed the kaustinen-with-shapella branch from 4a2f6fb to e5d5e09 Compare February 24, 2026 14:09
@gballet gballet requested a review from holiman as a code owner February 24, 2026 14:09
@gballet gballet force-pushed the kaustinen-with-shapella branch from e5d5e09 to 4a2f6fb Compare February 24, 2026 14:10
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