Files
chains/evm/cevm/parallel/parallel_test.go
T
zeekayandHanzo Dev 6223789846 The cevm executor runs what cevm declines on the Go EVM
cevm's Go entry is gpu_execute_block (go_bridge.h, ABI 6); the
gpu_execute_block_v4 and gpu_free_result_v2 this package called are gone
from the library, so the native build did not link. The entry answers ok=0
for any block it does not run — any batch with code, and any refusal on
balance, nonce, price, block gas limit, revision or hashes — and that block
is the caller's. ExecuteBlock returns ErrDeclined for it, with no result,
and the executor declines the block to the Go EVM: (nil, nil), counted. A
decline is never an error, so CEVM_STRICT and ErrGPUEVMRequired are gone;
the state processor fell through on that error anyway.

Nothing wider than the 64-bit wire reaches cevm. A gas price or fee cap
above 2^64-1 crossed as 0; it, a value, a base fee or a chain id that does
not fit now declines the block, as does a tx the wire drops part of: an
access list, a blob or set-code tx, a tip above its fee cap.

Snapshot rows carry what the header asks for: keccak256 of nothing and the
empty trie root for an account that does not exist — the StateDB answers
zero, which cevm reads as saying nothing and declines — the real storage
root otherwise, and a row for the coinbase. cevm_cgo.go checks the four C
structs' sizes at compile time, so a header that grows a field cannot have
it cross as zero unnoticed.

The call into cevm is a field on the Executor, so the tests show a declined
block going to the Go EVM and a value of 2^64 never reaching cevm without
the library.

Co-authored-by: Hanzo Dev <[email protected]>
2026-09-23 09:22:10 -07:00

88 lines
2.7 KiB
Go

// Copyright (C) 2025-2026, Lux Industries Inc. All rights reserved.
// See the file LICENSE for licensing terms.
//go:build cgo && lux_cevm_native
package parallel
import (
"errors"
"math/big"
"testing"
"github.com/holiman/uint256"
"github.com/luxfi/chains/evm/cevm"
"github.com/luxfi/geth/common"
"github.com/luxfi/geth/core/tracing"
"github.com/luxfi/geth/core/types"
)
// These run against the linked library and hold it to go_bridge.h (ABI 6).
// A batch that carries code is declined on every backend the library offers:
// gpu_execute_block passes no host, so it would run the code as a message on
// its whole limit, which is not the tx's gas. Declined means ErrDeclined and
// no result.
func TestABatchWithCodeIsDeclinedOnEveryBackend(t *testing.T) {
tx := cevm.Transaction{
From: [20]byte{0x11},
To: [20]byte{0x22},
HasTo: true,
Code: []byte{0x60, 0x01, 0x60, 0x01, 0x01, 0x50, 0x00}, // 1+1, POP, STOP
GasLimit: 100_000,
GasPrice: 1,
}
for _, b := range cevm.AvailableBackends() {
t.Run(cevm.BackendName(b), func(t *testing.T) {
r, err := cevm.ExecuteBlock(b, 0, []cevm.Transaction{tx}, nil, nil)
if !errors.Is(err, cevm.ErrDeclined) {
t.Fatalf("ExecuteBlock = %v, want ErrDeclined", err)
}
if r != nil {
t.Errorf("a declined block came back with a result: %+v", r)
}
})
}
}
// A block of plain transfers from funded senders, end to end through the
// executor: a lane that runs it receipts every transfer at 21000 gas; a lane
// that does not declines it to the Go EVM. Neither is an error.
func TestAPlainTransferBlockIsReceiptedOrDeclined(t *testing.T) {
const n = 8
sdb := newState(t)
header := newHeader()
header.BaseFee = big.NewInt(1)
header.Coinbase = common.Address{0xC0}
txs := make(types.Transactions, n)
from := senders(n)
for i := range txs {
sdb.AddBalance(from[i], uint256.NewInt(1_000_000_000_000_000_000), tracing.BalanceChangeUnspecified)
to := common.Address{0xB0, byte(i + 1)} // fresh: not in the state
txs[i] = types.NewTx(&types.LegacyTx{To: &to, Value: big.NewInt(1), Gas: 21000, GasPrice: big.NewInt(1)})
}
for _, b := range cevm.AvailableBackends() {
t.Run(cevm.BackendName(b), func(t *testing.T) {
receipts, err := (&Executor{CevmBackend: b}).run(chainConfig(), header, txs, from, sdb)
if err != nil {
t.Fatalf("run: %v", err)
}
if receipts == nil {
t.Logf("%s declined the block to the Go EVM", cevm.BackendName(b))
return
}
if len(receipts) != n {
t.Fatalf("%d receipts for %d transactions", len(receipts), n)
}
for i, r := range receipts {
if r.Status != types.ReceiptStatusSuccessful || r.GasUsed != 21000 {
t.Errorf("receipt %d: status %d gas %d, want success at 21000", i, r.Status, r.GasUsed)
}
}
})
}
}