diff --git a/beacon-chain/powchain/BUILD.bazel b/beacon-chain/powchain/BUILD.bazel index c023c483a6..79983739ae 100644 --- a/beacon-chain/powchain/BUILD.bazel +++ b/beacon-chain/powchain/BUILD.bazel @@ -77,6 +77,7 @@ go_test( "block_reader_test.go", "check_transition_config_test.go", "deposit_test.go", + "engine_client_fuzz_test.go", "engine_client_test.go", "init_test.go", "log_processing_test.go", @@ -85,6 +86,7 @@ go_test( "provider_test.go", "service_test.go", ], + data = glob(["testdata/**"]), embed = [":go_default_library"], deps = [ "//async/event:go_default_library", @@ -121,6 +123,7 @@ go_test( "@com_github_ethereum_go_ethereum//accounts/abi/bind/backends:go_default_library", "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", + "@com_github_ethereum_go_ethereum//core/beacon:go_default_library", "@com_github_ethereum_go_ethereum//core/types:go_default_library", "@com_github_ethereum_go_ethereum//rpc:go_default_library", "@com_github_ethereum_go_ethereum//trie:go_default_library", diff --git a/beacon-chain/powchain/engine_client_fuzz_test.go b/beacon-chain/powchain/engine_client_fuzz_test.go new file mode 100644 index 0000000000..f3fd30777e --- /dev/null +++ b/beacon-chain/powchain/engine_client_fuzz_test.go @@ -0,0 +1,114 @@ +//go:build go1.18 +// +build go1.18 + +package powchain_test + +import ( + "encoding/json" + "fmt" + "math" + "math/big" + "testing" + + "github.com/ethereum/go-ethereum/common" + "github.com/ethereum/go-ethereum/core/beacon" + "github.com/prysmaticlabs/prysm/beacon-chain/powchain" + pb "github.com/prysmaticlabs/prysm/proto/engine/v1" + "github.com/prysmaticlabs/prysm/testing/assert" +) + +func FuzzForkChoiceResponse(f *testing.F) { + valHash := common.Hash([32]byte{0xFF, 0x01}) + payloadID := beacon.PayloadID([8]byte{0x01, 0xFF, 0xAA, 0x00, 0xEE, 0xFE, 0x00, 0x00}) + valErr := "asjajshjahsaj" + seed := &beacon.ForkChoiceResponse{ + PayloadStatus: beacon.PayloadStatusV1{ + Status: "INVALID_TERMINAL_BLOCK", + LatestValidHash: &valHash, + ValidationError: &valErr, + }, + PayloadID: &payloadID, + } + output, err := json.Marshal(seed) + assert.NoError(f, err) + f.Add(output) + f.Fuzz(func(t *testing.T, jsonBlob []byte) { + gethResp := &beacon.ForkChoiceResponse{} + prysmResp := &powchain.ForkchoiceUpdatedResponse{} + gethErr := json.Unmarshal(jsonBlob, gethResp) + prysmErr := json.Unmarshal(jsonBlob, prysmResp) + assert.Equal(t, gethErr != nil, prysmErr != nil, fmt.Sprintf("geth and prysm unmarshaller return inconsistent errors. %v and %v", gethErr, prysmErr)) + // Nothing to marshal if we have an error. + if gethErr != nil { + return + } + gethBlob, gethErr := json.Marshal(gethResp) + prysmBlob, prysmErr := json.Marshal(prysmResp) + assert.Equal(t, gethErr != nil, prysmErr != nil, "geth and prysm unmarshaller return inconsistent errors") + newGethResp := &beacon.ForkChoiceResponse{} + newGethErr := json.Unmarshal(prysmBlob, newGethResp) + assert.NoError(t, newGethErr) + if newGethResp.PayloadStatus.Status == "UNKNOWN" { + return + } + + newGethResp2 := &beacon.ForkChoiceResponse{} + newGethErr = json.Unmarshal(gethBlob, newGethResp2) + assert.NoError(t, newGethErr) + + assert.DeepEqual(t, newGethResp.PayloadID, newGethResp2.PayloadID) + assert.DeepEqual(t, newGethResp.PayloadStatus.Status, newGethResp2.PayloadStatus.Status) + assert.DeepEqual(t, newGethResp.PayloadStatus.LatestValidHash, newGethResp2.PayloadStatus.LatestValidHash) + isNilOrEmpty := newGethResp.PayloadStatus.ValidationError == nil || (*newGethResp.PayloadStatus.ValidationError == "") + isNilOrEmpty2 := newGethResp2.PayloadStatus.ValidationError == nil || (*newGethResp2.PayloadStatus.ValidationError == "") + assert.DeepEqual(t, isNilOrEmpty, isNilOrEmpty2) + if !isNilOrEmpty { + assert.DeepEqual(t, *newGethResp.PayloadStatus.ValidationError, *newGethResp2.PayloadStatus.ValidationError) + } + }) +} + +func FuzzExecutionPayload(f *testing.F) { + logsBloom := [256]byte{'j', 'u', 'n', 'k'} + execData := &beacon.ExecutableDataV1{ + ParentHash: common.Hash([32]byte{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}), + FeeRecipient: common.Address([20]byte{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF}), + StateRoot: common.Hash([32]byte{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}), + ReceiptsRoot: common.Hash([32]byte{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}), + LogsBloom: logsBloom[:], + Random: common.Hash([32]byte{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}), + Number: math.MaxUint64, + GasLimit: math.MaxUint64, + GasUsed: math.MaxUint64, + Timestamp: 100, + ExtraData: nil, + BaseFeePerGas: big.NewInt(math.MaxInt), + BlockHash: common.Hash([32]byte{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}), + Transactions: [][]byte{{0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}, {0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}, {0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}, {0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01, 0xFF, 0x01}}, + } + output, err := json.Marshal(execData) + assert.NoError(f, err) + f.Add(output) + f.Fuzz(func(t *testing.T, jsonBlob []byte) { + gethResp := &beacon.ExecutableDataV1{} + prysmResp := &pb.ExecutionPayload{} + gethErr := json.Unmarshal(jsonBlob, gethResp) + prysmErr := json.Unmarshal(jsonBlob, prysmResp) + assert.Equal(t, gethErr != nil, prysmErr != nil, fmt.Sprintf("geth and prysm unmarshaller return inconsistent errors. %v and %v", gethErr, prysmErr)) + // Nothing to marshal if we have an error. + if gethErr != nil { + return + } + gethBlob, gethErr := json.Marshal(gethResp) + prysmBlob, prysmErr := json.Marshal(prysmResp) + assert.Equal(t, gethErr != nil, prysmErr != nil, "geth and prysm unmarshaller return inconsistent errors") + newGethResp := &beacon.ExecutableDataV1{} + newGethErr := json.Unmarshal(prysmBlob, newGethResp) + assert.NoError(t, newGethErr) + newGethResp2 := &beacon.ExecutableDataV1{} + newGethErr = json.Unmarshal(gethBlob, newGethResp2) + assert.NoError(t, newGethErr) + + assert.DeepEqual(t, newGethResp.LogsBloom, newGethResp2.LogsBloom) + }) +} diff --git a/beacon-chain/powchain/engine_client_test.go b/beacon-chain/powchain/engine_client_test.go index f277d56da9..8f82a19ff4 100644 --- a/beacon-chain/powchain/engine_client_test.go +++ b/beacon-chain/powchain/engine_client_test.go @@ -806,7 +806,7 @@ func fixtures() map[string]interface{} { forkChoiceInvalidResp := &ForkchoiceUpdatedResponse{ Status: &pb.PayloadStatus{ Status: pb.PayloadStatus_INVALID, - LatestValidHash: []byte("latestValidHash"), + LatestValidHash: bytesutil.PadTo([]byte("latestValidHash"), 32), }, PayloadId: &id, } diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/100722c8124711a78513977bf46b7efc49c3219fff556ba4e5fca40825097e41 b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/100722c8124711a78513977bf46b7efc49c3219fff556ba4e5fca40825097e41 new file mode 100644 index 0000000000..281f9a687e --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/100722c8124711a78513977bf46b7efc49c3219fff556ba4e5fca40825097e41 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"parentHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"feeRecipient\":\"0xff01ff01ff01ff01ffff01ff01ff01ff01ff0000\",\"stateRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"receiptsRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff01000000fffffff0000000000000000000\",\"logsBloom\":\"0x6a756e6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"prevRandao\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"blockNumber\":\"0xffffffffffffffff\",\"gasLimit\":\"0xffffffffffffffff\",\"gasUsed\":\"0xffffffffffffffff\",\"timestamp\":\"0x64\",\"extraData\":\"0x\",\"baseFeePerGas\":\"0x7fffff0000000fff\",\"blockHash\":\"0xff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"transactions\":[\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\"]}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/41784bc5bdb982cfc2d08e901aef27c3aff6604b506658bc52a25fade49b1f4e b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/41784bc5bdb982cfc2d08e901aef27c3aff6604b506658bc52a25fade49b1f4e new file mode 100644 index 0000000000..a543d2eb0c --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/41784bc5bdb982cfc2d08e901aef27c3aff6604b506658bc52a25fade49b1f4e @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"BAseFeePerGAs\":\"0X0\"}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/527c135d6108092428e79c0f4649292c433148aec13371aff07dbc679f4f6a90 b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/527c135d6108092428e79c0f4649292c433148aec13371aff07dbc679f4f6a90 new file mode 100644 index 0000000000..cb80dd7a99 --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/527c135d6108092428e79c0f4649292c433148aec13371aff07dbc679f4f6a90 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"parentHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"feeRecipient\":\"0xff01ff01ff01ff01ffff01ff01ff0000\",\"stateRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"receiptsRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"logsBloom\":\"0x6a756e6b000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"prevRandao\":\"0xff01ff01ff01ff01ff01ff000000ff0100000000000000000000000000000000\",\"blockNumber\":\"0xffffffffffffffff\",\"gasLimit\":\"0xffffffffffffffff\",\"gasUsed\":\"0xffffffffffffffff\",\"timestamp\":\"0x64\",\"extraData\":\"0x\",\"baseFeePerGas\":\"0x7f0fffffffffffff\",\"blockHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"transactions\":[\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\"]}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/83bfaa74d6d90c81a32fabfe3b7767556ed68b07b41c9b71c3c8adcf513623d5 b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/83bfaa74d6d90c81a32fabfe3b7767556ed68b07b41c9b71c3c8adcf513623d5 new file mode 100644 index 0000000000..ff03a7c88e --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/83bfaa74d6d90c81a32fabfe3b7767556ed68b07b41c9b71c3c8adcf513623d5 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"parentHash\":\"0xff01Ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"feeRecipient\":\"0xff01ff01ff01ff01ffff01ff01ff01ff01ff0000\",\"stateRoot\":\"0xff01ff01ff0fff01ff01ff01ff01ff0100000000000000000000000000000000\",\"receiptsRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"logsBloom\":\"0x6a756e6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"prevRandao\":\"0xff01ff01ff01ff01ff011f01ff01ff0100000000000000000000000000000000\",\"blockNumber\":\"0xffffffffffffffff\",\"gasLimit\":\"0xffffffffffffffff\",\"gasUsed\":\"0xffffffffffffffff\",\"timestamp\":\"0x64\",\"extraData\":\"0x\",\"baseFeePerGas\":\"0x7fffffffffffffff\",\"blockHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"transactions\":[\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\"]}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/8664c701ef3242a177be72eadef6c3a68465e15ca39f569ce56442181ab2771e b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/8664c701ef3242a177be72eadef6c3a68465e15ca39f569ce56442181ab2771e new file mode 100644 index 0000000000..b0ec8b0c83 --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/8664c701ef3242a177be72eadef6c3a68465e15ca39f569ce56442181ab2771e @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"pArentHAsh\":\"\",\"feeReCipient\":\"\",\"stAteRoot\":\"\",\"reCeiptsRoot\":\"\",\"logsBloom\":\"\",\"prevRAndAo\":\"\",\"eXtrADAtA\":\"\",\"BAseFeePerGAs\":\"0X0\",\"BloCkHAsh\":\"\",\"trAnsACtions\":[]}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/970ac64975387437edb15f7aa06e7d420d7f2b16a2b8348749020ca172332512 b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/970ac64975387437edb15f7aa06e7d420d7f2b16a2b8348749020ca172332512 new file mode 100644 index 0000000000..a31f65ffba --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/970ac64975387437edb15f7aa06e7d420d7f2b16a2b8348749020ca172332512 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"parentHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"feeRecipient\":\"0xff01ff01ff01ff01ffff01ff01ff01ff01ff0000\",\"stateRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"receiptsRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff01000000fffffff0000000000000000000\",\"logsBloom\":\"0x6a756e6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"prevRandao\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"blockNumber\":\"0xffffffffffffffff\",\"gasLimit\":\"0xffffffffffffffff\",\"gasUsed\":\"0xffffffffffffffff\",\"t\xc1\xc1\xc1\xc1\xc1\xc1\xc1\xc1\":\"0x64\",\"extraData\":\"0x\",\"baseFeePerGas\":\"0x7fffff0000000fff\",\"blockHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"transactions\":[\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\"]}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/9f2b178e755b4330641370a05be5ba6a7db96c0b8d6650f64ab0aaa2982124e8 b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/9f2b178e755b4330641370a05be5ba6a7db96c0b8d6650f64ab0aaa2982124e8 new file mode 100644 index 0000000000..9b9b0e5faf --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/9f2b178e755b4330641370a05be5ba6a7db96c0b8d6650f64ab0aaa2982124e8 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"parentHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"feeRecipient\":\"0xff01ff01ff01ff01ffff01ff01ff01ff01ff0000\",\"stateRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"receiptsRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff01000000fffffff0000000000000000000\",\"logsBloom\":\"0x6a756e6b0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"prevRandao\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"blockNumber\":\"0xffffffffffffffff\",\"gasLimit\":\"0xffffffffffffffff\",\"gasUsed\":\"0xffffffffffffffff\",\"timestamp\":\"0x64\",\"extraData\":\"0x\",\"baseFeePerGas\":\"0x7fffff0000000fff0000000\",\"blockHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"transactions\":[\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff010ff1ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\"]}") diff --git a/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/b9490d64fb5ca3b43302c100b160125420b15130fa17d4b7e29c67267c97ec96 b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/b9490d64fb5ca3b43302c100b160125420b15130fa17d4b7e29c67267c97ec96 new file mode 100644 index 0000000000..15005e4904 --- /dev/null +++ b/beacon-chain/powchain/testdata/fuzz/FuzzExecutionPayload/b9490d64fb5ca3b43302c100b160125420b15130fa17d4b7e29c67267c97ec96 @@ -0,0 +1,2 @@ +go test fuzz v1 +[]byte("{\"parentHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"feeRecipient\":\"0xff01ff01ff01ff01ffff01ff01ff01ff01ff0000\",\"stateRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"receiptsRoot\":\"0xff01ff01ff01ff01ff01ff01ff01ff01000000fffffff0000000000000000000\",\"logsBloom\":\"0x6a756e6b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000f010000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000\",\"prevRandao\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"blockNu0000000mber\":\"0xffffffffffffffff\",\"gasLimit\":\"0xffffffffffffffff\",\"gasUsed\":\"0xffffffffffffffff\",\"timestamp\":\"0x64\",\"extraData\":\"0x\",\"baseFeePerGas\":\"0x7fffff0000000fff\",\"blockHash\":\"0xff01ff01ff01ff01ff01ff01ff01ff0100000000000000000000000000000000\",\"transactions\":[\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\",\"0xff01ff01ff01ff01ff01ff01ff01ff01\"]}") diff --git a/proto/engine/v1/BUILD.bazel b/proto/engine/v1/BUILD.bazel index fc5c7aeb22..a73d363de2 100644 --- a/proto/engine/v1/BUILD.bazel +++ b/proto/engine/v1/BUILD.bazel @@ -46,11 +46,11 @@ go_proto_library( proto = ":proto", visibility = ["//visibility:public"], deps = [ - "//proto/eth/ext:go_default_library", - "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", - "@com_github_golang_protobuf//proto:go_default_library", "//consensus-types/primitives:go_default_library", + "//proto/eth/ext:go_default_library", + "@com_github_golang_protobuf//proto:go_default_library", "@go_googleapis//google/api:annotations_go_proto", + "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", "@org_golang_google_protobuf//reflect/protoreflect:go_default_library", "@org_golang_google_protobuf//runtime/protoimpl:go_default_library", ], @@ -68,19 +68,21 @@ go_library( importpath = "github.com/prysmaticlabs/prysm/proto/engine/v1", visibility = ["//visibility:public"], deps = [ + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", + "//encoding/bytesutil:go_default_library", "//proto/eth/ext:go_default_library", - "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", - "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_ethereum_go_ethereum//common:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", - "@io_bazel_rules_go//proto/wkt:timestamp_go_proto", + "@com_github_golang_protobuf//proto:go_default_library", + "@com_github_pkg_errors//:go_default_library", + "@com_github_prysmaticlabs_fastssz//:go_default_library", "@go_googleapis//google/api:annotations_go_proto", + "@io_bazel_rules_go//proto/wkt:descriptor_go_proto", + "@io_bazel_rules_go//proto/wkt:timestamp_go_proto", "@org_golang_google_protobuf//encoding/protojson:go_default_library", "@org_golang_google_protobuf//reflect/protoreflect:go_default_library", "@org_golang_google_protobuf//runtime/protoimpl:go_default_library", - "@com_github_prysmaticlabs_fastssz//:go_default_library", - "//encoding/bytesutil:go_default_library", - "//config/fieldparams:go_default_library", - "//config/params:go_default_library", ], # keep ) @@ -91,10 +93,10 @@ go_test( ], deps = [ ":go_default_library", + "//config/fieldparams:go_default_library", + "//config/params:go_default_library", "//encoding/bytesutil:go_default_library", "//testing/require:go_default_library", "@com_github_ethereum_go_ethereum//common/hexutil:go_default_library", - "//config/fieldparams:go_default_library", - "//config/params:go_default_library", ], ) diff --git a/proto/engine/v1/json_marshal_unmarshal.go b/proto/engine/v1/json_marshal_unmarshal.go index da4487c2d7..cc29e6c041 100644 --- a/proto/engine/v1/json_marshal_unmarshal.go +++ b/proto/engine/v1/json_marshal_unmarshal.go @@ -4,7 +4,9 @@ import ( "encoding/json" "math/big" + "github.com/ethereum/go-ethereum/common" "github.com/ethereum/go-ethereum/common/hexutil" + "github.com/pkg/errors" fieldparams "github.com/prysmaticlabs/prysm/config/fieldparams" "github.com/prysmaticlabs/prysm/encoding/bytesutil" ) @@ -158,19 +160,19 @@ func (e *ExecutionBlock) UnmarshalJSON(enc []byte) error { } type executionPayloadJSON struct { - ParentHash hexutil.Bytes `json:"parentHash"` - FeeRecipient hexutil.Bytes `json:"feeRecipient"` - StateRoot hexutil.Bytes `json:"stateRoot"` - ReceiptsRoot hexutil.Bytes `json:"receiptsRoot"` - LogsBloom hexutil.Bytes `json:"logsBloom"` - PrevRandao hexutil.Bytes `json:"prevRandao"` - BlockNumber hexutil.Uint64 `json:"blockNumber"` - GasLimit hexutil.Uint64 `json:"gasLimit"` - GasUsed hexutil.Uint64 `json:"gasUsed"` - Timestamp hexutil.Uint64 `json:"timestamp"` + ParentHash *common.Hash `json:"parentHash"` + FeeRecipient *common.Address `json:"feeRecipient"` + StateRoot *common.Hash `json:"stateRoot"` + ReceiptsRoot *common.Hash `json:"receiptsRoot"` + LogsBloom *hexutil.Bytes `json:"logsBloom"` + PrevRandao *common.Hash `json:"prevRandao"` + BlockNumber *hexutil.Uint64 `json:"blockNumber"` + GasLimit *hexutil.Uint64 `json:"gasLimit"` + GasUsed *hexutil.Uint64 `json:"gasUsed"` + Timestamp *hexutil.Uint64 `json:"timestamp"` ExtraData hexutil.Bytes `json:"extraData"` BaseFeePerGas string `json:"baseFeePerGas"` - BlockHash hexutil.Bytes `json:"blockHash"` + BlockHash *common.Hash `json:"blockHash"` Transactions []hexutil.Bytes `json:"transactions"` } @@ -182,20 +184,31 @@ func (e *ExecutionPayload) MarshalJSON() ([]byte, error) { } baseFee := new(big.Int).SetBytes(bytesutil.ReverseByteOrder(e.BaseFeePerGas)) baseFeeHex := hexutil.EncodeBig(baseFee) + pHash := common.BytesToHash(e.ParentHash) + sRoot := common.BytesToHash(e.StateRoot) + recRoot := common.BytesToHash(e.ReceiptsRoot) + prevRan := common.BytesToHash(e.PrevRandao) + bHash := common.BytesToHash(e.BlockHash) + blockNum := hexutil.Uint64(e.BlockNumber) + gasLimit := hexutil.Uint64(e.GasLimit) + gasUsed := hexutil.Uint64(e.GasUsed) + timeStamp := hexutil.Uint64(e.Timestamp) + recipient := common.BytesToAddress(e.FeeRecipient) + logsBloom := hexutil.Bytes(e.LogsBloom) return json.Marshal(executionPayloadJSON{ - ParentHash: e.ParentHash, - FeeRecipient: e.FeeRecipient, - StateRoot: e.StateRoot, - ReceiptsRoot: e.ReceiptsRoot, - LogsBloom: e.LogsBloom, - PrevRandao: e.PrevRandao, - BlockNumber: hexutil.Uint64(e.BlockNumber), - GasLimit: hexutil.Uint64(e.GasLimit), - GasUsed: hexutil.Uint64(e.GasUsed), - Timestamp: hexutil.Uint64(e.Timestamp), + ParentHash: &pHash, + FeeRecipient: &recipient, + StateRoot: &sRoot, + ReceiptsRoot: &recRoot, + LogsBloom: &logsBloom, + PrevRandao: &prevRan, + BlockNumber: &blockNum, + GasLimit: &gasLimit, + GasUsed: &gasUsed, + Timestamp: &timeStamp, ExtraData: e.ExtraData, BaseFeePerGas: baseFeeHex, - BlockHash: e.BlockHash, + BlockHash: &bHash, Transactions: transactions, }) } @@ -206,24 +219,65 @@ func (e *ExecutionPayload) UnmarshalJSON(enc []byte) error { if err := json.Unmarshal(enc, &dec); err != nil { return err } + + if dec.ParentHash == nil { + return errors.New("missing required field 'parentHash' for ExecutionPayload") + } + if dec.FeeRecipient == nil { + return errors.New("missing required field 'feeRecipient' for ExecutionPayload") + } + if dec.StateRoot == nil { + return errors.New("missing required field 'stateRoot' for ExecutionPayload") + } + if dec.ReceiptsRoot == nil { + return errors.New("missing required field 'receiptsRoot' for ExecutableDataV1") + } + + if dec.LogsBloom == nil { + return errors.New("missing required field 'logsBloom' for ExecutionPayload") + } + if dec.PrevRandao == nil { + return errors.New("missing required field 'prevRandao' for ExecutionPayload") + } + if dec.ExtraData == nil { + return errors.New("missing required field 'extraData' for ExecutionPayload") + } + if dec.BlockHash == nil { + return errors.New("missing required field 'blockHash' for ExecutionPayload") + } + if dec.Transactions == nil { + return errors.New("missing required field 'transactions' for ExecutionPayload") + } + if dec.BlockNumber == nil { + return errors.New("missing required field 'blockNumber' for ExecutionPayload") + } + if dec.Timestamp == nil { + return errors.New("missing required field 'timestamp' for ExecutionPayload") + } + if dec.GasUsed == nil { + return errors.New("missing required field 'gasUsed' for ExecutionPayload") + } + if dec.GasLimit == nil { + return errors.New("missing required field 'gasLimit' for ExecutionPayload") + } *e = ExecutionPayload{} - e.ParentHash = bytesutil.PadTo(dec.ParentHash, fieldparams.RootLength) - e.FeeRecipient = bytesutil.PadTo(dec.FeeRecipient, fieldparams.FeeRecipientLength) - e.StateRoot = bytesutil.PadTo(dec.StateRoot, fieldparams.RootLength) - e.ReceiptsRoot = bytesutil.PadTo(dec.ReceiptsRoot, fieldparams.RootLength) - e.LogsBloom = bytesutil.PadTo(dec.LogsBloom, fieldparams.LogsBloomLength) - e.PrevRandao = bytesutil.PadTo(dec.PrevRandao, fieldparams.RootLength) - e.BlockNumber = uint64(dec.BlockNumber) - e.GasLimit = uint64(dec.GasLimit) - e.GasUsed = uint64(dec.GasUsed) - e.Timestamp = uint64(dec.Timestamp) + e.ParentHash = dec.ParentHash.Bytes() + e.FeeRecipient = dec.FeeRecipient.Bytes() + e.StateRoot = dec.StateRoot.Bytes() + e.ReceiptsRoot = dec.ReceiptsRoot.Bytes() + e.LogsBloom = *dec.LogsBloom + e.PrevRandao = dec.PrevRandao.Bytes() + e.BlockNumber = uint64(*dec.BlockNumber) + e.GasLimit = uint64(*dec.GasLimit) + e.GasUsed = uint64(*dec.GasUsed) + e.Timestamp = uint64(*dec.Timestamp) e.ExtraData = dec.ExtraData baseFee, err := hexutil.DecodeBig(dec.BaseFeePerGas) if err != nil { return err } e.BaseFeePerGas = bytesutil.PadTo(bytesutil.ReverseByteOrder(baseFee.Bytes()), fieldparams.RootLength) - e.BlockHash = bytesutil.PadTo(dec.BlockHash, fieldparams.RootLength) + e.BlockHash = dec.BlockHash.Bytes() transactions := make([][]byte, len(dec.Transactions)) for i, tx := range dec.Transactions { transactions[i] = tx @@ -261,16 +315,20 @@ func (p *PayloadAttributes) UnmarshalJSON(enc []byte) error { } type payloadStatusJSON struct { - LatestValidHash *hexutil.Bytes `json:"latestValidHash"` - Status string `json:"status"` - ValidationError *string `json:"validationError"` + LatestValidHash *common.Hash `json:"latestValidHash"` + Status string `json:"status"` + ValidationError *string `json:"validationError"` } // MarshalJSON -- func (p *PayloadStatus) MarshalJSON() ([]byte, error) { - hash := p.LatestValidHash + var latestHash *common.Hash + if p.LatestValidHash != nil { + hash := common.Hash(bytesutil.ToBytes32(p.LatestValidHash)) + latestHash = (*common.Hash)(&hash) + } return json.Marshal(payloadStatusJSON{ - LatestValidHash: (*hexutil.Bytes)(&hash), + LatestValidHash: latestHash, Status: p.Status.String(), ValidationError: &p.ValidationError, }) @@ -284,7 +342,7 @@ func (p *PayloadStatus) UnmarshalJSON(enc []byte) error { } *p = PayloadStatus{} if dec.LatestValidHash != nil { - p.LatestValidHash = *dec.LatestValidHash + p.LatestValidHash = dec.LatestValidHash[:] } p.Status = PayloadStatus_Status(PayloadStatus_Status_value[dec.Status]) if dec.ValidationError != nil {