2022-07-13 01:45:48 +00:00
|
|
|
# beacon_chain
|
2023-01-20 14:14:37 +00:00
|
|
|
# Copyright (c) 2022-2023 Status Research & Development GmbH
|
2022-07-13 01:45:48 +00:00
|
|
|
# Licensed and distributed under either of
|
|
|
|
# * MIT license (license terms in the root directory or at https://opensource.org/licenses/MIT).
|
|
|
|
# * Apache v2 license (license terms in the root directory or at https://www.apache.org/licenses/LICENSE-2.0).
|
|
|
|
# at your option. This file may not be copied, modified, or distributed except according to those terms.
|
|
|
|
|
2022-06-20 18:03:57 +00:00
|
|
|
# https://notes.ethereum.org/@9AeMAlpyQYaAAyuj47BzRw/rkwW3ceVY
|
|
|
|
# Monitor traffic: socat -v TCP-LISTEN:9550,fork TCP-CONNECT:127.0.0.1:8550
|
|
|
|
|
|
|
|
import
|
|
|
|
std/options,
|
|
|
|
stew/results,
|
|
|
|
chronos,
|
2023-05-15 05:05:12 +00:00
|
|
|
../beacon_chain/el/el_manager
|
2022-06-20 18:03:57 +00:00
|
|
|
|
2023-01-20 14:14:37 +00:00
|
|
|
{.push raises: [].}
|
2022-06-20 18:03:57 +00:00
|
|
|
|
|
|
|
from std/os import paramCount, paramStr
|
|
|
|
from nimcrypto/utils import fromHex
|
|
|
|
from web3/engine_api_types import PayloadExecutionStatus
|
|
|
|
from ../beacon_chain/networking/network_metadata import Eth1Network
|
|
|
|
from ../beacon_chain/spec/datatypes/base import ZERO_HASH
|
|
|
|
from ../beacon_chain/spec/presets import Eth1Address, defaultRuntimeConfig
|
|
|
|
|
2022-08-02 12:23:03 +00:00
|
|
|
# TODO factor this out and have a version with the result of the JWT secret
|
2022-06-20 18:03:57 +00:00
|
|
|
# slurp for testing purposes
|
|
|
|
proc readJwtSecret(jwtSecretFile: string): Result[seq[byte], cstring] =
|
2023-04-17 20:11:28 +00:00
|
|
|
# https://github.com/ethereum/execution-apis/blob/v1.0.0-beta.3/src/engine/authentication.md#key-distribution
|
2022-06-20 18:03:57 +00:00
|
|
|
# If such a parameter is given, but the file cannot be read, or does not
|
2023-04-17 20:11:28 +00:00
|
|
|
# contain a hex-encoded key of 256 bits, the client SHOULD treat this as an
|
2022-08-26 10:44:50 +00:00
|
|
|
# error: either abort the startup, or show error and continue without
|
|
|
|
# exposing the authenticated port.
|
2022-06-20 18:03:57 +00:00
|
|
|
const MIN_SECRET_LEN = 32
|
|
|
|
|
|
|
|
try:
|
|
|
|
let lines = readLines(jwtSecretFile, 1)
|
|
|
|
if lines.len > 0:
|
|
|
|
# Secret JWT key is parsed in constant time using nimcrypto:
|
|
|
|
# https://github.com/cheatfate/nimcrypto/pull/44
|
|
|
|
let secret = utils.fromHex(lines[0])
|
|
|
|
if secret.len >= MIN_SECRET_LEN:
|
|
|
|
ok(secret)
|
|
|
|
else:
|
|
|
|
err("JWT secret not at least 256 bits")
|
|
|
|
else:
|
|
|
|
err("JWT secret file empty")
|
|
|
|
except IOError as exc:
|
|
|
|
err("JWT secret file could not be read from")
|
|
|
|
|
|
|
|
proc run() {.async.} =
|
|
|
|
if paramCount() < 2:
|
|
|
|
echo "args are: web3url jwtsecretfilename"
|
|
|
|
|
|
|
|
let
|
2023-02-23 02:10:07 +00:00
|
|
|
elManager = newClone ELManager.init(
|
2022-07-14 04:07:40 +00:00
|
|
|
defaultRuntimeConfig, db = nil, nil, @[paramStr(1)],
|
2022-12-07 10:24:51 +00:00
|
|
|
none(DepositTreeSnapshot), none(Eth1Network), false,
|
2022-09-19 21:47:46 +00:00
|
|
|
some readJwtSecret(paramStr(2)).get)
|
2022-06-20 18:03:57 +00:00
|
|
|
|
|
|
|
try:
|
2023-02-23 02:10:07 +00:00
|
|
|
await elManager.exchangeTransitionConfiguration()
|
2022-06-20 18:03:57 +00:00
|
|
|
except ValueError as exc:
|
|
|
|
# Expected, since nothing here sets up the Nimbus TTD correctly
|
|
|
|
echo "exchangeTransitionConfiguration ValueError: " & exc.msg
|
|
|
|
echo "Invalid TTD errors are fine in this context"
|
|
|
|
|
|
|
|
waitFor run()
|