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 precompile address checks & value bearing witness cost charging #412

Merged
merged 1 commit into from
Apr 9, 2024

Conversation

jsign
Copy link
Collaborator

@jsign jsign commented Apr 8, 2024

This PR:

  • Does some refactor to avoid duplicate work in CALL/CALLCODE/DELEGATECALL/STATICCALL witness events.
  • Comply to the spec rule of only doing that if the target address isn't a precompile. Not only for the above instructions, but also for EXTCODEHASH, EXTCODESIZE and SELFDESTRUCT.
  • Add a missing value-bearing charging for CALLCODE.

… value-bearing rule

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Comment on lines +450 to +451
if transfersValue {
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], address.Bytes()[:]))
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Charging this was missing?

Copy link
Owner

Choose a reason for hiding this comment

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

apparently

@@ -73,8 +78,10 @@ func makeCallVariantGasEIP4762(oldCalculator gasFunc) gasFunc {
if err != nil {
return 0, err
}
wgas := evm.Accesses.TouchCodeSize(contract.Address().Bytes(), false)
wgas += evm.Accesses.TouchCodeHash(contract.Address().Bytes(), false)
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Remove this wrong CodeHash touching.

if _, isPrecompile := evm.precompile(contract.Address()); isPrecompile {
return gas, nil
}
wgas := evm.Accesses.TouchAndChargeMessageCall(contract.Address().Bytes())
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Touch version and codesize.

Comment on lines +101 to +103
if _, isPrecompile := evm.precompile(beneficiaryAddr); isPrecompile {
return 0, nil
}
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

This was missing too

@jsign jsign requested a review from gballet April 8, 2024 18:58
@jsign jsign marked this pull request as ready for review April 8, 2024 18:58
Copy link
Owner

@gballet gballet left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines +450 to +451
if transfersValue {
gas, overflow = math.SafeAdd(gas, evm.Accesses.TouchAndChargeValueTransfer(contract.Address().Bytes()[:], address.Bytes()[:]))
Copy link
Owner

Choose a reason for hiding this comment

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

apparently

@gballet gballet merged commit bec7d2e into eip-4762-rewrite Apr 9, 2024
gballet pushed a commit that referenced this pull request Apr 10, 2024
… value-bearing rule (#412)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet added a commit that referenced this pull request Apr 15, 2024
* simplified gas accounting layer

* integrate some review feedback

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* more suggestions from code review

* don't charge creation gas + charge code chunks in create

* A couple more fixes

* make linter happy

* fix create init gas consumption issue

* fix: in gas funcs, use tx witness instead of global witness

* fix linter issue

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix: EXTCODECOPY gas consumption

* fix warm gas costs

* fix the order gas is charged in during contract creation epilogue

* fix selfdestruct

* fix #365 in eip rewrite (#407)

* fix: OOG type in code creation OOG (#408)

* core/vm: charge BLOCKHASH witness cost (#409)

* core/vm: charge BLOCKHASH witness cost

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove gas optimization for now

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove redundant logic for contract creation (#413)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix precompile address check for charging witness costs & fix missing value-bearing rule (#412)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* core/vm: fix wrong check (#416)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* charge for account creation if selfdestruct creates a new account (#417)

* add key comparison test (#418)

* core/vm: charge contract init before execution logic (#419)

* core/vm: charge contract init before execution logic

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix CREATE2 as well

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* quell linter

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet added a commit that referenced this pull request May 7, 2024
* simplified gas accounting layer

* integrate some review feedback

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* more suggestions from code review

* don't charge creation gas + charge code chunks in create

* A couple more fixes

* make linter happy

* fix create init gas consumption issue

* fix: in gas funcs, use tx witness instead of global witness

* fix linter issue

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix: EXTCODECOPY gas consumption

* fix warm gas costs

* fix the order gas is charged in during contract creation epilogue

* fix selfdestruct

* fix #365 in eip rewrite (#407)

* fix: OOG type in code creation OOG (#408)

* core/vm: charge BLOCKHASH witness cost (#409)

* core/vm: charge BLOCKHASH witness cost

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove gas optimization for now

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove redundant logic for contract creation (#413)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix precompile address check for charging witness costs & fix missing value-bearing rule (#412)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* core/vm: fix wrong check (#416)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* charge for account creation if selfdestruct creates a new account (#417)

* add key comparison test (#418)

* core/vm: charge contract init before execution logic (#419)

* core/vm: charge contract init before execution logic

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix CREATE2 as well

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* quell linter

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet added a commit that referenced this pull request May 8, 2024
* simplified gas accounting layer

* integrate some review feedback

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* more suggestions from code review

* don't charge creation gas + charge code chunks in create

* A couple more fixes

* make linter happy

* fix create init gas consumption issue

* fix: in gas funcs, use tx witness instead of global witness

* fix linter issue

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix: EXTCODECOPY gas consumption

* fix warm gas costs

* fix the order gas is charged in during contract creation epilogue

* fix selfdestruct

* fix #365 in eip rewrite (#407)

* fix: OOG type in code creation OOG (#408)

* core/vm: charge BLOCKHASH witness cost (#409)

* core/vm: charge BLOCKHASH witness cost

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove gas optimization for now

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove redundant logic for contract creation (#413)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix precompile address check for charging witness costs & fix missing value-bearing rule (#412)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* core/vm: fix wrong check (#416)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* charge for account creation if selfdestruct creates a new account (#417)

* add key comparison test (#418)

* core/vm: charge contract init before execution logic (#419)

* core/vm: charge contract init before execution logic

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix CREATE2 as well

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* quell linter

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet added a commit that referenced this pull request May 8, 2024
* simplified gas accounting layer

* integrate some review feedback

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* more suggestions from code review

* don't charge creation gas + charge code chunks in create

* A couple more fixes

* make linter happy

* fix create init gas consumption issue

* fix: in gas funcs, use tx witness instead of global witness

* fix linter issue

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix: EXTCODECOPY gas consumption

* fix warm gas costs

* fix the order gas is charged in during contract creation epilogue

* fix selfdestruct

* fix #365 in eip rewrite (#407)

* fix: OOG type in code creation OOG (#408)

* core/vm: charge BLOCKHASH witness cost (#409)

* core/vm: charge BLOCKHASH witness cost

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove gas optimization for now

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove redundant logic for contract creation (#413)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix precompile address check for charging witness costs & fix missing value-bearing rule (#412)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* core/vm: fix wrong check (#416)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* charge for account creation if selfdestruct creates a new account (#417)

* add key comparison test (#418)

* core/vm: charge contract init before execution logic (#419)

* core/vm: charge contract init before execution logic

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix CREATE2 as well

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* quell linter

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>
gballet added a commit that referenced this pull request May 8, 2024
* simplified gas accounting layer

* integrate some review feedback

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* more suggestions from code review

* don't charge creation gas + charge code chunks in create

* A couple more fixes

* make linter happy

* fix create init gas consumption issue

* fix: in gas funcs, use tx witness instead of global witness

* fix linter issue

* Apply suggestions from code review

Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix: EXTCODECOPY gas consumption

* fix warm gas costs

* fix the order gas is charged in during contract creation epilogue

* fix selfdestruct

* fix #365 in eip rewrite (#407)

* fix: OOG type in code creation OOG (#408)

* core/vm: charge BLOCKHASH witness cost (#409)

* core/vm: charge BLOCKHASH witness cost

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove gas optimization for now

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* remove redundant logic for contract creation (#413)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix precompile address check for charging witness costs & fix missing value-bearing rule (#412)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* core/vm: fix wrong check (#416)

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* charge for account creation if selfdestruct creates a new account (#417)

* add key comparison test (#418)

* core/vm: charge contract init before execution logic (#419)

* core/vm: charge contract init before execution logic

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>

* fix CREATE2 as well

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Guillaume Ballet <3272758+gballet@users.noreply.github.com>

* quell linter

---------

Signed-off-by: Ignacio Hagopian <jsign.uy@gmail.com>
Co-authored-by: Ignacio Hagopian <jsign.uy@gmail.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.

None yet

2 participants