Skip to content

Commit

Permalink
cmd: core: apply review comments, fix t8n tool
Browse files Browse the repository at this point in the history
  • Loading branch information
MariusVanDerWijden committed Sep 21, 2023
1 parent 44d6276 commit a09c7f1
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 9 deletions.
2 changes: 2 additions & 0 deletions cmd/evm/internal/t8ntool/execution.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
// If excessBlobGas is defined, add it to the vmContext.
if pre.Env.ExcessBlobGas != nil {
vmContext.ExcessBlobGas = pre.Env.ExcessBlobGas
vmContext.BlobFee = eip4844.CalcBlobFee(*pre.Env.ExcessBlobGas)
} else {
// If it is not explicitly defined, but we have the parent values, we try
// to calculate it ourselves.
Expand All @@ -174,6 +175,7 @@ func (pre *Prestate) Apply(vmConfig vm.Config, chainConfig *params.ChainConfig,
if parentExcessBlobGas != nil && parentBlobGasUsed != nil {
excessBlobGas := eip4844.CalcExcessBlobGas(*parentExcessBlobGas, *parentBlobGasUsed)
vmContext.ExcessBlobGas = &excessBlobGas
vmContext.BlobFee = eip4844.CalcBlobFee(excessBlobGas)
}
}
// If DAO is supported/enabled, we need to handle it here. In geth 'proper', it's
Expand Down
4 changes: 3 additions & 1 deletion cmd/evm/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,8 @@ func runCmd(ctx *cli.Context) error {
sender = common.BytesToAddress([]byte("sender"))
receiver = common.BytesToAddress([]byte("receiver"))
preimages = ctx.Bool(DumpFlag.Name)
blobHashes []common.Hash // TODO (MariusVanDerWijden) implement blob hashes in state tests
blobHashes []common.Hash // TODO (MariusVanDerWijden) implement blob hashes in state tests
blobFee = new(big.Int) // TODO (MariusVanDerWijden) implement blob fee in state tests
)
if ctx.Bool(MachineFlag.Name) {
tracer = logger.NewJSONLogger(logconfig, os.Stdout)
Expand Down Expand Up @@ -221,6 +222,7 @@ func runCmd(ctx *cli.Context) error {
Coinbase: genesisConfig.Coinbase,
BlockNumber: new(big.Int).SetUint64(genesisConfig.Number),
BlobHashes: blobHashes,
BlobFee: blobFee,
EVMConfig: vm.Config{
Tracer: tracer,
},
Expand Down
8 changes: 4 additions & 4 deletions core/vm/eips.go
Original file line number Diff line number Diff line change
Expand Up @@ -282,8 +282,8 @@ func opBlobHash(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([
return nil, nil
}

// opBlobfee implements BLOBFEE opcode
func opBlobfee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
// opBlobFee implements BLOBBASEFEE opcode
func opBlobFee(pc *uint64, interpreter *EVMInterpreter, scope *ScopeContext) ([]byte, error) {
blobFee, _ := uint256.FromBig(interpreter.evm.Context.BlobFee)
scope.Stack.push(blobFee)
return nil, nil
Expand All @@ -298,8 +298,8 @@ func enable4844(jt *JumpTable) {
minStack: minStack(1, 1),
maxStack: maxStack(1, 1),
}
jt[BLOBFEE] = &operation{
execute: opBlobfee,
jt[BLOBBASEFEE] = &operation{
execute: opBlobFee,
constantGas: GasQuickStep,
minStack: minStack(0, 1),
maxStack: maxStack(0, 1),
Expand Down
2 changes: 1 addition & 1 deletion core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ type BlockContext struct {
Time uint64 // Provides information for TIME
Difficulty *big.Int // Provides information for DIFFICULTY
BaseFee *big.Int // Provides information for BASEFEE
BlobFee *big.Int // Provides information for BLOBFEE
BlobFee *big.Int // Provides information for BLOBBASEFEE
Random *common.Hash // Provides information for PREVRANDAO
ExcessBlobGas *uint64 // ExcessBlobGas field in the header, needed to compute the data
}
Expand Down
6 changes: 3 additions & 3 deletions core/vm/opcodes.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ const (
SELFBALANCE OpCode = 0x47
BASEFEE OpCode = 0x48
BLOBHASH OpCode = 0x49
BLOBFEE OpCode = 0x4a
BLOBBASEFEE OpCode = 0x4a
)

// 0x50 range - 'storage' and execution.
Expand Down Expand Up @@ -288,7 +288,7 @@ var opCodeToString = map[OpCode]string{
SELFBALANCE: "SELFBALANCE",
BASEFEE: "BASEFEE",
BLOBHASH: "BLOBHASH",
BLOBFEE: "BLOBFEE",
BLOBBASEFEE: "BLOBBASEFEE",

// 0x50 range - 'storage' and execution.
POP: "POP",
Expand Down Expand Up @@ -446,7 +446,7 @@ var stringToOp = map[string]OpCode{
"CHAINID": CHAINID,
"BASEFEE": BASEFEE,
"BLOBHASH": BLOBHASH,
"BLOBFEE": BLOBFEE,
"BLOBBASEFEE": BLOBBASEFEE,
"DELEGATECALL": DELEGATECALL,
"STATICCALL": STATICCALL,
"CODESIZE": CODESIZE,
Expand Down
1 change: 1 addition & 0 deletions core/vm/runtime/env.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ func NewEnv(cfg *Config) *vm.EVM {
Difficulty: cfg.Difficulty,
GasLimit: cfg.GasLimit,
BaseFee: cfg.BaseFee,
BlobFee: cfg.BlobFee,
Random: cfg.Random,
}

Expand Down
4 changes: 4 additions & 0 deletions core/vm/runtime/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ type Config struct {
Debug bool
EVMConfig vm.Config
BaseFee *big.Int
BlobFee *big.Int
BlobHashes []common.Hash
Random *common.Hash

Expand Down Expand Up @@ -95,6 +96,9 @@ func setDefaults(cfg *Config) {
if cfg.BaseFee == nil {
cfg.BaseFee = big.NewInt(params.InitialBaseFee)
}
if cfg.BlobFee == nil {
cfg.BlobFee = new(big.Int)
}
}

// Execute executes the code using the input as call data during the execution.
Expand Down
4 changes: 4 additions & 0 deletions internal/ethapi/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -998,6 +998,7 @@ type BlockOverrides struct {
Coinbase *common.Address
Random *common.Hash
BaseFee *hexutil.Big
BlobFee *hexutil.Big
}

// Apply overrides the given header fields into the given block context.
Expand Down Expand Up @@ -1026,6 +1027,9 @@ func (diff *BlockOverrides) Apply(blockCtx *vm.BlockContext) {
if diff.BaseFee != nil {
blockCtx.BaseFee = diff.BaseFee.ToInt()
}
if diff.BlobFee != nil {
blockCtx.BlobFee = diff.BlobFee.ToInt()
}
}

// ChainContextBackend provides methods required to implement ChainContext.
Expand Down

0 comments on commit a09c7f1

Please sign in to comment.