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

AA-408 deduct gas for aatx #28

Merged
merged 10 commits into from
Sep 16, 2024
Merged

AA-408 deduct gas for aatx #28

merged 10 commits into from
Sep 16, 2024

Conversation

drortirosh
Copy link

No description provided.

@drortirosh drortirosh force-pushed the AA-408-deduct-gas branch 2 times, most recently from bead6c0 to 164d851 Compare August 18, 2024 09:17
@@ -173,7 +172,14 @@ func TransactionToMessage(tx *types.Transaction, s types.Signer, baseFee *big.In
msg.GasPrice = cmath.BigMin(msg.GasPrice.Add(msg.GasTipCap, baseFee), msg.GasFeeCap)
}
var err error
msg.From, err = types.Sender(s, tx)
if tx.Type() == types.Rip7560Type {

Choose a reason for hiding this comment

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

This change is not meaningful - at no point will an Rip7560Type transaction be converted into a Message using TransactionToMessage function.
By definition, Rip7560Type transaction contains from 2 to 5 separate Messages.

@@ -429,6 +439,7 @@ func preparePaymasterValidationMessage(baseTx *types.Transaction, config *params
if err != nil {
return nil, err
}
//no GasPayer: account validation already prepaid

Choose a reason for hiding this comment

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

I could not object any stronger to this approach. I prefer the pre-charge to be a standalone operation as it was before. In any case, I don't see any benefit of having one frame pre-pay gas for another.

Comment on lines 255 to 241
//fmt.Printf("== buyGas %+v\n", st.msg)
mgval := new(big.Int).SetUint64(st.msg.GasLimit)
mgval.Mul(mgval, st.msg.GasPrice)

Choose a reason for hiding this comment

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

These lines are unmodified, implying that you "pre-charge" the exact amount of the first frame's gas limit.
How confusing would it be to pre-charge a different amount specifically in the first frame of a RIP-7560 transaction?
How will you pass this "total RIP-7560 transaction gas limit" value into the Message object?

@@ -513,7 +529,7 @@ func (st *StateTransition) refundGas(refundQuotient uint64) uint64 {
// Return ETH for remaining gas, exchanged at the original rate.
remaining := uint256.NewInt(st.gasRemaining)
remaining.Mul(remaining, uint256.MustFromBig(st.msg.GasPrice))
st.state.AddBalance(st.msg.From, remaining, tracing.BalanceIncreaseGasReturn)
st.state.AddBalance(*st.msg.GasPayer, remaining, tracing.BalanceIncreaseGasReturn)

Choose a reason for hiding this comment

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

This change makes no sense to me. If IsRip7560Frame is refunded separately, the GasPayer here will always be a From address, right?

@drortirosh drortirosh marked this pull request as ready for review September 15, 2024 12:58
core/state_processor_rip7560.go Outdated Show resolved Hide resolved
PaymasterContext []byte
PreCharge *uint256.Int
EffectiveGasPrice *uint256.Int
TotalValidationGasUsed uint64

Choose a reason for hiding this comment

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

Having both ValidationUsedGas and TotalValidationGasUsed in the same object is extremely confusing. Let's make the names AccountValidationUsedGas and ValidationPhaseUsedGas?

core/state_processor_rip7560.go Outdated Show resolved Hide resolved
core/state_processor_rip7560.go Outdated Show resolved Hide resolved
@@ -516,25 +532,25 @@ func ApplyRip7560ExecutionPhase(
executionResult := CallFrame(st, &AA_ENTRY_POINT, sender, accountExecutionMsg, aatx.Gas)
receiptStatus := types.ReceiptStatusSuccessful
executionStatus := ExecutionStatusSuccess
execRefund := capRefund(st.state.GetRefund(), executionResult.UsedGas)

Choose a reason for hiding this comment

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

There is no point in having capRefund called for each call - we probably should apply EIP-3529 refund cap the entire transaction's refund, not per-frame or per-phase.

Copy link
Author

Choose a reason for hiding this comment

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

I think it should be calculated and capped separately for each phase.
In in the future (see AA-450), refund it just after validation, before execution. This way, it might allow more TXs to be added to the block. Otherwise, this known-to-be-refunded gas can be used for more AATXs in the block.

core/state_processor_rip7560.go Outdated Show resolved Hide resolved
@forshtat forshtat merged commit 5b754c2 into RIP-7560-revision-2 Sep 16, 2024
1 check failed
@forshtat forshtat deleted the AA-408-deduct-gas branch September 16, 2024 16:26
shahafn added a commit that referenced this pull request Jan 7, 2025
…port (#49)

* WIP: manually bring over RIP-7560 related code; compiles but does not run

* TMP: check in commands to run the validator and beacon chain node

* TMP: check in ignored files

* Create a separate 'cleanup.sh' command

* Set slot time to 3 seconds; check in "--dev" mode idea command

* Remove code related to EOA-based RIP-7560 transactions

* Remove BigNonce and NonceManager logic as it has moved to separate RIP

* Fix issue: charging 'from' address (EntryPoint) for inner frames gas

* remove expectedRevenue

* remove StateTransition rip7560Frame bool

is msg.isRip7560Frame,
which allows usage of plain ApplyMessage

* add paymaster, deployer optional params (#4)

* Remove unused EOA-era function

* Fix comment

* Test ApplyRip7560ValidationPhases (#5)

* initial UT for ApplyRip7560ValidationPhases

test ./tests/rip7560/

* refactor test context

* add some error tests

* returnData helper

* github actions for rip7560 tests

* update path

* refactor test utils

* refactor textContextBuilder

* remove prestate json.

* pr comments

* merge master (#6)

* initial Process test (#7)

initial test for the full "Process" call, to handle mixed legacy and AA
transactions

* remove stub message (#8)

* remove stub message

was created just to create the vm.Txontext

* update

* WIP: create the 'debug_traceRip7560Validation' API

* WIP: Execute 'ApplyRip7560ValidationPhases' with 'rip7560Validation' tracer

* refactor dev genesis (#10)

* check error

* update tests, match return values to RIP

* refactor: test HandleRip7560Transactions

(instead of individual validation methods)

* test nonce

* added time-range tests

* pr issues

* initial paymaster test flows

* returnWithData, revertWithData

arbitrary-length return or revert
(currently, can't test it, since we check "error", and actual revert
data is hidden. will be probably needed when testing paymaster.)

* test paymaster validations

* paymaster time-range checking

* pr reviews

* test deployer flows

* initial paymaster test flows

* returnWithData, revertWithData

arbitrary-length return or revert
(currently, can't test it, since we check "error", and actual revert
data is hidden. will be probably needed when testing paymaster.)

* test paymaster validations

* paymaster time-range checking

* pr reviews

* AA-247: Implement tracer (#11)

* WIP: bring in old 4337 Bundler Collector Tracer code (compiles)

* Fix runtime errors (WIP)

* Adding missing fields, using OnEnter hook

* Fix using [0:20] bytes of "PaymasterData" instead of the new "Paymaster" field

* Fix banned opcode checks for Factory frame

* Add 'nil' check

---------

Co-authored-by: shahafn <[email protected]>

* Fix syntax error

* I don't understand why would we need & 0xFF here, please elaborate

* Fixing validationData packing

* Fix: do not lose the AA tx application error; fix lost 'nonce' value

* Move the 'TraceRip7560Validation' API to the 'eth' namespace, from the 'debug'

* check gas, nonce form ApplyRip7560ValidationPhases (#16)

move validations into the validation phase.
note that it breaks some tests which rely on wrong nonce.

* fix nonce, entrypoint (#17)

- add correct sender address for AA transactions (AA_ENTRY_POINT, and AA_CREATOR for the deployment frame)
- disable nonce increment in TransitionDb if the sender is either of these magic addresses
- add AA-specific nonce increment for the transaction sender.

* AA-403: Fix RIP-7560 transaction hash calculation (#19)

* AA-378: Completing native tracer (#15)

* Renaming, Adding tstore/tload support

* Fixing tracer wip

* Adding handling of value, onExit

* Removing method id

* Fix abi encoding of nil fields

* typo

* Removing logs

* AA-394 receipt fields (#21)

* handle transaction receipt status
  effectiveGasUsed
  refund excess to account/paymaster

* AA-381: Create a "pull bundle" block building mode and a 'getRip7560Bundle' method (#18)

* Fix crash

* getTransaction (#24)

* AA-257: Return useful errors and on-chain revert reasons to the RPC response message (#22)

* Propagate validation on-chain revert reasons to the RPC response message
* Explicit error for missing both deployed code and factory
* Bubble up the real 'RevertReason' through the 'TraceRip7560Validation' API

* AA-411: Parse calls to EntryPoint address for account/paymaster 'acceptance' (#23)

* AA-411: Parse calls to EntryPoint address for account/paymaster 'acceptance'
* Extract ABI encoding&decoding into file; use ABI instead of manual bit parsing
* Remove rudimentary mentions of "magic" in RIP-7560 related code
* Copy the "evm.Config.Tracer" instead of overriding the original object
* Remove depth check, compare addresses instead

* AA-336 Revert excution when postOp reverts (#29)

* Revert excution when postOp reverts

* Fixing execution,postOp

* Adding statedb access list functions to be able to snapshot/revert

* AA-412: Implement RIP-7712 NonceManager support (#27)

* Add RIP-7712 nonce field to the RIP-7560 transaction type

* Do not increment legacy nonce for RIP-7712 transactions

* Handle on-chain NonceManager revert

* AA-419: "signature" -> "authorizationData" & "calldata" -> "executionData" (#30)

* AA-419: "signature" -> "authorizationData", "calldata" -> "executionData"

* AA-417: Fix ignored paymaster revert (#31)

* AA-419: "signature" -> "authorizationData", "calldata" -> "executionData"

* AA-422: Fix transaction hash function - add all missing fields (#32)

* AA-422: Fix transaction hash function - add all missing fields

* AA-425: Directly execute call frames without "ApplyMessage" wrapper & AA-432: Penalization gas postOp observability (#33)

* CallFrame

* move checkNonce

* refactor Nonce handling

* execution phase

* refactor prepare-msgs

* refactor json-abi

* fix errors

* Make 'sumGas' accept vararg inputs

* Extract 'performNonceCheckFrameRip7712' function

* Update comment

* Remove rudimentary modifications to the original ApplyMessage flow

* Account for CallDataGas in 'postOp'; move code to Tx type interface

---------

Co-authored-by: Alex Forshtat <[email protected]>

* AA-344: During block building simply skip invalid RIP-7560 transactions (#35)

* AA-344: (WIP) During block building simply skip invalid RIP-7560 transactions

* Create 'eth_getRip7560TransactionDebugInfo' API to observe late invalidation

* Remove unnecessary override

* AA-382: Inject system events (#34)

* WIP: Inject system events

* WIP: Encode the event correctly and pass relevant data

* Implement revert reason system events

* Fix crash

* Fix unhandled error

* Remove unncecessary gas fields, expose failure type in status

* Add 'ExecutionStatusExecutionAndPostOpFailure' status

* Add 'RIP7560AccountDeployed' event; add 'nonceKey' event parameter; cleanup

* AA-402: 'CallDataGasCost' is not a separate component of 'TotalGasLimit' (#36)

* AA-402: (WIP) 'CallDataGasCost' is not a separate component of 'TotalGasLimit'

* Remove

* Fix 'CumulativeGasUsed' not being calculated correctly (#38)

* Fix 'CumulativeGasUsed' not being calculated correctly

* call Prepare to initialize warm addresses

* remove prints

---------

Co-authored-by: Dror Tirosh <[email protected]>

* AA-445: Charge validation gas for calldata and repurpose 'CallDataUsedGas' as 'PreTransactionGasCost' (#39)

* AA-408 deduct gas for aatx (#28)

* AA-408 deduct gas, pay coinbase

* Fix 'CumulativeGasUsed' not being calculated correctly

* call Prepare to initialize warm addresses

* remove prints

* reformat

* PR comments

---------

Co-authored-by: Alex Forshtat <[email protected]>

* AA-414: Consume block gas limit for RIP-7560 transactions

* Remove unused function; extract 'validationPhaseUsedGas'

* Expose gas limit reached error through the debug API

* AA-405: Perform multiple static validations on an RIP-7560 transaction (#42)

* Remove print and comment

* Rename

* AA-446: Separate 'nonce' into two 256-bit values 'nonceKey' and 'nonceSequence' (#40)

* AA-446: Separate 'nonce' into two 256-bit values 'nonceKey' and 'nonceSequence'

* Fix nonce manager address

* Print nonce manager address

---------

Co-authored-by: shahafn <[email protected]>

* Include ERC-7562 tracer

Remove checking the 'OnlyTopCall' as it doesn't fit the use-case

Remove most of the string-based opcode manipulation

Fix

Construct the correct tracer object

Bring in 'OnTxEnd' and 'GetResult' functions

Missing 'OnOpcode' hook

native bundlerCollectorTracer

Rename to erc7562Tracer

Fixing tracer wip

WIP: Make 'allowed opcodes' a configurable parameter with a hex string input

WIP: Remove all inefficient code working with opcodes as strings

erc7562 tracer wip

Fixing pointer

Fixing contract size type

Fixing handleExtOpcodes

Fixing stack pointers

Changing UsedOpcodes type

Fixing ignoredOpcodes

Adding isCall(), fixing PR comments

Remving callTracer, callTracerConfig, adding erc7562TracerConfig

Detecting OOG in OnExit instead of OnOpcode

Removing unused function

Removing unused

Changing Keccak member from array to mapping

Replacing lastSeenOpcodes for lastOpWithStack

---------

Co-authored-by: Alex Forshtat <[email protected]>
Co-authored-by: Dror Tirosh <[email protected]>
Co-authored-by: Dror Tirosh <[email protected]>
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