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

eth/catalyst: add timestamp checks to fcu and new payload and improve param checks #28230

Merged
merged 11 commits into from
Jan 23, 2024

Conversation

lightclient
Copy link
Member

@lightclient lightclient commented Sep 29, 2023

This PR introduces a few changes with respect to payload verification in fcu and new payload requests:

  • First of all, it undoes the verifyPayloadAttributes(..) simplification I attempted in beacon/engine, eth/catalyst, miner: 4788 CL/EL protocol updates #27872. At the time I expected the pattern from forkchoiceUpdatedV2 to continue where the previous version's payload attributes would be accepted by the method if the timestamp allowed. It turns out this is only a special case in forkchoiceUpdatedV2. In forkchoiceUpdatedV3 is not possible to provide PayloadAttributesV2. Only V3 is accepted. This sort of defeats the purpose of the shared method.

    To see this in the spec, you may first view the parameters for forkchoiceUpdatedV2 which accepts both PayloadAttributesV1 and PayloadAttributesV2 versus the parameters for forkchoiceUpdatedV3 which accepts only PayloadAttributesV3.

    For this reason I have removed verifyPayloadAttributes(..) and its related functions in favor of a more straight forward approach of verifying the existence of optional values on engine.PayloadAttributes. I went ahead and updated this logic for forkchoiceUpdatedV2 even though it should technically still allow V1 payload attributes, because we have passed Paris on all networks and have no need to continue support of building V1 blocks via forkchoiceUpdatedV2. I think it also simplifies the API to not have these two conflicting approaches for V1 vs. V2 fcu.

  • Next I have added timestamp validation to fcu payload attributes as required (section 2) by the Engine API spec. I back ported this from forkchoiceUpdatedV3 to forkchoiceUpdatedV2 so that it is only possible to call forkchoiceUpdatedV2 with attributes occurring in the Shanghai fork. This is done for the same reason a referenced above.

  • For the new payload methods, I also update the verification of the executable data. For newPayloadV2, it does not currently ensure that cancun values are nil. Which could make it possible to submit cancun payloads through it. Additionally, it verifies the timestamp of the payload is exactly within the Shanghai fork. Both of these break the ability to use newPayloadV2 for pre-shanghai blocks, but as already stated, all networks are past this point and it is not necessary to continue support. Decided to retain support for v1 payloads in new payload v2.

    On newPayloadV3 the same types of checks are added. All shanghai and cancun related fields in the executable data must be non-nil, with the addition that the timestamp is only with cancun.

  • Finally it updates a newly failing catalyst test to call the correct fcu and new payload methods depending on the fork.

--

The general flow of all engine API methods are:

  • check the well-formedness of the parameters -- this makes sense because the spec is written in a way were object is versioned, whereas we use a single object with optional values. So it would expect an immediate rejection by the API in case an object does not meet the expected criteria.
  • check the timing of the request -- although the fcu V2 and new payload V2 methods are special and also accept V1 requests, it is clear that going forward (as we see in V3) that the methods will be locked strictly to the fork they are related to and so we should check this after the well-formedness.
  • the thing -- after the checks are complete we can continue with processing the request

@lightclient lightclient force-pushed the fix-engine-param-checks branch 2 times, most recently from fa574ad to f5894ac Compare October 10, 2023 14:28
eth/catalyst/api.go Outdated Show resolved Hide resolved
eth/catalyst/api.go Outdated Show resolved Hide resolved
@lightclient
Copy link
Member Author

Agreed, the string comparison sucks. I am just hesitant to expose a new public interface for the fork order. I too another stab at it in the last commit though. LatestFork is a bit tricky to get right. We technically have three "markers" for determining which fork we're in. Block, total difficulty, and timestamp. I opted to only support time-based forks as that is how we will operate moving forward and the method doesn't need to be backwards compatible.


