Skip to content

Commit

Permalink
core: create official prague instruction set, name eof set
Browse files Browse the repository at this point in the history
  • Loading branch information
lightclient committed Dec 12, 2024
1 parent 48da5f5 commit 846d2b8
Show file tree
Hide file tree
Showing 6 changed files with 33 additions and 27 deletions.
2 changes: 1 addition & 1 deletion cmd/evm/eofparse.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ var jt vm.JumpTable
const initcode = "INITCODE"

func init() {
jt = vm.NewPragueEOFInstructionSetForTesting()
jt = vm.NewEOFInstructionSetForTesting()
}

var (
Expand Down
2 changes: 1 addition & 1 deletion cmd/evm/eofparse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func FuzzEofParsing(f *testing.F) {
// And do the fuzzing
f.Fuzz(func(t *testing.T, data []byte) {
var (
jt = vm.NewPragueEOFInstructionSetForTesting()
jt = vm.NewEOFInstructionSetForTesting()
c vm.Container
)
cpy := common.CopyBytes(data)
Expand Down
20 changes: 9 additions & 11 deletions cmd/evm/testdata/33/exp.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
"balance": "0x29a2241af62c0000"
},
"0x2adc25665018aa1fe0e6bc666dac8fc2697ff9ba": {
"balance": "0x2bf52"
"balance": "0x2ab02"
},
"0x703c4b2bd70c169f5717101caee543299fc946c7": {
"code": "0xef0100000000000000000000000000000000000000bbbb",
Expand All @@ -21,7 +21,7 @@
},
"0x71562b71999873db5b286df957af199ec94617f7": {
"code": "0xef0100000000000000000000000000000000000000aaaa",
"balance": "0x6124fee993afa30e",
"balance": "0x6124fee993affe76",
"nonce": "0x2"
},
"0x8a0a19589531694250d570040a0c4b74576919b8": {
Expand All @@ -35,29 +35,27 @@
}
},
"result": {
"stateRoot": "0x9fdcacd4510e93c4488e537dc51578b5c6d505771db64a2610036eeb4be7b26f",
"stateRoot": "0x90e868da38bc6aff256832d72710207a04fa5ecfd86b0fc326e73d8fcb09dc1c",
"txRoot": "0x5d13a0b074e80388dc754da92b22922313a63417b3e25a10f324935e09697a53",
"receiptsRoot": "0x504c5d86c34391f70d210e6c482615b391db4bdb9f43479366399d9c5599850a",
"receiptsRoot": "0xdd64f30ac99db69f75893bb4b7bb10a76c86cf192ca48c4bfe724d7fe96c469a",
"logsHash": "0x1dcc4de8dec75d7aab85b567b6ccd41ad312451b948a7413f0a142fd40d49347",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"receipts": [
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","receipts": [
{
"type": "0x4",
"root": "0x",
"status": "0x1",
"cumulativeGasUsed": "0x15fa9",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000",
"logs": null,
"cumulativeGasUsed": "0x15581",
"logsBloom": "0x00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000","logs": null,
"transactionHash": "0x0417aab7c1d8a3989190c3167c132876ce9b8afd99262c5a0f9d06802de3d7ef",
"contractAddress": "0x0000000000000000000000000000000000000000",
"gasUsed": "0x15fa9",
"gasUsed": "0x15581",
"effectiveGasPrice": null,
"blockHash": "0x0000000000000000000000000000000000000000000000000000000000000000",
"transactionIndex": "0x0"
}
],
"currentDifficulty": null,
"gasUsed": "0x15fa9",
"gasUsed": "0x15581",
"currentBaseFee": "0x7",
"withdrawalsRoot": "0x56e81f171bcc55a6ff8345e692c0f86e5b48e01b996cadc001622fb5e363b421",
"requestsHash": "0xe3b0c44298fc1c149afbf4c8996fb92427ae41e4649b934ca495991b7852b855",
Expand Down
16 changes: 8 additions & 8 deletions core/vm/eof_validation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ func TestValidateCode(t *testing.T) {
data: make([]byte, 0),
subContainers: make([]*Container, 0),
}
_, err := validateCode(test.code, test.section, container, &pragueEOFInstructionSet, false)
_, err := validateCode(test.code, test.section, container, &eofInstructionSet, false)
if !errors.Is(err, test.err) {
t.Errorf("test %d (%s): unexpected error (want: %v, got: %v)", i, common.Bytes2Hex(test.code), test.err, err)
}
Expand All @@ -277,7 +277,7 @@ func BenchmarkRJUMPI(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := validateCode(code, 0, container, &pragueEOFInstructionSet, false)
_, err := validateCode(code, 0, container, &eofInstructionSet, false)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -309,7 +309,7 @@ func BenchmarkRJUMPV(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := validateCode(code, 0, container, &pragueEOFInstructionSet, false)
_, err := validateCode(code, 0, container, &pragueInstructionSet, false)
if err != nil {
b.Fatal(err)
}
Expand Down Expand Up @@ -357,7 +357,7 @@ func BenchmarkEOFValidation(b *testing.B) {
if err := container2.UnmarshalBinary(bin, true); err != nil {
b.Fatal(err)
}
if err := container2.ValidateCode(&pragueEOFInstructionSet, false); err != nil {
if err := container2.ValidateCode(&pragueInstructionSet, false); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -412,7 +412,7 @@ func BenchmarkEOFValidation2(b *testing.B) {
if err := container2.UnmarshalBinary(bin, true); err != nil {
b.Fatal(err)
}
if err := container2.ValidateCode(&pragueEOFInstructionSet, false); err != nil {
if err := container2.ValidateCode(&pragueInstructionSet, false); err != nil {
b.Fatal(err)
}
}
Expand Down Expand Up @@ -468,7 +468,7 @@ func BenchmarkEOFValidation3(b *testing.B) {
if err := container2.UnmarshalBinary(bin, true); err != nil {
b.Fatal(err)
}
if err := container2.ValidateCode(&pragueEOFInstructionSet, false); err != nil {
if err := container2.ValidateCode(&pragueInstructionSet, false); err != nil {
b.Fatal(err)
}
}
Expand All @@ -494,7 +494,7 @@ func BenchmarkRJUMPI_2(b *testing.B) {
}
b.ResetTimer()
for i := 0; i < b.N; i++ {
_, err := validateCode(code, 0, container, &pragueEOFInstructionSet, false)
_, err := validateCode(code, 0, container, &pragueInstructionSet, false)
if err != nil {
b.Fatal(err)
}
Expand All @@ -512,6 +512,6 @@ func FuzzValidate(f *testing.F) {
f.Fuzz(func(_ *testing.T, code []byte, maxStack uint16) {
var container Container
container.types = append(container.types, &functionMetadata{inputs: 0, outputs: 0x80, maxStackHeight: maxStack})
validateCode(code, 0, &container, &pragueEOFInstructionSet, true)
validateCode(code, 0, &container, &pragueInstructionSet, true)
})
}
2 changes: 2 additions & 0 deletions core/vm/interpreter.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ func NewEVMInterpreter(evm *EVM) *EVMInterpreter {
case evm.chainRules.IsVerkle:
// TODO replace with proper instruction set when fork is specified
table = &verkleInstructionSet
case evm.chainRules.IsPrague:
table = &pragueInstructionSet
case evm.chainRules.IsCancun:
table = &cancunInstructionSet
case evm.chainRules.IsShanghai:
Expand Down
18 changes: 12 additions & 6 deletions core/vm/jump_table.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,8 @@ var (
shanghaiInstructionSet = newShanghaiInstructionSet()
cancunInstructionSet = newCancunInstructionSet()
verkleInstructionSet = newVerkleInstructionSet()
pragueEOFInstructionSet = newPragueEOFInstructionSet()
pragueInstructionSet = newPragueInstructionSet()
eofInstructionSet = newEOFInstructionSetForTesting()
)

// JumpTable contains the EVM opcodes supported at a given fork.
Expand Down Expand Up @@ -91,24 +92,29 @@ func newVerkleInstructionSet() JumpTable {
return validate(instructionSet)
}

func NewPragueEOFInstructionSetForTesting() JumpTable {
return newPragueEOFInstructionSet()
func NewEOFInstructionSetForTesting() JumpTable {
return newEOFInstructionSetForTesting()
}

func newPragueEOFInstructionSet() JumpTable {
instructionSet := newCancunInstructionSet()
func newEOFInstructionSetForTesting() JumpTable {
instructionSet := newPragueInstructionSet()
enableEOF(&instructionSet)
return validate(instructionSet)
}

func newPragueInstructionSet() JumpTable {
instructionSet := newCancunInstructionSet()
enable7702(&instructionSet) // EIP-7702 Setcode transaction type
return validate(instructionSet)
}

func newCancunInstructionSet() JumpTable {
instructionSet := newShanghaiInstructionSet()
enable4844(&instructionSet) // EIP-4844 (BLOBHASH opcode)
enable7516(&instructionSet) // EIP-7516 (BLOBBASEFEE opcode)
enable1153(&instructionSet) // EIP-1153 "Transient Storage"
enable5656(&instructionSet) // EIP-5656 (MCOPY opcode)
enable6780(&instructionSet) // EIP-6780 SELFDESTRUCT only in same transaction
enable7702(&instructionSet)
return validate(instructionSet)
}

Expand Down

0 comments on commit 846d2b8

Please sign in to comment.