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

Deneb+Cancun support #10

Merged
merged 7 commits into from
May 3, 2024
Merged
Show file tree
Hide file tree
Changes from 2 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
30 changes: 15 additions & 15 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -23,13 +23,13 @@
ARG DEBIAN_RELEASE="bookworm"

# Lighthouse testnet bakery helper
ARG LCLI_VERSION="4.5.0"
ARG LCLI_VERSION="5.0.0"

# Ethereum clients
ARG GETH_VERSION="1.13.2"
ARG LIGHTHOUSE_VERSION="4.5.0"
ARG TEKU_VERSION="23.10.0"
ARG MEV_BOOST_VERSION="1.6"
ARG GETH_VERSION="1.13.13"
ARG LIGHTHOUSE_VERSION="5.0.0"
ARG TEKU_VERSION="24.2.0"
ARG MEV_BOOST_VERSION="1.7a1"

# prysm image
FROM bitnami/minideb:${DEBIAN_RELEASE} AS prysmbuilder
Expand All @@ -38,7 +38,7 @@ FROM bitnami/minideb:${DEBIAN_RELEASE} AS prysmbuilder
ARG BAZELISK_VERSION="1.17.0"
ARG BAZELISK_SHA256="61699e22abb2a26304edfa1376f65ad24191f94a4ffed68a58d42b6fee01e124"

ARG PRYSM_REF="refs/tags/v4.0.8"
ARG PRYSM_REF="refs/tags/v4.2.0"

ENV BAZELISK_VERSION="${BAZELISK_VERSION}"
ENV PRYSM_REF="${PRYSM_REF}"
Expand All @@ -62,7 +62,7 @@ RUN find -L /usr/local/prysm

# builder and relay
FROM bitnami/minideb:${DEBIAN_RELEASE} AS mevbuilder
ARG FLASHBOTS_BUILDER_REF="v1.11.5-0.2.1"
ARG FLASHBOTS_BUILDER_REF="7845c515c32ef08f15c420fda0f5de4f2e6800cd"
ARG MAINIFOLD_FREELAY_REF="support-privatenet"
ENV GO_1_20_SHA256="5a9ebcc65c1cce56e0d2dc616aff4c4cedcfbda8cc6f0288cc08cda3b18dcbf1"

Expand Down Expand Up @@ -92,19 +92,19 @@ RUN PATH="/usr/local/go/bin/:$PATH" go run build/ci.go install -static ./cmd/get
# genesis & zcli tools
FROM bitnami/minideb:${DEBIAN_RELEASE} AS genesisbuilder
# Testnet baking accessories
ARG ZCLI_REF="refs/tags/v0.6.0"
ARG ETH2_TESTNET_GENESIS_REF="refs/tags/v0.8.0"
ENV GO_1_19_SHA256="464b6b66591f6cf055bc5df90a9750bf5fbc9d038722bb84a9d56a2bea974be6"
ARG ZCLI_REF="refs/tags/v0.7.1"
ARG ETH2_TESTNET_GENESIS_REF="4b3498476f14b872b43080eee319adea45286daf"
ENV GO_1_21_SHA256="13b76a9b2a26823e53062fa841b07087d48ae2ef2936445dc34c4ae03293702c"
ENV ZCLI_REF="${ZCLI_REF}"
ENV ETH2_TESTNET_GENESIS_REF="${ETH2_TESTNET_GENESIS_REF}"
WORKDIR /usr/local/src/

RUN install_packages curl ca-certificates git build-essential

# Install golang
RUN cd /tmp && curl -OL https://golang.org/dl/go1.19.linux-amd64.tar.gz
RUN echo "${GO_1_19_SHA256} /tmp/go1.19.linux-amd64.tar.gz" | sha256sum -c
RUN cd /tmp && tar -C /usr/local -xvf go1.19.linux-amd64.tar.gz
RUN cd /tmp && curl -OL https://golang.org/dl/go1.21.7.linux-amd64.tar.gz
RUN echo "${GO_1_21_SHA256} /tmp/go1.21.7.linux-amd64.tar.gz" | sha256sum -c
RUN cd /tmp && tar -C /usr/local -xvf go1.21.7.linux-amd64.tar.gz

# Build zcli
RUN git clone https://github.com/protolambda/zcli.git && cd zcli && git fetch origin "${ZCLI_REF}" && git checkout "${ZCLI_REF}"
Expand All @@ -116,7 +116,7 @@ RUN cd eth2-testnet-genesis && PATH="/usr/local/go/bin/:$PATH" go build

# builder and relay
FROM bitnami/minideb:${DEBIAN_RELEASE} AS ethodbuilder
ARG ETHDO_REF="v1.31.0"
ARG ETHDO_REF="5895bbfbe6484505ddf666f0f4c0e25dde3cce9b"
Copy link

Choose a reason for hiding this comment

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

Why do we need Ethdo?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It triggers voluntary exit of validators in the test suite, see https://github.com/ChorusOne/eth-possim/blob/main/tests/test_pos_privatenet.py#L156

ENV GO_1_20_SHA256="5a9ebcc65c1cce56e0d2dc616aff4c4cedcfbda8cc6f0288cc08cda3b18dcbf1"

RUN install_packages curl ca-certificates git build-essential
Expand All @@ -126,7 +126,7 @@ RUN echo "${GO_1_20_SHA256} /tmp/go1.20.linux-amd64.tar.gz" | sha256sum -c
RUN cd /tmp && tar -C /usr/local -xvf go1.20.linux-amd64.tar.gz

WORKDIR /usr/local/src/
RUN git clone https://github.com/wealdtech/ethdo.git && cd ethdo && git fetch origin "${ETHDO_REF}" && git checkout "${ETHDO_REF}"
RUN git clone https://github.com/ChorusOne/ethdo.git && cd ethdo && git fetch origin "${ETHDO_REF}" && git checkout "${ETHDO_REF}"
Copy link

Choose a reason for hiding this comment

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

Why do we need to use a fork again?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Because upstream does not support Deneb, in fork the SSZ libraries are updated to the latest version that supports it to some degree

Copy link

Choose a reason for hiding this comment

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

we can just create an issue/send a pr

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Before that pr is merged, need to use forked version

Copy link

Choose a reason for hiding this comment

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

yeah sure- you've pushed one already?

RUN cd ethdo && PATH="/usr/local/go/bin/:$PATH" go mod download
RUN cd ethdo && PATH="/usr/local/go/bin/:$PATH" go build

Expand Down
22 changes: 18 additions & 4 deletions eth_possim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ def deploy_batch_deposit_contract(rpc: str):
with open("./.data/configuration.yaml", "w") as f:
yaml.dump(cfg, f)


@cli.command()
@click.option("--rpc", help="RPC endpoint URL address.", default="")
def deploy_fee_manager_contracts(rpc: str):
Expand All @@ -97,34 +98,47 @@ def deploy_fee_manager_contracts(rpc: str):
rpc=rpc,
foundry_json_path=f"{cfg['resources']}/ethereum_compiled_contracts/FeeRewardsManager.json",
args=[2800],
libraries=[("__$c56d76a1417c078a963cba4fa22c45184c$__", fee_manager_library_address)]
libraries=[
("__$c56d76a1417c078a963cba4fa22c45184c$__", fee_manager_library_address)
],
)
cfg["cl"]["fee_manager_address"] = fee_manager_address

with open("./.data/configuration.yaml", "w") as f:
yaml.dump(cfg, f)


@cli.command()
@click.option("--rpc", help="RPC endpoint URL address.", default="")
@click.option("--path", help="Path to the contract source.")
@click.option("--cfg-key-address", help="Key in which to save the contract address.")
@click.option("--library", multiple=True, type=(str, str), help="Libraries to be replaced in the bytecode contract in the format key value")
@click.option(
"--library",
multiple=True,
type=(str, str),
help="Libraries to be replaced in the bytecode contract in the format key value",
)
@click.argument("args", nargs=-1)
def deploy_contract_bytecode(rpc: str, path: str, cfg_key_address: str, args: list, library: list):
def deploy_contract_bytecode(
rpc: str, path: str, cfg_key_address: str, args: list, library: list
):
"""Deploys a contract by the compiled bytecode and abi."""

with open("./.data/configuration.yaml", "r") as f:
cfg = yaml.safe_load(f)
if not rpc:
rpc = f"http://localhost:{cfg['haproxy']['el']['port_geth_rpc']}"

contract_address = deploy_compiled_contract(cfg=cfg, rpc=rpc, foundry_json_path=path, args=args, libraries=library)
contract_address = deploy_compiled_contract(
cfg=cfg, rpc=rpc, foundry_json_path=path, args=args, libraries=library
)

# Patch and write back `configuration.yaml`
cfg["cl"][cfg_key_address] = contract_address
with open("./.data/configuration.yaml", "w") as f:
yaml.dump(cfg, f)


@cli.command()
@click.option("--rpc", help="RPC endpoint URL address.", default="")
@click.option("--path", help="Path to the contract source.")
Expand Down
38 changes: 29 additions & 9 deletions eth_possim/contracts.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,21 +4,29 @@
import solcx
import web3
import re
import time
from typing import List, Tuple


logger = logging.getLogger(__name__)

def deploy_compiled_contract(cfg: dict, rpc: str, foundry_json_path: str, args: list = [], libraries: List[Tuple[str, str]] = []) -> str:

def deploy_compiled_contract(
cfg: dict,
rpc: str,
foundry_json_path: str,
args: list = [],
libraries: List[Tuple[str, str]] = [],
) -> str:
with open(foundry_json_path, "r") as f:
foundry_json = json.loads(f.read())

bytecode_str = foundry_json["bytecode"]["object"][2:]
for library in libraries:
# Skip 0x from the library address.
bytecode_str = bytecode_str.replace(library[0], library[1][2:])
bytecode_str = bytecode_str.replace(library[0], library[1][2:])
bytecode = binascii.unhexlify(bytecode_str)

abi = foundry_json["abi"]