const (
Frontier = iota
FrontierThawing
Copy link
Member

Choose a reason for hiding this comment

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

I have never heard of frontierThawing before, very interesting

Copy link
Contributor

Choose a reason for hiding this comment

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

Me neither... Do you have a reference @lightclient ?

Copy link
Member

Choose a reason for hiding this comment

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

it was the fork that increased the gaslimit so transactions could be executed. I don't know if it was a hardfork or a softfork though

Comment on lines +37 to +41
GrayGlacier
Paris
Shanghai
Cancun
Prague
Copy link
Contributor

Choose a reason for hiding this comment

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

Wait, what is paris, and why is it before shanghai?

Copy link
Member

Choose a reason for hiding this comment

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

Paris was the official name for the merge

@MariusVanDerWijden
Copy link
Member

@parithosh told me that the devnet-10 branch (which I think contains this) had some issues on a shadowfork.

WARN [11-03|09:50:03.922] Served engine_newPayloadV2               conn=172.18.0.4:56686 reqid=1330 duration=2.520127ms err="Invalid parameters"       errdata="{Error:non-nil withdrawals pre-shanghai}"

even though the node was post-shanghai already. The CL node send (imo correctly) and empty withdrawal slice post-shanghai via v2, which should be accepted

@fjl fjl added the cancun label Jan 17, 2024
@lightclient
Copy link
Member Author

lightclient commented Jan 22, 2024

Currently we're failing a handful of engine-cancun tests. This PR resolves most of them, still couple which will i) be fixed by #28246 (depends on this PR) or ii) a forthcoming PR to split up forkchoiceUpdate(..) into methods which update the actual head and then a method to kick off payload building.

Before:
Screenshot 2024-01-22 at 09 20 25

After:
Screenshot 2024-01-22 at 09 22 49

Copy link
Contributor

@holiman holiman left a comment

Choose a reason for hiding this comment

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

LGTM

Comment on lines 455 to 456
func (api *ConsensusAPI) NewPayloadV2(params engine.ExecutableData) (engine.PayloadStatusV1, error) {
if api.eth.BlockChain().Config().IsShanghai(new(big.Int).SetUint64(params.Number), params.Timestamp) {
if api.eth.BlockChain().Config().LatestFork(params.Timestamp) == forks.Shanghai {
Copy link
Contributor

@holiman holiman Jan 23, 2024

Choose a reason for hiding this comment

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

Shouldn't something like this work?

if api.eth.BlockChain().Config.IsCancun(..) { 
    return engine.PayloadStatusV1{Status: engine.INVALID}, engine.InvalidParams.With(errors.New("NewPayloadV2 used post-shanghai"))
}
if api.eth.BlockChain().Config().LatestFork(params.Timestamp) == forks.Shanghai {

@holiman holiman added this to the 1.13.11 milestone Jan 23, 2024
Copy link
Member

@MariusVanDerWijden MariusVanDerWijden left a comment

Choose a reason for hiding this comment

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

LGTM

@holiman holiman merged commit 98eaa57 into ethereum:master Jan 23, 2024
2 of 3 checks passed
Dergarcon pushed a commit to specialmechanisms/mev-geth-0x2mev that referenced this pull request Jan 31, 2024
… param checks (ethereum#28230)

 This PR introduces a few changes with respect to payload verification in fcu and new payload requests:

* First of all, it undoes the `verifyPayloadAttributes(..)` simplification I attempted in ethereum#27872. 
* Adds timestamp validation to fcu payload attributes [as required](https://github.com/ethereum/execution-apis/blob/main/src/engine/cancun.md#specification-1) (section 2) by the Engine API spec. 
* For the new payload methods, I also update the verification of the executable data. For `newPayloadV2`, it does not currently ensure that cancun values are `nil`. Which could make it possible to submit cancun payloads through it. 
* On `newPayloadV3` the same types of checks are added. All shanghai and cancun related fields in the executable data must be non-nil, with the addition that the timestamp is _only_ with cancun.
* Finally it updates a newly failing catalyst test to call the correct fcu and new payload methods depending on the fork.
This pull request was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants