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

Non-osaka EOF changes #179

Merged
merged 2 commits into from
Dec 17, 2024
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
14 changes: 13 additions & 1 deletion evms/besu.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,13 @@ func (vm *BesuVM) ParseStateRoot(data []byte) (string, error) {
root := string(data[start : start+2+64])
return root, nil
}
return "", errors.New("besu: no stateroot found")
start = strings.Index(string(data), `"stateRoot":"`)
Copy link
Owner

Choose a reason for hiding this comment

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

Do you have any example statetest which makes besu emit this? Or is that an opcoming change?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

hyperledger/besu#8006 - will land in main after new year

if start > 0 {
start = start + len(`"stateRoot":"`)
root := string(data[start : start+2+64])
return root, nil
}
return "", errors.New("besu: no stateroot/posthash found")
}

// feed reads from the reader, does some geth-specific filtering and
Expand All @@ -128,6 +134,10 @@ func (evm *BesuVM) copyUntilEnd(out io.Writer, input io.Reader) stateRoot {
var elem opLog
for scanner.Next(&elem) == nil {
// If we have a stateroot, we're done
if len(elem.StateRoot1) != 0 {
stateRoot.StateRoot = elem.StateRoot1
break
}
if len(elem.StateRoot2) != 0 {
stateRoot.StateRoot = elem.StateRoot2
break
Expand All @@ -142,6 +152,8 @@ func (evm *BesuVM) copyUntilEnd(out io.Writer, input io.Reader) stateRoot {
fmt.Fprintf(os.Stderr, "Error writing to out: %v\n", err)
return stateRoot
}
elem.FunctionDepth = 0 // function depth is optional and "gets dirty" if not set
elem.Section = 0
}
root, _ := json.Marshal(stateRoot)
if _, err := out.Write(append(root, '\n')); err != nil {
Expand Down
78 changes: 51 additions & 27 deletions evms/gen_oplog.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion evms/geth.go
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ func (evm *GethEVM) copyUntilEnd(out io.Writer, input io.Reader) stateRoot {
if current == nil { // final flush
return
}
if prev.Pc == current.Pc && prev.Depth == current.Depth {
if prev.Pc == current.Pc && prev.Depth == current.Depth && prev.FunctionDepth == current.FunctionDepth {
// Yup, that happened here. Set the error and continue
prev = nil
} else {
Expand Down
24 changes: 21 additions & 3 deletions evms/marshalling.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,32 @@ func CustomMarshal(log *opLog) []byte {
b = append(b, []byte(`,"pc":`)...)
b = strconv.AppendUint(b, uint64(log.Pc), 10)

if !IgnoreEOF {
// code section, if not zero
if log.Section != 0 {
b = append(b, []byte(`,"section":`)...)
b = strconv.AppendUint(b, uint64(log.Section), 10)
}

// function call depth, if not zero
if log.FunctionDepth != 0 {
b = append(b, []byte(`,"functionDepth":`)...)
b = strconv.AppendUint(b, uint64(log.FunctionDepth), 10)
}
}

// Gas remaining
b = append(b, []byte(`,"gas":`)...)
b = strconv.AppendUint(b, uint64(log.Gas), 10)

// Op
b = append(b, []byte(`,"op":`)...)
b = strconv.AppendUint(b, uint64(log.Op), 10)
b = append(b, []byte(`,"opName":"`)...)
b = append(b, []byte(`,"op":"0x`)...)
opcode := uint64(log.Op)
if opcode < 0x10 {
b = append(b, []byte(`0`)...)
}
b = strconv.AppendUint(b, opcode, 16)
b = append(b, []byte(`","opName":"`)...)
b = append(b, []byte(log.Op.String())...)
b = append(b, '"')

Expand Down
22 changes: 12 additions & 10 deletions evms/oplog.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,18 @@ import (
// - also has the ability to soup up a stateroot,
// - and is a bit more lax in parsing (e.g allows negative refund)
type opLog struct {
Pc uint64 `json:"pc"`
Op vm.OpCode `json:"op"`
Gas uint64 `json:"gas"`
GasCost uint64 `json:"gasCost"`
Memory []byte `json:"memory,omitempty"`
MemorySize int `json:"memSize"`
Stack []uint256.Int `json:"stack"`
ReturnData []byte `json:"returnData,omitempty"`
Depth int `json:"depth"`
Err error `json:"-"`
Pc uint64 `json:"pc"`
Section uint64 `json:"section,omitempty"`
Op vm.OpCode `json:"op"`
Gas uint64 `json:"gas"`
GasCost uint64 `json:"gasCost"`
Memory []byte `json:"memory,omitempty"`
MemorySize int `json:"memSize"`
Stack []uint256.Int `json:"stack"`
ReturnData []byte `json:"returnData,omitempty"`
Depth int `json:"depth"`
FunctionDepth int `json:"functionDepth,omitempty"`
Err error `json:"-"`

// stateroot as output by geth, reth, eels, nethermind
StateRoot1 string `json:"stateRoot"`
Expand Down
3 changes: 3 additions & 0 deletions evms/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ const (

// Besu sometimes reports GasCost of 0x7fffffffffffffff, along with ,"error":"Out of gas"
ClearGascost = true

// EOF is not universally ready
IgnoreEOF = false //FIXME
)

// StdErrOutput runs the command and returns its standard error.
Expand Down
88 changes: 85 additions & 3 deletions ops/forks.go
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,48 @@ var (
CREATE, CALL, CALLCODE, RETURN, DELEGATECALL, CREATE2, STATICCALL, REVERT, INVALID,
SELFDESTRUCT},
}
prague = Fork{
Name: "Prague",
//ActivePrecompiles: nil,
ValidOpcodes: []OpCode{
STOP, ADD, MUL, SUB, DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD, EXP, SIGNEXTEND,
LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, NOT, BYTE, SHL, SHR, SAR,
KECCAK256,
ADDRESS, BALANCE, ORIGIN, CALLER, CALLVALUE, CALLDATALOAD, CALLDATASIZE, CALLDATACOPY, CODESIZE, CODECOPY, GASPRICE, EXTCODESIZE, EXTCODECOPY, RETURNDATASIZE, RETURNDATACOPY, EXTCODEHASH, BLOCKHASH,
COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, SELFBALANCE, BASEFEE, BLOBHASH, BLOBBASEFEE,
POP, MLOAD, MSTORE, MSTORE8, SLOAD, SSTORE, JUMP, JUMPI, PC, MSIZE, GAS, JUMPDEST, TLOAD, TSTORE, MCOPY,
PUSH0, PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16,
PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32,
DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16,
SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16,
LOG0, LOG1, LOG2, LOG3, LOG4,
CREATE, CALL, CALLCODE, RETURN, DELEGATECALL, CREATE2, STATICCALL, REVERT, INVALID,
RETURNDATACOPY,
SELFDESTRUCT},
}
osaka = Fork{
Name: "Osaka",
//ActivePrecompiles: nil,
ValidOpcodes: []OpCode{
STOP, ADD, MUL, SUB, DIV, SDIV, MOD, SMOD, ADDMOD, MULMOD, EXP, SIGNEXTEND,
LT, GT, SLT, SGT, EQ, ISZERO, AND, OR, XOR, NOT, BYTE, SHL, SHR, SAR,
KECCAK256,
ADDRESS, BALANCE, ORIGIN, CALLER, CALLVALUE, CALLDATALOAD, CALLDATASIZE, CALLDATACOPY, CODESIZE, CODECOPY, GASPRICE, EXTCODESIZE, EXTCODECOPY, RETURNDATASIZE, RETURNDATACOPY, EXTCODEHASH, BLOCKHASH,
COINBASE, TIMESTAMP, NUMBER, DIFFICULTY, GASLIMIT, CHAINID, SELFBALANCE, BASEFEE, BLOBHASH, BLOBBASEFEE,
POP, MLOAD, MSTORE, MSTORE8, SLOAD, SSTORE, JUMP, JUMPI, PC, MSIZE, GAS, JUMPDEST, TLOAD, TSTORE, MCOPY,
PUSH0, PUSH1, PUSH2, PUSH3, PUSH4, PUSH5, PUSH6, PUSH7, PUSH8, PUSH9, PUSH10, PUSH11, PUSH12, PUSH13, PUSH14, PUSH15, PUSH16,
PUSH17, PUSH18, PUSH19, PUSH20, PUSH21, PUSH22, PUSH23, PUSH24, PUSH25, PUSH26, PUSH27, PUSH28, PUSH29, PUSH30, PUSH31, PUSH32,
DUP1, DUP2, DUP3, DUP4, DUP5, DUP6, DUP7, DUP8, DUP9, DUP10, DUP11, DUP12, DUP13, DUP14, DUP15, DUP16,
SWAP1, SWAP2, SWAP3, SWAP4, SWAP5, SWAP6, SWAP7, SWAP8, SWAP9, SWAP10, SWAP11, SWAP12, SWAP13, SWAP14, SWAP15, SWAP16,
LOG0, LOG1, LOG2, LOG3, LOG4,
DATALOAD, DATALOADN, DATASIZE, DATACOPY, // New for Osaka
RJUMP, RJUMPI, RJUMPV, CALLF, RETF, JUMPF, DUPN, SWAPN, EXCHANGE, EOFCREATE, RETURNCONTRACT, // New for Osaka
CREATE, CALL, CALLCODE, RETURN, DELEGATECALL, CREATE2, STATICCALL, REVERT, INVALID,
RETURNDATACOPY, EXTCALL, EXTDELEGATECALL, EXTSTATICCALL, // New for Osaka
SELFDESTRUCT},
}
forks = []Fork{
istanbul, berlin, london, merged, shanghai, cancun,
istanbul, berlin, london, merged, shanghai, cancun, prague, osaka,
}
)

Expand Down Expand Up @@ -266,6 +306,42 @@ func LookupRules(fork string) params.Rules {
IsShanghai: true,
IsCancun: true,
}
case "Prague":
return params.Rules{
IsHomestead: true,
IsEIP150: true,
IsEIP155: true,
IsEIP158: true,
IsByzantium: true,
IsConstantinople: true,
IsPetersburg: true,
IsIstanbul: true,
IsBerlin: true,
IsLondon: true,
IsMerge: true,
IsShanghai: true,
IsCancun: true,
IsPrague: true,
}
case "Osaka":
return params.Rules{
IsHomestead: true,
IsEIP150: true,
IsEIP155: true,
IsEIP158: true,
IsByzantium: true,
IsConstantinople: true,
IsPetersburg: true,
IsIstanbul: true,
IsBerlin: true,
IsLondon: true,
IsMerge: true,
IsShanghai: true,
IsCancun: true,
IsPrague: true,
// Depends on Geth EOF support
// IsOsaka: true,
}
default:
panic(fmt.Sprintf("Unsupported: %v", fork))

Expand Down Expand Up @@ -295,6 +371,9 @@ func LookupChainConfig(fork string) (*params.ChainConfig, error) {
var merge = cpy(london, func(p *params.ChainConfig) { p.MergeNetsplitBlock = big.NewInt(0) })
var shanghai = cpy(merge, func(p *params.ChainConfig) { p.ShanghaiTime = new(uint64) })
var cancun = cpy(shanghai, func(p *params.ChainConfig) { p.CancunTime = new(uint64) })
var prague = cpy(cancun, func(p *params.ChainConfig) { p.PragueTime = new(uint64) })
// Depends on Geth EOF support
//var osaka = cpy(prague, func(p *params.ChainConfig) { p.OsakaTime = new(uint64) })

switch fork {
case "Frontier":
Expand All @@ -321,8 +400,11 @@ func LookupChainConfig(fork string) (*params.ChainConfig, error) {
return merge, nil
case "Shanghai":
return shanghai, nil
case "Cancun":
return cancun, nil
case "Prague":
return prague, nil
// Depends on Geth EOF support
//case "Osaka":
// return osaka, nil
}
return nil, fmt.Errorf("unknown fork %v", fork)
}
Loading