Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions blockchain/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func NewEVMBlockContext(header *types.Header, chain ChainContext, author *common
// NewEVMTxContext creates a new transaction context for a single transaction.
func NewEVMTxContext(msg Message, header *types.Header, config *params.ChainConfig) vm.TxContext {
return vm.TxContext{
Origin: msg.ValidatedSender(),
GasPrice: new(big.Int).Set(msg.EffectiveGasPrice(header, config)),
Origin: msg.ValidatedSender(),
GasPrice: new(big.Int).Set(msg.EffectiveGasPrice(header, config)),
BlobHashes: msg.BlobHashes(),
}
}

Expand Down
1 change: 1 addition & 0 deletions blockchain/state_transition.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,7 @@ type Message interface {
Execute(vm types.VM, stateDB types.StateDB, currentBlockNumber uint64, gas uint64, value *big.Int) ([]byte, uint64, error)

AccessList() types.AccessList
BlobHashes() []common.Hash
AuthList() []types.SetCodeAuthorization
}

Expand Down
14 changes: 10 additions & 4 deletions blockchain/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,12 +314,18 @@ func enable6780(jt *JumpTable) {
}

// opBlobHash implements the BLOBHASH opcode
// Since blob data is generated in dank sharding, opBlobHash will perform only the default action of setting the top of the stack as zero
// as long as the blob txType is not fully supported in Kaia.
// This works as follows:
// - Since Cancun: Must return zero.
// - Since Osaka: Returns BlobHashes if the transaction is BlobTx.
// Before Osaka, there was no BlobTx after all, so the logic below is applicable to before and after Osaka.
func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
index := scope.Stack.peek()
index.Clear()

if index.LtUint64(uint64(len(interpreter.evm.TxContext.BlobHashes))) {
blobHash := interpreter.evm.TxContext.BlobHashes[index.Uint64()]
index.SetBytes32(blobHash[:])
} else {
index.Clear()
}
return nil, nil
}

Expand Down
5 changes: 3 additions & 2 deletions blockchain/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,9 @@ type BlockContext struct {
// All fields can change between transactions.
type TxContext struct {
// Message information
Origin common.Address // Provides information for ORIGIN
GasPrice *big.Int // Provides information for GASPRICE
Origin common.Address // Provides information for ORIGIN (0x32)
GasPrice *big.Int // Provides information for GASPRICE (0x3a)
BlobHashes []common.Hash // Provides information for BLOBHASH (0x49)
}

// EVM is the Ethereum Virtual Machine base object and provides
Expand Down
21 changes: 13 additions & 8 deletions blockchain/vm/instructions_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,18 +299,23 @@ func TestBlobHash(t *testing.T) {
name string
idx uint64
expect common.Hash
// hashes []common.Hash // Kaia doesn't support blobHashes
hashes []common.Hash
}
zero := common.Hash{0}
var (
zero = common.Hash{0}
one = common.Hash{1}
two = common.Hash{2}
three = common.Hash{3}
)
for _, tt := range []testcase{
{name: "[{1}]", idx: 0, expect: zero},
{name: "[1,{2},3]", idx: 2, expect: zero},
{name: "out-of-bounds (empty)", idx: 10, expect: zero},
{name: "out-of-bounds", idx: 25, expect: zero},
{name: "out-of-bounds (nil)", idx: 25, expect: zero},
{name: "[{1}]", idx: 0, expect: one, hashes: []common.Hash{one}},
{name: "[1,{2},3]", idx: 2, expect: three, hashes: []common.Hash{one, two, three}},
{name: "out-of-bounds (empty)", idx: 10, expect: zero, hashes: []common.Hash{}},
{name: "out-of-bounds", idx: 25, expect: zero, hashes: []common.Hash{one, two, three}},
{name: "out-of-bounds (nil)", idx: 25, expect: zero, hashes: nil},
} {
var (
env = NewEVM(BlockContext{}, TxContext{}, nil, params.TestChainConfig, &Config{})
env = NewEVM(BlockContext{}, TxContext{BlobHashes: tt.hashes}, nil, params.TestChainConfig, &Config{})
stack = newstack()
pc = uint64(0)
evmInterpreter = env.interpreter
Expand Down
5 changes: 3 additions & 2 deletions blockchain/vm/runtime/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ import (

func NewEnv(cfg *Config) *vm.EVM {
txContext := vm.TxContext{
Origin: cfg.Origin,
GasPrice: cfg.GasPrice,
Origin: cfg.Origin,
GasPrice: cfg.GasPrice,
BlobHashes: cfg.BlobHashes,
}
blockContext := vm.BlockContext{
CanTransfer: blockchain.CanTransfer,
Expand Down
1 change: 1 addition & 0 deletions blockchain/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Config struct {
Debug bool
EVMConfig vm.Config
BaseFee *big.Int
BlobHashes []common.Hash

State *state.StateDB
GetHashFn func(n uint64) common.Hash
Expand Down