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

simulators/ethereum/engine: Add ForkchoiceUpdated with Invalid Payload Attributes Test #527

Merged
merged 2 commits into from
May 5, 2022
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
4 changes: 4 additions & 0 deletions simulators/ethereum/engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ Perform a forkchoiceUpdated call with an unknown (random) SafeBlockHash, the cli
- Unknown FinalizedBlockHash:
Perform a forkchoiceUpdated call with an unknown (random) FinalizedBlockHash, the client should throw an error.

- Invalid Payload Attributes:
Perform a forkchoiceUpdated call with valid forkchoice but invalid payload attributes.
Expected outcome is that the forkchoiceUpdate proceeds, but the call returns an error.

- Pre-TTD Block Hash:
Perform a forkchoiceUpdated call using a block hash part of the canonical chain that precedes the block where the TTD occurred. (Behavior is undefined for this edge case and not verified, but should not produce unrecoverable error)

Expand Down
65 changes: 65 additions & 0 deletions simulators/ethereum/engine/enginetests.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,14 @@ var engineTests = []TestSpec{
Name: "Unknown FinalizedBlockHash",
Run: unknownFinalizedBlockHash,
},
{
Name: "ForkchoiceUpdated Invalid Payload Attributes",
Run: invalidPayloadAttributesGen(false),
},
{
Name: "ForkchoiceUpdated Invalid Payload Attributes (Syncing)",
Run: invalidPayloadAttributesGen(true),
},
{
Name: "Pre-TTD ForkchoiceUpdated After PoS Switch",
Run: preTTDFinalizedBlockHash,
Expand Down Expand Up @@ -377,6 +385,63 @@ func unknownHeadBlockHash(t *TestEnv) {

}

// Verify behavior on a forkchoiceUpdated with invalid payload attributes
func invalidPayloadAttributesGen(syncing bool) func(*TestEnv) {

return func(t *TestEnv) {
// Wait until TTD is reached by this client
t.CLMock.waitForTTD()

// Produce blocks before starting the test
t.CLMock.produceBlocks(5, BlockProcessCallbacks{})

// Send a forkchoiceUpdated with invalid PayloadAttributes
t.CLMock.produceSingleBlock(BlockProcessCallbacks{
OnNewPayloadBroadcast: func() {
// Try to apply the new payload with invalid attributes
var blockHash common.Hash
if syncing {
// Setting a random hash will put the client into `SYNCING`
rand.Read(blockHash[:])
} else {
// Set the block hash to the next payload that was broadcasted
blockHash = t.CLMock.LatestPayloadBuilt.BlockHash
}
t.Logf("INFO (%s): Sending EngineForkchoiceUpdatedV1 (Syncing=%s) with invalid payload attributes", t.TestName, syncing)
fcu := ForkchoiceStateV1{
HeadBlockHash: blockHash,
SafeBlockHash: blockHash,
FinalizedBlockHash: blockHash,
}
attr := PayloadAttributesV1{
Timestamp: 0,
PrevRandao: common.Hash{},
SuggestedFeeRecipient: common.Address{},
}
// 0) Check headBlock is known and there is no missing data, if not respond with SYNCING
// 1) Check headBlock is VALID, if not respond with INVALID
// 2) Apply forkchoiceState
// 3) Check payloadAttributes, if invalid respond with error: code: Invalid payload attributes
// 4) Start payload build process and respond with VALID
if syncing {
// If we are SYNCING, the outcome should be SYNCING regardless of the validity of the payload atttributes
r := t.TestEngine.TestEngineForkchoiceUpdatedV1(&fcu, &attr)
r.ExpectPayloadStatus(Syncing)
r.ExpectPayloadID(nil)
} else {
r := t.TestEngine.TestEngineForkchoiceUpdatedV1(&fcu, &attr)
r.ExpectError()

// Check that the forkchoice was applied, regardless of the error
s := t.TestEth.TestHeaderByNumber(nil)
s.ExpectHash(blockHash)
}
},
})
}

}

// Verify that a forkchoiceUpdated fails on hash being set to a pre-TTD block after PoS change
func preTTDFinalizedBlockHash(t *TestEnv) {
// Wait until TTD is reached by this client
Expand Down