From cfa0c5532192423338537d70fa6b6d846e7b8099 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Keszey=20D=C3=A1niel?= Date: Tue, 8 Oct 2024 16:32:26 +0200 Subject: [PATCH] rebase make install procedure to newest base --- Dockerfile | 47 ++++++++-- .../scripts/L2_txn_simulation/sendTx.py | 69 ++++++++++++++ .../scripts/confs/network_params.yaml | 11 ++- packages/protocol/scripts/setup_deps.sh | 91 +++++++++++++++---- packages/protocol/scripts/verify_contracts.sh | 90 ++++++++++++++++++ 5 files changed, 281 insertions(+), 27 deletions(-) create mode 100755 packages/protocol/scripts/L2_txn_simulation/sendTx.py create mode 100755 packages/protocol/scripts/verify_contracts.sh diff --git a/Dockerfile b/Dockerfile index 85546548dba9..3a6514d0ef04 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,11 +1,10 @@ FROM lukemathwalker/cargo-chef:latest-rust-1 AS chef WORKDIR /app - LABEL org.opencontainers.image.source=https://github.com/paradigmxyz/reth LABEL org.opencontainers.image.licenses="MIT OR Apache-2.0" # Install system dependencies -RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config +RUN apt-get update && apt-get -y upgrade && apt-get install -y libclang-dev pkg-config git # Builds a cargo-chef plan FROM chef AS planner @@ -17,36 +16,64 @@ COPY --from=planner /app/recipe.json recipe.json # Build profile, release by default ARG BUILD_PROFILE=release -ENV BUILD_PROFILE=$BUILD_PROFILE +ENV BUILD_PROFILE $BUILD_PROFILE # Extra Cargo flags ARG RUSTFLAGS="" -ENV RUSTFLAGS="$RUSTFLAGS" +ENV RUSTFLAGS "$RUSTFLAGS" # Extra Cargo features ARG FEATURES="" -ENV FEATURES=$FEATURES +ENV FEATURES $FEATURES # Builds dependencies RUN cargo chef cook --profile $BUILD_PROFILE --features "$FEATURES" --recipe-path recipe.json - # Build application COPY . . RUN cargo build --profile $BUILD_PROFILE --features "$FEATURES" --locked --bin reth -# ARG is not resolved in COPY so we have to hack around it by copying the -# binary to a temporary location +# Hack: Add a cache busting step (above steps are the more +# time consuming ones but we need to make sure the rbuilder is +# always freshly cloned and not cached !) +# Since the content of this file will change +# with each build, Docker will consider this +# layer (and all subsequent layers) as modified, +# forcing a re-execution of the following steps. +# ADD https://worldtimeapi.org/api/ip /tmp/bustcache + +# Clone and build rbuilder (gwyneth branch) +RUN git clone -b gwyneth https://github.com/taikoxyz/rbuilder.git /app/rbuilder +WORKDIR /app/rbuilder +RUN cargo build --release + +# Copy binaries to a temporary location RUN cp /app/target/$BUILD_PROFILE/reth /app/reth +RUN cp /app/rbuilder/target/release/rbuilder /app/rbuilder # Use Ubuntu as the release image -FROM ubuntu AS runtime +FROM ubuntu:22.04 AS runtime WORKDIR /app -# Copy reth over from the build stage +# Install necessary runtime dependencies and Rust/Cargo +RUN apt-get update && apt-get install -y ca-certificates && rm -rf /var/lib/apt/lists/* + +# Install Rust and Cargo +RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y +ENV PATH="/root/.cargo/bin:${PATH}" + +# Copy reth and rbuilder binaries over from the build stage COPY --from=builder /app/reth /usr/local/bin +COPY --from=builder /app/rbuilder /usr/local/bin + +# Copy the entire rbuilder repository +COPY --from=builder /app/rbuilder /app/rbuilder # Copy licenses COPY LICENSE-* ./ +# Create start script +RUN echo '#!/bin/bash\nrbuilder run /app/rbuilder/config-gwyneth-reth.toml' > /app/start_rbuilder.sh && \ + chmod +x /app/start_rbuilder.sh + EXPOSE 30303 30303/udp 9001 8545 8546 ENTRYPOINT ["/usr/local/bin/reth"] diff --git a/packages/protocol/scripts/L2_txn_simulation/sendTx.py b/packages/protocol/scripts/L2_txn_simulation/sendTx.py new file mode 100755 index 000000000000..6e822e54cbf0 --- /dev/null +++ b/packages/protocol/scripts/L2_txn_simulation/sendTx.py @@ -0,0 +1,69 @@ +from web3 import Web3 +from eth_abi import encode +import argparse + +RPC_URL_L2 = 'http://127.0.0.1:' # Anything is fine for now as long as we dont have the L2 network, but if we have we can automate nonce and gas settings +w3_taiko_l2 = Web3(Web3.HTTPProvider(RPC_URL_L2)) + +# Some pre-loaded ETH addresses from Kurtosis private network (NO secret, no harm to use for private testnets!) +sender_addresses = ['0x8943545177806ED17B9F23F0a21ee5948eCaa776'] +sender_pks = ['bcdf20249abf0ed6d944c0288fad489e33f66b3960d9e6229c1cd214ed3bbe31'] + +receiver = '0xf93Ee4Cf8c6c40b329b0c0626F28333c132CF241' # This address also has pre-loaded ETH addresses + +parser = argparse.ArgumentParser() + +parser.add_argument("-p", "--port", help="port on localhost", + type=str, required=True) +# parser.add_argument("-c", "--chainid", help="l2 chainId", +# type=int, required=True) + +transaction_list = [] + +if __name__ == "__main__": + args = parser.parse_args() + port = args.port + w3_taiko_l2 = Web3(Web3.HTTPProvider(RPC_URL_L2+port)) + chainId = 167010 + + # Build the new tx list + idx = 0 + for sender in sender_addresses: + # Build the tx + transaction = { + 'chainId': chainId, + 'from': sender, + 'to': receiver, + 'value': w3_taiko_l2.to_wei('1', 'ether'), + 'nonce': w3_taiko_l2.eth.get_transaction_count(sender), + 'gas': 200000, + 'maxFeePerGas': 2000000000, # w3_taiko_l2.eth.gas_price or something + 'maxPriorityFeePerGas': 1000000000, + } + + # Debug prints of balance + # # Get the balance + # balance_wei = w3_taiko_l2.eth.get_balance(sender) + + # # Convert balance from Wei to Ether + # balance_eth = w3_taiko_l2.from_wei(balance_wei, 'ether') + # print("Balance before:", balance_eth) + + # 2. Sign tx with a private key + signed_txn = w3_taiko_l2.eth.account.sign_transaction(transaction, sender_pks[idx]) + + # print("RawTransaction:") + # print(signed_txn.rawTransaction) + print("RawTransaction.hex():") + print(signed_txn.rawTransaction.hex()) + + txn_hash = w3_taiko_l2.eth.send_raw_transaction(signed_txn.rawTransaction) + print("Txn hash:") + print(txn_hash.hex()) + + # # Get the balance + # balance_wei = w3_taiko_l2.eth.get_balance(sender) + + # # Convert balance from Wei to Ether + # balance_eth = w3_taiko_l2.from_wei(balance_wei, 'ether') + # print("Balance after:", balance_eth) \ No newline at end of file diff --git a/packages/protocol/scripts/confs/network_params.yaml b/packages/protocol/scripts/confs/network_params.yaml index 74119e4adf1c..e6ce20c35f68 100644 --- a/packages/protocol/scripts/confs/network_params.yaml +++ b/packages/protocol/scripts/confs/network_params.yaml @@ -3,9 +3,18 @@ participants: el_image: taiko_reth cl_type: lighthouse cl_image: sigp/lighthouse:latest + cl_extra_params: [--always-prepare-payload, --prepare-payload-lookahead, "12000"] - el_type: reth el_image: taiko_reth cl_type: teku cl_image: consensys/teku:latest network_params: - network_id: '160010' \ No newline at end of file + network_id: '160010' +additional_services: + - blockscout + - blockscout_l2_1 +port_publisher: + nat_exit_ip: KURTOSIS_IP_ADDR_PLACEHOLDER + el: + enabled: true + public_port_start: 32000 \ No newline at end of file diff --git a/packages/protocol/scripts/setup_deps.sh b/packages/protocol/scripts/setup_deps.sh index 650df26da2a4..b466c7aef3dd 100755 --- a/packages/protocol/scripts/setup_deps.sh +++ b/packages/protocol/scripts/setup_deps.sh @@ -22,15 +22,15 @@ else fi # Check if the taiko_reth image exists -#if ! docker image inspect taiko_reth >/dev/null 2>&1; then - echo "Docker image taiko_reth does not exist. Building the image..." - if ! docker build ../../ -t taiko_reth; then - echo "Failed to build the Docker image taiko_reth." - exit 1 - fi -#else -# echo "Docker image taiko_reth already exists." -#fi +# if ! docker image inspect taiko_reth >/dev/null 2>&1; then + echo "Docker image taiko_reth does not exist. Building the image..." + if ! docker build ../../ -t taiko_reth; then + echo "Failed to build the Docker image taiko_reth." + exit 1 + fi +# else +# echo "Docker image taiko_reth already exists." +# fi # Function to install Kurtosis on macOS install_kurtosis_mac() { @@ -86,20 +86,27 @@ fi echo "Running Kurtosis command..." KURTOSIS_OUTPUT=$(kurtosis run github.com/adaki2004/ethereum-package --args-file ./scripts/confs/network_params.yaml) -# Print the entire Kurtosis output for debugging +# Extract the Blockscout port +BLOCKSCOUT_PORT=$(echo "$KURTOSIS_OUTPUT" | grep -A 5 "^[a-f0-9]\+ *blockscout " | grep "http:" | sed -E 's/.*-> http:\/\/127\.0\.0\.1:([0-9]+).*/\1/' | head -n 1) + +if [ -z "$BLOCKSCOUT_PORT" ]; then + echo "Failed to extract Blockscout port." + exit 1 +fi + +echo "Extracted Blockscout port: $BLOCKSCOUT_PORT" +echo "$BLOCKSCOUT_PORT" > /tmp/kurtosis_blockscout_port +# # Print the entire Kurtosis output for debugging # echo "Kurtosis Output:" # echo "$KURTOSIS_OUTPUT" # Extract the "User Services" section USER_SERVICES_SECTION=$(echo "$KURTOSIS_OUTPUT" | awk '/^========================================== User Services ==========================================/{flag=1;next}/^$/{flag=0}flag') - # Print the "User Services" section for debugging echo "User Services Section:" echo "$USER_SERVICES_SECTION" - # Extract the dynamic port assigned to the rpc service for "el-1-reth-lighthouse" RPC_PORT=$(echo "$USER_SERVICES_SECTION" | grep -A 5 "el-1-reth-lighthouse" | grep "rpc: 8545/tcp" | sed -E 's/.* -> 127.0.0.1:([0-9]+).*/\1/') - if [ -z "$RPC_PORT" ]; then echo "Failed to extract RPC port from User Services section." exit 1 @@ -108,6 +115,51 @@ else echo "$RPC_PORT" > /tmp/kurtosis_rpc_port fi +# Extract the Starlark output section +STARLARK_OUTPUT=$(echo "$KURTOSIS_OUTPUT" | awk '/^Starlark code successfully run. Output was:/{flag=1; next} /^$/{flag=0} flag') + +# Extract the beacon_http_url for cl-1-lighthouse-reth +BEACON_HTTP_URL=$(echo "$STARLARK_OUTPUT" | jq -r '.all_participants[] | select(.cl_context.beacon_service_name == "cl-1-lighthouse-reth") | .cl_context.beacon_http_url') + +if [ -z "$BEACON_HTTP_URL" ]; then + echo "Failed to extract beacon_http_url for cl-1-lighthouse-reth." + exit 1 +else + echo "Extracted beacon_http_url: $BEACON_HTTP_URL" + echo "$BEACON_HTTP_URL" > /tmp/kurtosis_beacon_http_url +fi + +# Find the correct Docker container +CONTAINER_ID=$(docker ps --format '{{.ID}} {{.Names}}' | grep 'el-1-reth-lighthouse--' | awk '{print $1}') + +if [ -z "$CONTAINER_ID" ]; then + echo "Failed to find the el-1-reth-lighthouse container." + exit 1 +else + echo "Found container ID: $CONTAINER_ID" +fi + +# Check if the file exists in the container +FILE_PATH="/app/rbuilder/config-gwyneth-reth.toml" +if ! docker exec "$CONTAINER_ID" test -f "$FILE_PATH"; then + echo "File $FILE_PATH does not exist in the container." + exit 1 +fi + +# Update the cl_node_url in the file, regardless of its current content +ESCAPED_URL=$(echo "$BEACON_HTTP_URL" | sed 's/[\/&]/\\&/g') +UPDATE_COMMAND="sed -i '/^cl_node_url[[:space:]]*=/c\cl_node_url = [\"$ESCAPED_URL\"]' $FILE_PATH" +if docker exec "$CONTAINER_ID" sh -c "$UPDATE_COMMAND"; then + echo "Successfully updated $FILE_PATH in the container." +else + echo "Failed to update $FILE_PATH in the container." + exit 1 +fi + +# Verify the change +VERIFY_COMMAND="grep 'cl_node_url' $FILE_PATH" +VERIFICATION=$(docker exec "$CONTAINER_ID" sh -c "$VERIFY_COMMAND") +echo "Updated line in $FILE_PATH: $VERIFICATION" # Load the .env file and extract the PRIVATE_KEY if [ -f .env ]; then export $(grep -v '^#' .env | xargs) @@ -116,14 +168,21 @@ else echo ".env file not found. Please create a .env file with your PRIVATE_KEY." exit 1 fi - if [ -z "$PRIVATE_KEY" ]; then echo "PRIVATE_KEY not found in the .env file." exit 1 fi - # Run the forge foundry script using the extracted RPC port and PRIVATE_KEY FORGE_COMMAND="forge script --rpc-url http://127.0.0.1:$RPC_PORT scripts/DeployL1Locally.s.sol -vvvv --broadcast --private-key $PRIVATE_KEY --legacy" echo "Running forge foundry script..." -eval $FORGE_COMMAND +FORGE_OUTPUT=$(eval $FORGE_COMMAND | tee /dev/tty) echo "Script execution completed." + +# Extract the path to run-latest.json +RUN_LATEST_PATH=$(echo "$FORGE_OUTPUT" | grep "Transactions saved to:" | sed 's/Transactions saved to: //') + +# Run the verification script +echo "Starting contract verification..." +BLOCKSCOUT_PORT=$(cat /tmp/kurtosis_blockscout_port) +SCRIPT_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" &> /dev/null && pwd )" +"$SCRIPT_DIR/verify_contracts.sh" "$BLOCKSCOUT_PORT" "$RUN_LATEST_PATH" \ No newline at end of file diff --git a/packages/protocol/scripts/verify_contracts.sh b/packages/protocol/scripts/verify_contracts.sh new file mode 100755 index 000000000000..7ae2e41c8973 --- /dev/null +++ b/packages/protocol/scripts/verify_contracts.sh @@ -0,0 +1,90 @@ +#!/bin/bash + +# Check if both BLOCKSCOUT_PORT and RUN_LATEST_PATH are provided +if [ -z "$1" ] || [ -z "$2" ]; then + echo "Error: Both BLOCKSCOUT_PORT and RUN_LATEST_PATH must be provided" + echo "Usage: $0 " + exit 1 +fi + +BLOCKSCOUT_PORT="$1" +RUN_LATEST_PATH="$2" + +echo "Using Blockscout port: $BLOCKSCOUT_PORT" +echo "Using run-latest.json path: $RUN_LATEST_PATH" + +# Function to verify a regular contract +verify_contract() { + local address=$1 + local contract_path=$2 + local contract_name=$3 + + echo "Verifying contract: $contract_name at address $address" + forge verify-contract "$address" "$contract_path:$contract_name" \ + --watch --verifier-url "http://localhost:$BLOCKSCOUT_PORT/api" \ + --verifier blockscout --chain-id 160010 +} + +# Function to verify a proxy contract +verify_proxy_contract() { + local address=$1 + local arguments=$2 + + echo "Verifying proxy contract at address: $address" + echo "Constructor arguments: $arguments" + forge verify-contract "$address" "node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol:ERC1967Proxy" \ + --watch --verifier-url "http://localhost:$BLOCKSCOUT_PORT/api" \ + --verifier blockscout --chain-id 160010 \ + --constructor-args "$arguments" --skip-is-verified-check +} + +# Read the run-latest.json file +if [ ! -f "$RUN_LATEST_PATH" ]; then + echo "Error: run-latest.json not found at $RUN_LATEST_PATH" + exit 1 +fi + +RUN_LATEST=$(cat "$RUN_LATEST_PATH") + +# Verify regular contracts +verify_all_creates() { + local contract_name=$1 + local contract_path=$2 + + echo "Verifying all instances of $contract_name" + local addresses=$(jq -r ".transactions[] | select(.contractName == \"$contract_name\" and .transactionType == \"CREATE\") | .contractAddress" <<< "$RUN_LATEST") + + if [ -z "$addresses" ]; then + echo "No CREATE transactions found for $contract_name" + else + echo "$addresses" | while read -r address; do + if [ ! -z "$address" ]; then + verify_contract "$address" "$contract_path" "$contract_name" + fi + done + fi +} + +verify_all_creates "AddressManager" "contracts/common/AddressManager.sol" +verify_all_creates "TaikoToken" "contracts/tko/TaikoToken.sol" +verify_all_creates "TaikoL1" "contracts/L1/TaikoL1.sol" +verify_all_creates "ChainProver" "contracts/L1/ChainProver.sol" +verify_all_creates "VerifierRegistry" "contracts/L1/VerifierRegistry.sol" +verify_all_creates "MockSgxVerifier" "contracts/L1/verifiers/MockSgxVerifier.sol" + +# Verify proxy contracts +echo "Verifying ERC1967Proxy contracts:" +PROXY_CONTRACTS=$(jq -r '.transactions[] | select(.contractName == "ERC1967Proxy" and .transactionType == "CREATE")' <<< "$RUN_LATEST") +echo "$PROXY_CONTRACTS" | jq -c '.' | while read -r proxy; do + if [ ! -z "$proxy" ]; then + address=$(echo "$proxy" | jq -r '.contractAddress') + args=$(echo "$proxy" | jq -r '.arguments | join(",")') + if [ ! -z "$address" ] && [ ! -z "$args" ]; then + verify_proxy_contract "$address" "$args" + else + echo "Skipping proxy contract due to missing address or arguments" + fi + fi +done + +echo "All contracts verified." \ No newline at end of file