Skip to content

Commit 25464f7

Browse files
authored
Merge branch 'master' into debug-block
2 parents bb1d238 + 57fe4b7 commit 25464f7

File tree

10 files changed

+334
-57
lines changed

10 files changed

+334
-57
lines changed

arbitrum/multigas/resources.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package multigas
22

33
import (
44
"encoding/json"
5+
"fmt"
56
"io"
67
"math/bits"
78

@@ -25,6 +26,14 @@ const (
2526
NumResourceKind
2627
)
2728

29+
// CheckResourceKind checks whether the given id is a valid resource.
30+
func CheckResourceKind(id uint8) (ResourceKind, error) {
31+
if id <= uint8(ResourceKindUnknown) || id >= uint8(NumResourceKind) {
32+
return ResourceKindUnknown, fmt.Errorf("invalid resource id: %v", id)
33+
}
34+
return ResourceKind(id), nil
35+
}
36+
2837
// MultiGas tracks gas usage across multiple resource kinds, while also
2938
// maintaining a single-dimensional total gas sum and refund amount.
3039
type MultiGas struct {
@@ -68,11 +77,6 @@ func MultiGasFromPairs(pairs ...Pair) MultiGas {
6877
return mg
6978
}
7079

71-
// UnknownGas returns a MultiGas initialized with unknown gas.
72-
func UnknownGas(amount uint64) MultiGas {
73-
return NewMultiGas(ResourceKindUnknown, amount)
74-
}
75-
7680
// ComputationGas returns a MultiGas initialized with computation gas.
7781
func ComputationGas(amount uint64) MultiGas {
7882
return NewMultiGas(ResourceKindComputation, amount)

arbitrum/multigas/resources_test.go

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,24 @@ import (
1010
"github.com/ethereum/go-ethereum/rlp"
1111
)
1212

13+
func TestCheckResourceKind(t *testing.T) {
14+
_, err := CheckResourceKind(0)
15+
if err == nil {
16+
t.Errorf("expected error, got nil")
17+
}
18+
_, err = CheckResourceKind(uint8(NumResourceKind))
19+
if err == nil {
20+
t.Errorf("expected error, got nil")
21+
}
22+
resource, err := CheckResourceKind(uint8(ResourceKindComputation))
23+
if err != nil {
24+
t.Errorf("unexpected error, got %v", err)
25+
}
26+
if resource != ResourceKindComputation {
27+
t.Errorf("expected computation resource, got %v", resource)
28+
}
29+
}
30+
1331
func TestZeroGas(t *testing.T) {
1432
zero := ZeroGas()
1533
if zero.SingleGas() != 0 {

arbitrum/recordingdb.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import (
1414
"github.com/ethereum/go-ethereum/core/rawdb"
1515
"github.com/ethereum/go-ethereum/core/state"
1616
"github.com/ethereum/go-ethereum/core/types"
17+
"github.com/ethereum/go-ethereum/core/vm"
1718
"github.com/ethereum/go-ethereum/crypto"
1819
"github.com/ethereum/go-ethereum/ethdb"
1920
"github.com/ethereum/go-ethereum/log"
@@ -334,7 +335,7 @@ func (r *RecordingDatabase) GetOrRecreateState(ctx context.Context, header *type
334335
returnedBlockNumber := header.Number.Uint64()
335336
for ctx.Err() == nil {
336337
var block *types.Block
337-
state, block, err = AdvanceStateByBlock(ctx, r.bc, state, blockToRecreate, prevHash, logFunc)
338+
state, block, _, err = AdvanceStateByBlock(ctx, r.bc, state, blockToRecreate, prevHash, logFunc, vm.Config{})
338339
if err != nil {
339340
return nil, err
340341
}

arbitrum/recreatestate.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -69,20 +69,20 @@ func FindLastAvailableState(ctx context.Context, bc *core.BlockChain, stateFor S
6969
return state, currentHeader, release, ctx.Err()
7070
}
7171

72-
func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, blockToRecreate uint64, prevBlockHash common.Hash, logFunc StateBuildingLogFunction) (*state.StateDB, *types.Block, error) {
72+
func AdvanceStateByBlock(ctx context.Context, bc *core.BlockChain, state *state.StateDB, blockToRecreate uint64, prevBlockHash common.Hash, logFunc StateBuildingLogFunction, vmConfig vm.Config) (*state.StateDB, *types.Block, types.Receipts, error) {
7373
block := bc.GetBlockByNumber(blockToRecreate)
7474
if block == nil {
75-
return nil, nil, fmt.Errorf("block not found while recreating: %d", blockToRecreate)
75+
return nil, nil, nil, fmt.Errorf("block not found while recreating: %d", blockToRecreate)
7676
}
7777
if block.ParentHash() != prevBlockHash {
78-
return nil, nil, fmt.Errorf("reorg detected: number %d expectedPrev: %v foundPrev: %v", blockToRecreate, prevBlockHash, block.ParentHash())
78+
return nil, nil, nil, fmt.Errorf("reorg detected: number %d expectedPrev: %v foundPrev: %v", blockToRecreate, prevBlockHash, block.ParentHash())
7979
}
8080
if logFunc != nil {
8181
logFunc(block.Header(), true)
8282
}
83-
_, err := bc.Processor().Process(block, state, vm.Config{})
83+
result, err := bc.Processor().Process(block, state, vmConfig)
8484
if err != nil {
85-
return nil, nil, fmt.Errorf("failed recreating state for block %d : %w", blockToRecreate, err)
85+
return nil, nil, nil, fmt.Errorf("failed recreating state for block %d : %w", blockToRecreate, err)
8686
}
87-
return state, block, nil
87+
return state, block, result.Receipts, nil
8888
}

core/reverted_tx_gas.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// Copyright 2020 The go-ethereum Authors
2+
// This file is part of the go-ethereum library.
3+
//
4+
// The go-ethereum library is free software: you can redistribute it and/or modify
5+
// it under the terms of the GNU Lesser General Public License as published by
6+
// the Free Software Foundation, either version 3 of the License, or
7+
// (at your option) any later version.
8+
//
9+
// The go-ethereum library is distributed in the hope that it will be useful,
10+
// but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
// GNU Lesser General Public License for more details.
13+
//
14+
// You should have received a copy of the GNU Lesser General Public License
15+
// along with the go-ethereum library. If not, see <http://www.gnu.org/licenses/>.
16+
17+
package core
18+
19+
import (
20+
"github.com/ethereum/go-ethereum/common"
21+
)
22+
23+
// RevertedTxGasUsed maps specific transaction hashes that have been previously reverted to the amount
24+
// of GAS used by that specific transaction alone.
25+
var RevertedTxGasUsed = map[common.Hash]uint64{
26+
// Arbitrum Sepolia (chain_id=421614). Tx timestamp: Oct-13-2025 03:30:36 AM +UTC
27+
common.HexToHash("0x58df300a7f04fe31d41d24672786cbe1c58b4f3d8329d0d74392d814dd9f7e40"): 45174,
28+
}

core/state_transition.go

Lines changed: 57 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -681,34 +681,43 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
681681
ret []byte
682682
vmerr error // vm errors do not effect consensus and are therefore not assigned to err
683683
)
684-
if contractCreation {
685-
deployedContract = &common.Address{}
686-
ret, *deployedContract, st.gasRemaining, multiGas, vmerr = st.evm.Create(msg.From, msg.Data, st.gasRemaining, value)
687-
usedMultiGas = usedMultiGas.SaturatingAdd(multiGas)
688-
} else {
689-
// Increment the nonce for the next transaction.
690-
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1, tracing.NonceChangeEoACall)
691684

692-
// Apply EIP-7702 authorizations.
693-
if msg.SetCodeAuthorizations != nil {
694-
for _, auth := range msg.SetCodeAuthorizations {
695-
// Note errors are ignored, we simply skip invalid authorizations here.
696-
st.applyAuthorization(&auth)
685+
// Check against hardcoded transaction hashes that have previously reverted, so instead
686+
// of executing the transaction we just update state nonce and remaining gas to avoid
687+
// state divergence.
688+
usedMultiGas, vmerr = st.handleRevertedTx(msg, usedMultiGas)
689+
690+
// vmerr is only not nil when we find a previous reverted transaction
691+
if vmerr == nil {
692+
if contractCreation {
693+
deployedContract = &common.Address{}
694+
ret, *deployedContract, st.gasRemaining, multiGas, vmerr = st.evm.Create(msg.From, msg.Data, st.gasRemaining, value)
695+
usedMultiGas = usedMultiGas.SaturatingAdd(multiGas)
696+
} else {
697+
// Increment the nonce for the next transaction.
698+
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1, tracing.NonceChangeEoACall)
699+
700+
// Apply EIP-7702 authorizations.
701+
if msg.SetCodeAuthorizations != nil {
702+
for _, auth := range msg.SetCodeAuthorizations {
703+
// Note errors are ignored, we simply skip invalid authorizations here.
704+
st.applyAuthorization(&auth)
705+
}
697706
}
698-
}
699707

700-
// Perform convenience warming of sender's delegation target. Although the
701-
// sender is already warmed in Prepare(..), it's possible a delegation to
702-
// the account was deployed during this transaction. To handle correctly,
703-
// simply wait until the final state of delegations is determined before
704-
// performing the resolution and warming.
705-
if addr, ok := types.ParseDelegation(st.state.GetCode(*msg.To)); ok {
706-
st.state.AddAddressToAccessList(addr)
707-
}
708+
// Perform convenience warming of sender's delegation target. Although the
709+
// sender is already warmed in Prepare(..), it's possible a delegation to
710+
// the account was deployed during this transaction. To handle correctly,
711+
// simply wait until the final state of delegations is determined before
712+
// performing the resolution and warming.
713+
if addr, ok := types.ParseDelegation(st.state.GetCode(*msg.To)); ok {
714+
st.state.AddAddressToAccessList(addr)
715+
}
708716

709-
// Execute the transaction's call.
710-
ret, st.gasRemaining, multiGas, vmerr = st.evm.Call(msg.From, st.to(), msg.Data, st.gasRemaining, value)
711-
usedMultiGas = usedMultiGas.SaturatingAdd(multiGas)
717+
// Execute the transaction's call.
718+
ret, st.gasRemaining, multiGas, vmerr = st.evm.Call(msg.From, st.to(), msg.Data, st.gasRemaining, value)
719+
usedMultiGas = usedMultiGas.SaturatingAdd(multiGas)
720+
}
712721
}
713722

714723
// Refund the gas that was held to limit the amount of computation done.
@@ -787,6 +796,30 @@ func (st *stateTransition) execute() (*ExecutionResult, error) {
787796
}, nil
788797
}
789798

799+
// handleRevertedTx attempts to process a reverted transaction. It returns
800+
// ErrExecutionReverted with the updated multiGas if a matching reverted
801+
// tx is found; otherwise, it returns nil error with unchangedmultiGas
802+
func (st *stateTransition) handleRevertedTx(msg *Message, usedMultiGas multigas.MultiGas) (multigas.MultiGas, error) {
803+
if msg.Tx == nil {
804+
return usedMultiGas, nil
805+
}
806+
807+
txHash := msg.Tx.Hash()
808+
if l2GasUsed, ok := RevertedTxGasUsed[txHash]; ok {
809+
st.state.SetNonce(msg.From, st.state.GetNonce(msg.From)+1, tracing.NonceChangeEoACall)
810+
811+
// Calculate adjusted gas since l2GasUsed contains params.TxGas
812+
adjustedGas := l2GasUsed - params.TxGas
813+
st.gasRemaining -= adjustedGas
814+
815+
// Update multigas and return ErrExecutionReverted error
816+
usedMultiGas = usedMultiGas.SaturatingAdd(multigas.ComputationGas(adjustedGas))
817+
return usedMultiGas, vm.ErrExecutionReverted
818+
}
819+
820+
return usedMultiGas, nil
821+
}
822+
790823
// validateAuthorization validates an EIP-7702 authorization against the state.
791824
func (st *stateTransition) validateAuthorization(auth *types.SetCodeAuthorization) (authority common.Address, err error) {
792825
// Verify chain ID is null or equal to current chain ID.

core/vm/gas_table.go

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -304,8 +304,7 @@ func gasKeccak256(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memor
304304
if wordGas, overflow = math.SafeMul(toWordSize(wordGas), params.Keccak256WordGas); overflow {
305305
return multigas.ZeroGas(), ErrGasUintOverflow
306306
}
307-
// TODO(NIT-3484): Update multi dimensional gas here
308-
if multiGas, overflow = multiGas.SafeIncrement(multigas.ResourceKindUnknown, wordGas); overflow {
307+
if multiGas, overflow = multiGas.SafeIncrement(multigas.ResourceKindComputation, wordGas); overflow {
309308
return multigas.ZeroGas(), ErrGasUintOverflow
310309
}
311310
return multiGas, nil
@@ -402,8 +401,7 @@ func gasExpFrontier(evm *EVM, contract *Contract, stack *Stack, mem *Memory, mem
402401
if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow {
403402
return multigas.ZeroGas(), ErrGasUintOverflow
404403
}
405-
// TODO(NIT-3484): Update multi dimensional gas here
406-
return multigas.UnknownGas(gas), nil
404+
return multigas.ComputationGas(gas), nil
407405
}
408406

409407
func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (multigas.MultiGas, error) {
@@ -416,8 +414,7 @@ func gasExpEIP158(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memor
416414
if gas, overflow = math.SafeAdd(gas, params.ExpGas); overflow {
417415
return multigas.ZeroGas(), ErrGasUintOverflow
418416
}
419-
// TODO(NIT-3484): Update multi dimensional gas here
420-
return multigas.UnknownGas(gas), nil
417+
return multigas.ComputationGas(gas), nil
421418
}
422419

423420
func gasCall(evm *EVM, contract *Contract, stack *Stack, mem *Memory, memorySize uint64) (multigas.MultiGas, error) {

node/database.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type DatabaseOptions struct {
4141
ReadOnly bool // if true, no writes can be performed
4242

4343
PebbleExtraOptions *pebble.ExtraOptions
44+
NoFreezer bool
4445
}
4546

4647
type InternalOpenOptions struct {
@@ -59,6 +60,9 @@ func OpenDatabase(o InternalOpenOptions) (ethdb.Database, error) {
5960
if err != nil {
6061
return nil, err
6162
}
63+
if o.DatabaseOptions.NoFreezer {
64+
return rawdb.NewDatabase(kvdb), nil
65+
}
6266
opts := rawdb.OpenOptions{
6367
Ancient: o.AncientsDirectory,
6468
Era: o.EraDirectory,

signer/core/apitypes/types.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type SendTxArgs struct {
108108
BlobHashes []common.Hash `json:"blobVersionedHashes,omitempty"`
109109

110110
// For BlobTxType transactions with blob sidecar
111+
BlobVersion byte `json:"blobVersion,omitempty"`
111112
Blobs []kzg4844.Blob `json:"blobs,omitempty"`
112113
Commitments []kzg4844.Commitment `json:"commitments,omitempty"`
113114
Proofs []kzg4844.Proof `json:"proofs,omitempty"`
@@ -235,37 +236,56 @@ func (args *SendTxArgs) validateTxSidecar() error {
235236
if args.Commitments != nil && len(args.Commitments) != n {
236237
return fmt.Errorf("number of blobs and commitments mismatch (have=%d, want=%d)", len(args.Commitments), n)
237238
}
238-
if args.Proofs != nil && len(args.Proofs) != n {
239-
return fmt.Errorf("number of blobs and proofs mismatch (have=%d, want=%d)", len(args.Proofs), n)
240-
}
241239
if args.BlobHashes != nil && len(args.BlobHashes) != n {
242240
return fmt.Errorf("number of blobs and hashes mismatch (have=%d, want=%d)", len(args.BlobHashes), n)
243241
}
244-
242+
if args.Proofs != nil {
243+
if len(args.Proofs) == n {
244+
// v1 transaction
245+
for i, b := range args.Blobs {
246+
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
247+
return fmt.Errorf("failed to verify blob proof: %v", err)
248+
}
249+
}
250+
} else if len(args.Proofs) == n*kzg4844.CellProofsPerBlob {
251+
// v2 transaction
252+
if err := kzg4844.VerifyCellProofs(args.Blobs, args.Commitments, args.Proofs); err != nil {
253+
return fmt.Errorf("failed to verify blob proof: %v", err)
254+
}
255+
} else {
256+
return fmt.Errorf("number of proofs and blobs mismatch (have=%d, want=%d or %d)", len(args.Proofs), n, n*kzg4844.CellProofsPerBlob)
257+
}
258+
}
245259
if args.Commitments == nil {
246260
// Generate commitment and proof.
247261
commitments := make([]kzg4844.Commitment, n)
248-
proofs := make([]kzg4844.Proof, n)
262+
proofs := make([]kzg4844.Proof, 0, n)
249263
for i, b := range args.Blobs {
250264
c, err := kzg4844.BlobToCommitment(&b)
251265
if err != nil {
252266
return fmt.Errorf("blobs[%d]: error computing commitment: %v", i, err)
253267
}
254268
commitments[i] = c
255-
p, err := kzg4844.ComputeBlobProof(&b, c)
256-
if err != nil {
257-
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
269+
}
270+
if args.BlobVersion == 1 {
271+
for i, b := range args.Blobs {
272+
p, err := kzg4844.ComputeCellProofs(&b)
273+
if err != nil {
274+
return fmt.Errorf("blobs[%d]: error computing cell proof: %v", i, err)
275+
}
276+
proofs = append(proofs, p...)
277+
}
278+
} else {
279+
for i, b := range args.Blobs {
280+
p, err := kzg4844.ComputeBlobProof(&b, commitments[i])
281+
if err != nil {
282+
return fmt.Errorf("blobs[%d]: error computing proof: %v", i, err)
283+
}
284+
proofs = append(proofs, p)
258285
}
259-
proofs[i] = p
260286
}
261287
args.Commitments = commitments
262288
args.Proofs = proofs
263-
} else {
264-
for i, b := range args.Blobs {
265-
if err := kzg4844.VerifyBlobProof(&b, args.Commitments[i], args.Proofs[i]); err != nil {
266-
return fmt.Errorf("failed to verify blob proof: %v", err)
267-
}
268-
}
269289
}
270290

271291
hashes := make([]common.Hash, n)

0 commit comments

Comments
 (0)