w3 = web3.Web3(web3.Web3.HTTPProvider(rpc))
Expand Down Expand Up @@ -54,6 +62,7 @@ def deploy_compiled_contract(cfg: dict, rpc: str, foundry_json_path: str, args:

return tx_receipt["contractAddress"]


def deploy_contract_onchain(
cfg: dict, rpc: str, path: str, name: str, args: list = []
) -> str:
Expand Down Expand Up @@ -96,10 +105,21 @@ def deploy_contract_onchain(
private_key=cfg["el"]["funder"]["private_key"],
)
w3.eth.send_raw_transaction(signed_txn.rawTransaction)
tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn.hash)
for _ in range(1, 10):
try:
tx_receipt = w3.eth.wait_for_transaction_receipt(signed_txn.hash)
except ValueError as exc:
if exc.args[0]["message"] == "transaction indexing is in progress":
logger.info(
"Failed to get transaction receipt due to indexing, will retry"
)
time.sleep(5)
continue
else:
raise

logger.info(
f"Contract from '{path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]"
)
logger.info(
f"Contract from '{path}' was published at address '{tx_receipt['contractAddress']}' [block: {tx_receipt['blockNumber']}]"
)

return tx_receipt["contractAddress"]
return tx_receipt["contractAddress"]
15 changes: 14 additions & 1 deletion eth_possim/resources/cl/minimal.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ PRESET_BASE: 'minimal'
# * 'mainnet' - there can be only one
# * 'prater' - testnet
# Must match the regex: [a-z0-9\-]
CONFIG_NAME: 'minimal'
# CONFIG_NAME: 'minimal'
# read from privatenet.yaml

# Transition
# ---------------------------------------------------------------
Expand Down Expand Up @@ -95,3 +96,15 @@ DEPOSIT_CHAIN_ID: 5
DEPOSIT_NETWORK_ID: 5
# Configured on a per testnet basis
DEPOSIT_CONTRACT_ADDRESS: 0xde1802CF413AC060F06abB158b15762016c196ad


# Misc
# ---------------------------------------------------------------
# [customized]
FIELD_ELEMENTS_PER_BLOB: 4096
# [customized]
MAX_BLOB_COMMITMENTS_PER_BLOCK: 16
# `uint64(6)`
MAX_BLOBS_PER_BLOCK: 6
# [customized] `floorlog2(BLOB_KZG_COMMITMENTS_GINDEX) + 1 + ceillog2(MAX_BLOB_COMMITMENTS_PER_BLOCK)` = 4 + 1 + 4 = 9
KZG_COMMITMENT_INCLUSION_PROOF_DEPTH: 9
3 changes: 2 additions & 1 deletion eth_possim/resources/cl/privatenet.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,13 @@ GENESIS_DELAY: 0
ALTAIR_FORK_EPOCH: 0
BELLATRIX_FORK_EPOCH: 0
CAPELLA_FORK_EPOCH: 0
DENEB_FORK_EPOCH: 0

EPOCHS_PER_SYNC_COMMITTEE_PERIOD: 8

# A.K.A. EIP4844
DENEB_FORK_VERSION: "0x04000001"
DENEB_FORK_EPOCH: 18446744073709551615


# Very fast deposit discovery
ETH1_FOLLOW_DISTANCE: 6
Expand Down
1 change: 1 addition & 0 deletions eth_possim/resources/el/genesis.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
"terminalTotalDifficulty": 0,
"terminalTotalDifficultyPassed": true,
"shanghaiTime": 0,
"cancunTime": 0,
"ethash": {}
},
"difficulty": "1",
Expand Down
7 changes: 3 additions & 4 deletions eth_possim/resources/shell/cl/__init/eth2-genesis.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@

set -euxo pipefail

# Generate post-merge (Capella-enabled) genesis
# Generate Deneb genesis
genesis_args=(
capella
--legacy-config {{ cfg.meta.dir.cl }}/etc/config-prysm.yaml
deneb
--config {{ cfg.meta.dir.cl }}/etc/config-prysm.yaml
--mnemonics {{ cfg.meta.dir.cl }}/etc/mnemonics.yaml
--tranches-dir {{ cfg.meta.dir.cl }}/etc/tranches
Expand All @@ -20,7 +19,7 @@ genesis_args=(
)

pretty_args=(
capella
deneb
BeaconState
--config {{ cfg.meta.dir.cl }}/etc/config-prysm.yaml
--preset-phase0 minimal
Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
pytest
pytest-ordering
pytest-timeout
pytest-timeout
typing-extensions
12 changes: 6 additions & 6 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,15 @@


setup(
name='eth_possim',
version='0.1.0',
description='''
name="eth_possim",
version="0.1.0",
description="""
Run full-featured Ethereum PoS simulator (private net) locally or in CI/CD,
with experimental PBS (MEV) emulation support.
''',
packages=find_packages(exclude=['ez_setup', 'tests', 'tests.*']),
""",
packages=find_packages(exclude=["ez_setup", "tests", "tests.*"]),
include_package_data=True,
install_requires=requires,
python_requires='==3.11',
python_requires="==3.11",
author_email="[email protected]",
)
Loading
Loading