MCPcopy Create free account
hub / github.com/base/base / validate_withdrawals_presence

Function validate_withdrawals_presence

crates/execution/node/src/engine.rs:346–383  ·  view source on GitHub ↗

Validates the presence of the `withdrawals` field according to the payload timestamp. After Canyon, withdrawals field must be [Some]. Before Canyon, withdrawals field must be [None]; Canyon activates the Shanghai EIPs, see the Canyon specs for more details:

(
    chain_spec: impl Upgrades,
    version: EngineApiMessageVersion,
    message_validation_kind: MessageValidationKind,
    timestamp: u64,
    has_withdrawals: bool,
)

Source from the content-addressed store, hash-verified

344/// Canyon activates the Shanghai EIPs, see the Canyon specs for more details:
345/// <https://github.com/ethereum-optimism/optimism/blob/ab926c5fd1e55b5c864341c44842d6d1ca679d99/specs/superchain-upgrades.md#canyon>
346pub fn validate_withdrawals_presence(
347 chain_spec: impl Upgrades,
348 version: EngineApiMessageVersion,
349 message_validation_kind: MessageValidationKind,
350 timestamp: u64,
351 has_withdrawals: bool,
352) -> Result<(), EngineObjectValidationError> {
353 let is_shanghai = chain_spec.is_canyon_active_at_timestamp(timestamp);
354
355 match version {
356 EngineApiMessageVersion::V1 => {
357 if has_withdrawals {
358 return Err(message_validation_kind
359 .to_error(VersionSpecificValidationError::WithdrawalsNotSupportedInV1));
360 }
361 if is_shanghai {
362 return Err(message_validation_kind
363 .to_error(VersionSpecificValidationError::NoWithdrawalsPostShanghai));
364 }
365 }
366 EngineApiMessageVersion::V2
367 | EngineApiMessageVersion::V3
368 | EngineApiMessageVersion::V4
369 | EngineApiMessageVersion::V5
370 | EngineApiMessageVersion::V6 => {
371 if is_shanghai && !has_withdrawals {
372 return Err(message_validation_kind
373 .to_error(VersionSpecificValidationError::NoWithdrawalsPostShanghai));
374 }
375 if !is_shanghai && has_withdrawals {
376 return Err(message_validation_kind
377 .to_error(VersionSpecificValidationError::HasWithdrawalsPreShanghai));
378 }
379 }
380 };
381
382 Ok(())
383}
384
385#[cfg(test)]
386mod tests {

Callers 1

Calls 1

Tested by

no test coverage detected