2022-11-26 14:59:19 +00:00
|
|
|
# Nimbus
|
|
|
|
# Copyright (c) 2022 Status Research & Development GmbH
|
|
|
|
# Licensed under either of
|
|
|
|
# * Apache License, version 2.0, ([LICENSE-APACHE](LICENSE-APACHE) or
|
|
|
|
# http://www.apache.org/licenses/LICENSE-2.0)
|
|
|
|
# * MIT license ([LICENSE-MIT](LICENSE-MIT) or
|
|
|
|
# http://opensource.org/licenses/MIT)
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except
|
|
|
|
# according to those terms.
|
|
|
|
|
|
|
|
import
|
|
|
|
stew/results,
|
2022-12-02 04:35:41 +00:00
|
|
|
../common/common
|
2022-11-26 14:59:19 +00:00
|
|
|
|
2023-01-30 22:10:23 +00:00
|
|
|
{.push raises: [].}
|
|
|
|
|
2022-11-26 14:59:19 +00:00
|
|
|
# https://eips.ethereum.org/EIPS/eip-4895
|
2023-06-25 13:30:34 +00:00
|
|
|
proc validateWithdrawals*(
|
2023-09-18 20:20:28 +00:00
|
|
|
com: CommonRef,
|
|
|
|
header: BlockHeader,
|
|
|
|
body: BlockBody
|
|
|
|
): Result[void, string]
|
2023-10-05 03:04:12 +00:00
|
|
|
{.gcsafe, raises: [].} =
|
2023-06-25 13:30:34 +00:00
|
|
|
|
|
|
|
if com.forkGTE(Shanghai):
|
|
|
|
if header.withdrawalsRoot.isNone:
|
|
|
|
return err("Post-Shanghai block header must have withdrawalsRoot")
|
|
|
|
elif body.withdrawals.isNone:
|
|
|
|
return err("Post-Shanghai block body must have withdrawals")
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
if body.withdrawals.get.calcWithdrawalsRoot != header.withdrawalsRoot.get:
|
|
|
|
return err("Mismatched withdrawalsRoot blockNumber =" & $header.blockNumber)
|
|
|
|
except RlpError as ex:
|
|
|
|
return err(ex.msg)
|
|
|
|
else:
|
|
|
|
if header.withdrawalsRoot.isSome:
|
|
|
|
return err("Pre-Shanghai block header must not have withdrawalsRoot")
|
|
|
|
elif body.withdrawals.isSome:
|
|
|
|
return err("Pre-Shanghai block body must not have withdrawals")
|
|
|
|
|
2022-11-26 14:59:19 +00:00
|
|
|
return ok()
|