From a66e0f2c069da294b0e882d4cf6a2c5a08760296 Mon Sep 17 00:00:00 2001 From: John Saigle Date: Wed, 26 Feb 2025 08:57:31 -0500 Subject: [PATCH 01/14] txverifier: Add integration test cases and refactor - Add integration test case for Transfer Tokens (in addition to existing Transfer Tokens With Payload' - Refactor integration test set-up. Now there is only one YAML file to manage instead of two. The tests have also been expanded to check for a variable number of error strings and include a timeout. They also report an error if too many error strings are found. - The Tilt configuration now runs this test as a Job rather than a Deployment. This is more appropriate for a test that is meant to run once. --- Tiltfile | 14 +- devnet/tx-verifier-monitor/Dockerfile | 2 - devnet/tx-verifier-monitor/README.md | 33 ++--- devnet/tx-verifier-monitor/monitor.sh | 53 +++++-- .../transfer-verifier-test.sh | 134 +++++++++++++++--- devnet/tx-verifier-test.yaml | 32 ----- devnet/tx-verifier.yaml | 50 +++++-- 7 files changed, 219 insertions(+), 99 deletions(-) delete mode 100644 devnet/tx-verifier-test.yaml diff --git a/Tiltfile b/Tiltfile index 600c548118..4b342384ee 100644 --- a/Tiltfile +++ b/Tiltfile @@ -663,8 +663,6 @@ if ci_tests: # transfer-verifier -- daemon and log monitoring k8s_yaml_with_ns("devnet/tx-verifier.yaml") - k8s_yaml_with_ns("devnet/tx-verifier-test.yaml") - # separate resources to parallelize docker builds k8s_resource( "sdk-ci-tests", @@ -696,19 +694,13 @@ if ci_tests: trigger_mode = trigger_mode, resource_deps = [], # testing/querysdk.sh handles waiting for query-server, not having deps gets the build earlier ) - # launches tx-verifier binary and sets up monitoring script - k8s_resource( - "tx-verifier-with-monitor", - resource_deps = ["eth-devnet"], - labels = ["tx-verifier"], - trigger_mode = trigger_mode, - ) - # triggers the integration tests that will be detected by the monitor + # launches Transfer Verifier binary and sets up monitoring script k8s_resource( "tx-verifier-test", - resource_deps = ["eth-devnet", "tx-verifier-with-monitor"], + resource_deps = ["eth-devnet"], labels = ["tx-verifier"], trigger_mode = trigger_mode, + auto_init=True, ) if terra_classic: diff --git a/devnet/tx-verifier-monitor/Dockerfile b/devnet/tx-verifier-monitor/Dockerfile index 0e9be40bd3..768bfc914a 100644 --- a/devnet/tx-verifier-monitor/Dockerfile +++ b/devnet/tx-verifier-monitor/Dockerfile @@ -6,5 +6,3 @@ RUN apk add --no-cache inotify-tools COPY monitor.sh /monitor.sh RUN chmod +x /monitor.sh - -CMD ["/monitor.sh"] diff --git a/devnet/tx-verifier-monitor/README.md b/devnet/tx-verifier-monitor/README.md index 7102b16531..4823771375 100644 --- a/devnet/tx-verifier-monitor/README.md +++ b/devnet/tx-verifier-monitor/README.md @@ -4,7 +4,7 @@ ### Overview -The Transfer Verifier tests involve interacting with the local ethereum devnet defined by the Tilt set-up in this repository. +The Transfer Verifier tests involve interacting with the local Ethereum devnet defined by the Tilt set-up in this repository. The basic idea is as follows: * Interact with the local Ethereum testnet. This should already have important pieces such as the Token Bridge and Core Bridge deployed. @@ -26,39 +26,40 @@ transactions to the `anvil` instance that powers the Ethereum testnet while bein This lets us perform actions that otherwise should be impossible, like causing a Publish Message event to be emitted from the Core Bridge without a corresponding deposit or transfer into the Token Bridge. +The current integration test sends exactly two messages, each one corresponding to a different Token Bridge endpoint +(Transfer and Transfer With Payload). + #### monitor.sh A bash script that monitors the error log file for a specific error pattern. It runs in an infinite loop so it will not exit until the error pattern is detected. -The error pattern is defined in `wormhole/devnet/tx-verifier.yaml` and matches an error string in the Transfer Verifier package. +The error pattern is defined in `devnet/tx-verifier.yaml` and matches an error string in the Transfer Verifier package. Once the pattern is detected, a success message is logged to a status file. Currently this is unused but this set-up could be modified to detect that this script has written the success message to figure out whether the whole test completed successfully. -### Pods +The integration test is considered successful as soon as two instances of the error pattern are detected, one for +each message type sent by the `transfer-verifier-test.sh`. -The files detailed below each have a primary role and are responsible for running one of the main pieces of the test functionality: +### YAML File Description +The YAML file that runs the integration tests runs three containers: * The Transfer Verifier binary which monitors the state of the local Ethereum network * The integration test script that generates activity that the Transfer Verifier classifies as malicious * The monitor script which ensures that the Transfer Verifier successfully detected the error we expected, and signals to Tilt that the overall test has succeeded -#### devnet/tx-verifier.yaml - -Runs the Transfer Verifier binary and redirects its STDERR to the error log file. This allows the output of the binary -to be monitored by `monitor.sh`. - -#### devnet/tx-verifier-test.yaml +## Further Work -Runs the `transfer-verifier-test.sh` script which simulates malicious Token Bridge activity. Defines the RPC URL used -by that bash script, which corresponds to the `anvil` instance created in the Ethereum devnet. +The tests cover the case where the Transfer Verifier should report when a Message Publication receipt from the +Token Bridge with a transfer type does not contain any deposits or transfers. -#### devnet/tx-verifier-monitor.yaml +However, the Transfer Verifier can do more than this. It also reports cases where the incoming funds to the Token +Bridge within one receipt are less than the amount encoded in the payload that it sends to the Core Bridge. This +is something like the transfer not being solvent at the resolution of one Ethereum Receipt. -Defines the expected error string that should be emitted by the Transfer Verifier code assuming that it successfully recognizes -the malicious Token Bridge activity simulated by the `cast` commands in `transfer-verifier-test.sh`. +Adding this test would be a good improvement but requires a more complicated test pattern, perhaps combining +multiple transactions into a single call to `cast`. -It also defines a path to the log file that contains this string. diff --git a/devnet/tx-verifier-monitor/monitor.sh b/devnet/tx-verifier-monitor/monitor.sh index 9ccdc8efb1..a5a695055a 100755 --- a/devnet/tx-verifier-monitor/monitor.sh +++ b/devnet/tx-verifier-monitor/monitor.sh @@ -1,8 +1,14 @@ #!/bin/sh - log_file="${ERROR_LOG_PATH:-/logs/error.log}" error_pattern="${ERROR_PATTERN:-ERROR}" -status_file="/logs/status" +status_file="${STATUS_FILE:-/logs/status}" +timeout="${TIMEOUT_SECONDS:-500}" +poll_interval=2 # Check for changes every 2 seconds + +# Compare with the integration test script: devnet/tx-verifier-monitor/transfer-verifier-test.sh +TARGET=2 + +echo "Beginning test with configured timeout of ${timeout} seconds" # Wait for log file to exist and be non-empty while [ ! -s "${log_file}" ]; do @@ -10,16 +16,43 @@ while [ ! -s "${log_file}" ]; do sleep 5 done -# Initialize status -echo "RUNNING" > "$status_file" -echo "Monitoring file '${log_file}' for error pattern: '${error_pattern}'" +# Calculate end time +end_time=$(($(date +%s) + timeout)) + +echo "Monitoring file '${log_file}' for ${TARGET} total instance(s) of error pattern: '${error_pattern}'" + +# Initialize counters +count=0 +prev_count=0 -# Watch for changes in the log file. If we find the error pattern that means we have -# succeeded. (Transfer verifier should correctly detect errors. -inotifywait -m -e modify "${log_file}" | while read -r directory events filename; do - if grep -q "$error_pattern" "$log_file"; then +# Poll until timeout or success +while [ $(date +%s) -lt $end_time ]; do + # Count current instances of the pattern + current_count=$(grep -c "$error_pattern" "$log_file") + + # Check if we found more instances + if [ $current_count -gt $prev_count ]; then + count=$((count + (current_count - prev_count))) + echo "Found error pattern: '${error_pattern}'" + echo "${count} instance(s) found so far." + prev_count=$current_count + fi + + # Check for success condition + if [ $current_count -eq $TARGET ]; then + echo "SUCCESS: Found ${current_count} instances of error pattern. Exiting." echo "SUCCESS" > "$status_file" - echo "Found error pattern. Exiting." exit 0 fi + + if [ $current_count -gt $TARGET ]; then + echo "Wanted ${TARGET} instances of error pattern but got ${current_count}. This is probably a bug." + fi + + # Sleep briefly before polling again + sleep $poll_interval done + +# If we reach here, the test timed out +echo "Test failed: Timed out after ${timeout} seconds." +exit 1 diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier-monitor/transfer-verifier-test.sh index 18e98bef1e..dfc28daa0b 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier-monitor/transfer-verifier-test.sh @@ -1,4 +1,27 @@ #!/usr/bin/env bash +# Overview +# This script simulates unusual, dangerous messages being emitted by the Core Bridge. +# Its purpose is to be used as an integration test for the Transfer Verifier. The +# Transfer Verifier can be set up as standalone binary to monitor the core bridge. +# Once this is done, this script can be used to simulate dangerous scenarios. The +# Transfer Verifier should pick up on this behaviour and log errors accordingly. +# +# Strategy +# The code below sets up several contract and wallet addresses that match +# the state of the devnet created by Tilt. Using the anvil and cast tools +# from foundry, it impersonates the Token Bridge, setting its address +# as the sender for messages to the core bridge. It sends messages that +# contain token transfer data. The Core Bridge emits a Message Publication +# as a result. However, no actual funds have been sent from a user into the +# Token Bridge. This is the danger that Transfer Verifier should detect. +# +# Coverage +# The code currently sends both a Transfer and Transfer With Payload type. +# As a result, exactly 2 violations should be detected by the Transfer Verifier. +# It should report an error that says that a message was sent without any +# transfers or deposits in its receipt. (Compare this with +# devnet/tx-verifier-monitor/monitor.sh) + set -euo pipefail RPC="${RPC_URL:-ws://eth-devnet:8545}" @@ -28,11 +51,34 @@ FROM="${ETH_WHALE}" RECIPIENT="0x00000000000000000000000064E078A8Aa15A41B85890265648e965De686bAE6" NONCE="234" # arbitrary -# Build the payload for token transfers. Declared on multiple lines to -# be more legible. Data pulled from an arbitrary LogMessagePublished event -# on etherscan. Metadata and fees commented out, leaving only the payload -PAYLOAD="0x" -declare -a SLOTS=( +# Build the payloads for token transfers. The payloads are built using +# arrays of strings and are concatenated together in a loop. Also, the +# data is declared on multiple lines in 32 bytes chunks. This isn't +# necessary but it makes the data a little easier to grok and work with. +# +# The data is pulled from an arbitrary LogMessagePublished event on +# etherscan. Metadata and fees are commented out, leaving only the payload. +# Note that the first non-commented byte corresponds to the payload type. +# (https://wormhole.com/docs/learn/infrastructure/vaas/#payload-types) + +declare -a TRANSFER_SLOTS=( + # "0000000000000000000000000000000000000000000000000000000000077009" + # "0000000000000000000000000000000000000000000000000000000067be1656" + # "0000000000000000000000000000000000000000000000000000000000000080" + # "0000000000000000000000000000000000000000000000000000000000000001" + # "0000000000000000000000000000000000000000000000000000000000000085" + "01000000000000000000000000000000000000000000000000000006c0260fe4" + "5f0000000000000000000000006b0b3a982b4634ac68dd83a4dbf02311ce3241" + "810002a5f3c5bf0f76bb899300b7ec6345ed3740f22fd4bb79501bc6204938fc" + "3a6c780001000000000000000000000000000000000000000000000000000000" + "0000000000000000000000000000000000000000000000000000000000000000" +) + +# Note that the token address of `ERC20_ADDR` appears within the payload +# but is not aligned with the slot size, i.e. the last byte of +# the address is found on the following line. This is not ideal to work +# with but it matches how the core bridge actually works. +declare -a TRANSFER_WITH_PAYLOAD_SLOTS=( # "0000000000000000000000000000000000000000000000000000000000055baf" # "0000000000000000000000000000000000000000000000000000000000000000" # "0000000000000000000000000000000000000000000000000000000000000080" @@ -45,12 +91,23 @@ declare -a SLOTS=( "f72b4160f10001010200c91f01004554480044eca3f6295d6d559ca1d99a5ef5" "a8f72b4160f10000000000000000000000000000000000000000000000000000" ) -for i in "${SLOTS[@]}" + +# Build payloads by joining the arrays of hex strings. +TRANSFER_DATA="0x" +TRANSFER_WITH_PAYLOAD_DATA="0x" + +for i in "${TRANSFER_SLOTS[@]}" +do + TRANSFER_DATA="$TRANSFER_DATA$i" +done + +for i in "${TRANSFER_WITH_PAYLOAD_SLOTS[@]}" do - PAYLOAD="$PAYLOAD$i" + TRANSFER_WITH_PAYLOAD_DATA="$TRANSFER_WITH_PAYLOAD_DATA$i" done -echo "DEBUG:" +# Header information for beginning the test. +echo "Beginning test with the following configuration" echo "- RPC=${RPC}" echo "- CORE_BRIDGE_CONTRACT=${CORE_BRIDGE_CONTRACT}" echo "- TOKEN_BRIDGE_CONTRACT=${TOKEN_BRIDGE_CONTRACT}" @@ -60,11 +117,13 @@ echo "- VALUE=${VALUE}" echo "- RECIPIENT=${RECIPIENT}" echo -# Fund the token bridge from the user -echo "Start impersonating Anvil key: ${ANVIL_USER}" +# Fund the token bridge from the user. +echo "Start impersonating Anvil user: ${ANVIL_USER}" cast rpc \ anvil_impersonateAccount "${ANVIL_USER}" \ --rpc-url "${RPC}" + +# Set-up function to make sure that the token bridge in the devnet is solvent. echo "Funding token bridge using the user's balance" cast send --unlocked \ --rpc-url "${RPC}" \ @@ -72,11 +131,13 @@ cast send --unlocked \ --value 100000000000000 \ ${TOKEN_BRIDGE_CONTRACT} echo "" -echo "End impersonating User0" +echo "End impersonating ${ANVIL_USER}" cast rpc \ anvil_stopImpersonatingAccount "${ANVIL_USER}" \ --rpc-url "${RPC}" +# Start the test, printing the conditions before any Token Bridge +# activity (except the initial funding). BALANCE_CORE=$(cast balance --rpc-url "${RPC}" $CORE_BRIDGE_CONTRACT) BALANCE_TOKEN=$(cast balance --rpc-url "${RPC}" $TOKEN_BRIDGE_CONTRACT) BALANCE_USER=$(cast balance --rpc-url "${RPC}" $ANVIL_USER) @@ -86,18 +147,24 @@ echo "- TOKEN_BRIDGE_CONTRACT=${BALANCE_TOKEN}" echo "- ANVIL_USER=${BALANCE_USER}" echo -# === Malicious call to transferTokensWithPayload() -# This is the exploit scenario: the token bridge has called publishMessage() without a ERC20 Transfer or Deposit -# being present in the same receipt. -# This is done by impersonating the token bridge contract and sending a message directly to the core bridge. -# Ensure that anvil is using `--auto-impersonate` or else that account impersonation is enabled in your local environment. -# --private-key "$MNEMONIC" \ -# --max-fee 500000 \ +# Simulate the Token Bridge so that it's possible to communicate with the core +# bridge in arbitrary ways. Normally, the only path to do this would involve +# doing a WETH Deposit or ERC20 transfer in the same transaction. This is +# exactly the invariant that we are trying to test with Transfer Verifier. If +# the Token Bridge can cause a Message Publication from the Core Bridge without +# any funds being sent into in to the Token Bridge first, there's a serious +# error. +# Ensure that anvil is using `--auto-impersonate` or else that account +# impersonation is enabled in your local environment. For Tilt, this should +# be handled already by the eth-devnet pod. echo "Start impersonate token bridge" cast rpc \ --rpc-url "${RPC}" \ anvil_impersonateAccount "${TOKEN_BRIDGE_CONTRACT}" -echo "Calling publishMessage as ${TOKEN_BRIDGE_CONTRACT}" + +# === Test Scenario 1: Malicious call to transferTokens() +NONCE=0 +echo "Calling publishMessage() with transferTokens() payload as ${TOKEN_BRIDGE_CONTRACT}" cast send --unlocked \ --rpc-url "${RPC}" \ --json \ @@ -107,13 +174,40 @@ cast send --unlocked \ --value "0" \ "${CORE_BRIDGE_CONTRACT}" \ "publishMessage(uint32,bytes,uint8)" \ - 0 "${PAYLOAD}" 1 + $NONCE "${TRANSFER_DATA}" 1 echo "" +NONCE=$(($NONCE + 1)) + +# === Test Scenario 2: Malicious call to transferTokensWithPayload() +echo "Calling publishMessage() with transferTokensWithPayload() payload as ${TOKEN_BRIDGE_CONTRACT}" +cast send --unlocked \ + --rpc-url "${RPC}" \ + --json \ + --gas-limit 10000000 \ + --priority-gas-price 1 \ + --from "${TOKEN_BRIDGE_CONTRACT}" \ + --value "0" \ + "${CORE_BRIDGE_CONTRACT}" \ + "publishMessage(uint32,bytes,uint8)" \ + 1 "${TRANSFER_WITH_PAYLOAD_DATA}" 1 +echo "" + +# Cleanup. cast rpc \ --rpc-url "${RPC}" \ anvil_stopImpersonatingAccount "${TOKEN_BRIDGE_CONTRACT}" echo "End impersonate token bridge" +# Print balances after. +BALANCE_CORE=$(cast balance --rpc-url "${RPC}" $CORE_BRIDGE_CONTRACT) +BALANCE_TOKEN=$(cast balance --rpc-url "${RPC}" $TOKEN_BRIDGE_CONTRACT) +BALANCE_USER=$(cast balance --rpc-url "${RPC}" $ANVIL_USER) +echo "BALANCES:" +echo "- CORE_BRIDGE_CONTRACT=${BALANCE_CORE}" +echo "- TOKEN_BRIDGE_CONTRACT=${BALANCE_TOKEN}" +echo "- ANVIL_USER=${BALANCE_USER}" +echo + # TODO add the 'multicall' scenario encoded in the forge script echo "Done Transfer Verifier integration test." diff --git a/devnet/tx-verifier-test.yaml b/devnet/tx-verifier-test.yaml deleted file mode 100644 index 17be61586f..0000000000 --- a/devnet/tx-verifier-test.yaml +++ /dev/null @@ -1,32 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: tx-verifier-test -spec: - # Number of successful pod completions needed - completions: 1 - # Number of pods to run in parallel - parallelism: 1 - # Time limit after which the job is terminated (optional) - # activeDeadlineSeconds: 100 - # Number of retries before marking as failed - backoffLimit: 4 - template: - metadata: - labels: - app: tx-verifier-test - spec: - restartPolicy: Never - containers: - - name: tx-verifier-test - image: tx-verifier-test - command: - - /bin/bash - - -c - - "/transfer-verifier-test.sh" - env: - - name: RPC_URL - value: "ws://eth-devnet:8545" - volumes: - - name: log-volume - emptyDir: {} diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index 1130f76035..963a6bf166 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -1,21 +1,36 @@ -apiVersion: apps/v1 -kind: Deployment +apiVersion: batch/v1 +kind: Job metadata: - name: tx-verifier-with-monitor + name: tx-verifier-test spec: - selector: - matchLabels: - app: tx-verifier-with-monitor + backoffLimit: 0 + completions: 1 template: metadata: labels: - app: tx-verifier-with-monitor + app: tx-verifier spec: + restartPolicy: Never + shareProcessNamespace: true securityContext: runAsUser: 1000 runAsGroup: 1000 fsGroup: 1000 containers: + # This container runs the script that simulates malicious traffic. The Transfer Verifier should detect this. + - name: tx-verifier-test + image: tx-verifier-test + volumeMounts: + - name: log-volume + mountPath: /logs + command: + - /bin/bash + - -c + - "/transfer-verifier-test.sh" + env: + - name: RPC_URL + value: "ws://eth-devnet:8545" + # This container runs the Transfer Verifier CLI tool, monitoring the Ethereum devnet set-up by Tilt. - name: tx-verifier image: guardiand-image volumeMounts: @@ -35,6 +50,7 @@ spec: --wrappedNativeContract 0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E \ --logLevel=info \ 2> /logs/error.log \ + # This container monitors the logs generated by Transfer Verifier and signals whether the test was successful. - name: tx-verifier-monitor image: tx-verifier-monitor volumeMounts: @@ -42,10 +58,28 @@ spec: mountPath: /logs env: - name: ERROR_PATTERN - # This error string comes from the transfer-verifier binary in node/ + # This error string comes from the Transfer Verifier package in node/pkg/txverifier value: "invalid receipt: no deposits and no transfers" - name: ERROR_LOG_PATH value: "/logs/error.log" + - name: TIMEOUT_SECONDS + value: "300" # 5 minutes timeout + command: ["/bin/sh", "-c"] + args: + - | + # Run the monitoring script + /monitor.sh + + # Store the exit code + RESULT=$? + echo "Monitor script completed with exit code ${RESULT}" + + # Find and kill the guardiand process (Transfer Verifier CLI tool) + # No need to keep it running if the monitor script has completed. + pkill -f guardiand || true + + # Exit with the monitoring script's status + exit $RESULT volumes: - name: log-volume emptyDir: {} From ac6a84effd73c22ba24920811011e3f13c8f6dad Mon Sep 17 00:00:00 2001 From: John Saigle Date: Wed, 26 Feb 2025 13:54:12 -0500 Subject: [PATCH 02/14] Try disabling timeout to address Tilt CI failure --- devnet/tx-verifier.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index 963a6bf166..dde34fa502 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -63,7 +63,7 @@ spec: - name: ERROR_LOG_PATH value: "/logs/error.log" - name: TIMEOUT_SECONDS - value: "300" # 5 minutes timeout + value: "3600" # TODO: 1 hour timeout -- testing CI failures command: ["/bin/sh", "-c"] args: - | From fd9343cf6c9511420366f82476a3d0fe71739d81 Mon Sep 17 00:00:00 2001 From: John Saigle Date: Wed, 26 Feb 2025 17:23:28 -0500 Subject: [PATCH 03/14] fix attempt: add readiness probe like other jobs --- Tiltfile | 3 +- devnet/tx-verifier-monitor/monitor.sh | 42 ++-------- .../transfer-verifier-test.sh | 11 ++- devnet/tx-verifier.yaml | 78 +++++++++++-------- 4 files changed, 61 insertions(+), 73 deletions(-) diff --git a/Tiltfile b/Tiltfile index 4b342384ee..72c0b20786 100644 --- a/Tiltfile +++ b/Tiltfile @@ -697,10 +697,9 @@ if ci_tests: # launches Transfer Verifier binary and sets up monitoring script k8s_resource( "tx-verifier-test", - resource_deps = ["eth-devnet"], labels = ["tx-verifier"], trigger_mode = trigger_mode, - auto_init=True, + resource_deps = ["eth-devnet"], ) if terra_classic: diff --git a/devnet/tx-verifier-monitor/monitor.sh b/devnet/tx-verifier-monitor/monitor.sh index a5a695055a..695041e265 100755 --- a/devnet/tx-verifier-monitor/monitor.sh +++ b/devnet/tx-verifier-monitor/monitor.sh @@ -1,58 +1,32 @@ #!/bin/sh log_file="${ERROR_LOG_PATH:-/logs/error.log}" error_pattern="${ERROR_PATTERN:-ERROR}" -status_file="${STATUS_FILE:-/logs/status}" -timeout="${TIMEOUT_SECONDS:-500}" -poll_interval=2 # Check for changes every 2 seconds - -# Compare with the integration test script: devnet/tx-verifier-monitor/transfer-verifier-test.sh +poll_interval=5 TARGET=2 -echo "Beginning test with configured timeout of ${timeout} seconds" - # Wait for log file to exist and be non-empty while [ ! -s "${log_file}" ]; do echo "Waiting for ${log_file} to be created and contain data..." sleep 5 done -# Calculate end time -end_time=$(($(date +%s) + timeout)) - echo "Monitoring file '${log_file}' for ${TARGET} total instance(s) of error pattern: '${error_pattern}'" -# Initialize counters -count=0 -prev_count=0 - -# Poll until timeout or success -while [ $(date +%s) -lt $end_time ]; do - # Count current instances of the pattern +# Poll until we find the target number of instances +while true; do current_count=$(grep -c "$error_pattern" "$log_file") - # Check if we found more instances - if [ $current_count -gt $prev_count ]; then - count=$((count + (current_count - prev_count))) - echo "Found error pattern: '${error_pattern}'" - echo "${count} instance(s) found so far." - prev_count=$current_count - fi - - # Check for success condition + echo "Found ${current_count} of ${TARGET} instances so far." + if [ $current_count -eq $TARGET ]; then - echo "SUCCESS: Found ${current_count} instances of error pattern. Exiting." - echo "SUCCESS" > "$status_file" + echo "SUCCESS: Found ${TARGET} instances of error pattern. Exiting." exit 0 fi - + if [ $current_count -gt $TARGET ]; then echo "Wanted ${TARGET} instances of error pattern but got ${current_count}. This is probably a bug." + exit 1 fi - # Sleep briefly before polling again sleep $poll_interval done - -# If we reach here, the test timed out -echo "Test failed: Timed out after ${timeout} seconds." -exit 1 diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier-monitor/transfer-verifier-test.sh index dfc28daa0b..d856441c49 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier-monitor/transfer-verifier-test.sh @@ -157,10 +157,10 @@ echo # Ensure that anvil is using `--auto-impersonate` or else that account # impersonation is enabled in your local environment. For Tilt, this should # be handled already by the eth-devnet pod. -echo "Start impersonate token bridge" +echo "Start impersonating the Token Bridge" cast rpc \ --rpc-url "${RPC}" \ - anvil_impersonateAccount "${TOKEN_BRIDGE_CONTRACT}" + anvil_impersonateAccount "${TOKEN_BRIDGE_CONTRACT}" &> /dev/null # === Test Scenario 1: Malicious call to transferTokens() NONCE=0 @@ -195,8 +195,8 @@ echo "" # Cleanup. cast rpc \ --rpc-url "${RPC}" \ - anvil_stopImpersonatingAccount "${TOKEN_BRIDGE_CONTRACT}" -echo "End impersonate token bridge" + anvil_stopImpersonatingAccount "${TOKEN_BRIDGE_CONTRACT}" &> /dev/null +echo "End impersonating the Token Bridge" # Print balances after. BALANCE_CORE=$(cast balance --rpc-url "${RPC}" $CORE_BRIDGE_CONTRACT) @@ -210,5 +210,4 @@ echo # TODO add the 'multicall' scenario encoded in the forge script -echo "Done Transfer Verifier integration test." -echo "Exiting." +echo "Done Transfer Verifier integration test. Exiting" diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index dde34fa502..78753265ad 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -4,11 +4,11 @@ metadata: name: tx-verifier-test spec: backoffLimit: 0 - completions: 1 template: metadata: labels: app: tx-verifier + name: tx-verifier spec: restartPolicy: Never shareProcessNamespace: true @@ -17,6 +17,36 @@ spec: runAsGroup: 1000 fsGroup: 1000 containers: + # This container monitors the logs generated by Transfer Verifier and signals whether the test was successful. + # The readiness probe for the other containers relies on the file written by the command invoked here. + - name: tx-verifier-monitor + image: tx-verifier-monitor + volumeMounts: + - name: log-volume + mountPath: /logs + env: + - name: ERROR_PATTERN + # This error string comes from the Transfer Verifier package in node/pkg/txverifier + value: "invalid receipt: no deposits and no transfers" + - name: ERROR_LOG_PATH + value: "/logs/error.log" + command: ["/bin/sh", "-c"] + args: + - | + # Run the monitoring script + echo "staring to run the monitor script" + /monitor.sh && touch /logs/success + + pkill -f guardiand || true + exit 0 + readinessProbe: + exec: + command: + - test + - -e + - "/logs/success" + initialDelaySeconds: 30 + periodSeconds: 5 # This container runs the script that simulates malicious traffic. The Transfer Verifier should detect this. - name: tx-verifier-test image: tx-verifier-test @@ -30,6 +60,14 @@ spec: env: - name: RPC_URL value: "ws://eth-devnet:8545" + readinessProbe: + exec: + command: + - test + - -e + - "/logs/success" + initialDelaySeconds: 30 + periodSeconds: 5 # This container runs the Transfer Verifier CLI tool, monitoring the Ethereum devnet set-up by Tilt. - name: tx-verifier image: guardiand-image @@ -50,36 +88,14 @@ spec: --wrappedNativeContract 0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E \ --logLevel=info \ 2> /logs/error.log \ - # This container monitors the logs generated by Transfer Verifier and signals whether the test was successful. - - name: tx-verifier-monitor - image: tx-verifier-monitor - volumeMounts: - - name: log-volume - mountPath: /logs - env: - - name: ERROR_PATTERN - # This error string comes from the Transfer Verifier package in node/pkg/txverifier - value: "invalid receipt: no deposits and no transfers" - - name: ERROR_LOG_PATH - value: "/logs/error.log" - - name: TIMEOUT_SECONDS - value: "3600" # TODO: 1 hour timeout -- testing CI failures - command: ["/bin/sh", "-c"] - args: - - | - # Run the monitoring script - /monitor.sh - - # Store the exit code - RESULT=$? - echo "Monitor script completed with exit code ${RESULT}" - - # Find and kill the guardiand process (Transfer Verifier CLI tool) - # No need to keep it running if the monitor script has completed. - pkill -f guardiand || true - - # Exit with the monitoring script's status - exit $RESULT + readinessProbe: + exec: + command: + - test + - -e + - "/logs/success" + initialDelaySeconds: 30 + periodSeconds: 5 volumes: - name: log-volume emptyDir: {} From 1370c568c95cb076cae19a606fad8ab0af58366a Mon Sep 17 00:00:00 2001 From: John Saigle Date: Fri, 28 Feb 2025 09:11:00 -0500 Subject: [PATCH 04/14] fix attempt: remove pkill on the binary (leave it running) --- devnet/tx-verifier.yaml | 3 --- 1 file changed, 3 deletions(-) diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index 78753265ad..055e31306c 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -36,9 +36,6 @@ spec: # Run the monitoring script echo "staring to run the monitor script" /monitor.sh && touch /logs/success - - pkill -f guardiand || true - exit 0 readinessProbe: exec: command: From c56a8c7525d5691ed7f0b45ded1115081f309106 Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 20:07:00 +0200 Subject: [PATCH 05/14] manually create /log/success from test and use different volume --- devnet/tx-verifier-monitor/transfer-verifier-test.sh | 2 ++ devnet/tx-verifier.yaml | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier-monitor/transfer-verifier-test.sh index d856441c49..8260fc69c2 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier-monitor/transfer-verifier-test.sh @@ -211,3 +211,5 @@ echo # TODO add the 'multicall' scenario encoded in the forge script echo "Done Transfer Verifier integration test. Exiting" + +touch /log/success diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index 055e31306c..e324e98e7e 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -48,7 +48,7 @@ spec: - name: tx-verifier-test image: tx-verifier-test volumeMounts: - - name: log-volume + - name: log-volume-2 mountPath: /logs command: - /bin/bash From acfce000349026734b4a5b39defb126e3ac7009a Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 20:11:06 +0200 Subject: [PATCH 06/14] add volume-2 --- devnet/tx-verifier.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index e324e98e7e..f788ab1b00 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -96,3 +96,5 @@ spec: volumes: - name: log-volume emptyDir: {} + - name: log-volume-2 + emptyDir: {} From 9a6da6fdcfc49f73abf00c4b8c1c475becffc0f7 Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 21:02:11 +0200 Subject: [PATCH 07/14] fix typo --- devnet/tx-verifier-monitor/transfer-verifier-test.sh | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier-monitor/transfer-verifier-test.sh index 8260fc69c2..eee4d833b3 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier-monitor/transfer-verifier-test.sh @@ -26,6 +26,11 @@ set -euo pipefail RPC="${RPC_URL:-ws://eth-devnet:8545}" +touch /logs/success + +echo "Early exiting from test" +exit 0 + # mainnet values # export CORE_CONTRACT="0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B" # export TOKEN_BRIDGE_CONTRACT="0x3ee18B2214AFF97000D974cf647E7C347E8fa585" @@ -210,6 +215,4 @@ echo # TODO add the 'multicall' scenario encoded in the forge script -echo "Done Transfer Verifier integration test. Exiting" - -touch /log/success +echo "Done Transfer Verifier integration test. Exiting" \ No newline at end of file From a15c23134a7ed400b9ad37fe538d4aaabccaa05d Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 21:09:43 +0200 Subject: [PATCH 08/14] remove volume --- devnet/tx-verifier-monitor/transfer-verifier-test.sh | 2 +- devnet/tx-verifier.yaml | 5 +---- 2 files changed, 2 insertions(+), 5 deletions(-) diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier-monitor/transfer-verifier-test.sh index eee4d833b3..2f979127eb 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier-monitor/transfer-verifier-test.sh @@ -26,7 +26,7 @@ set -euo pipefail RPC="${RPC_URL:-ws://eth-devnet:8545}" -touch /logs/success +touch /tmp/success echo "Early exiting from test" exit 0 diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index f788ab1b00..cd4f6c0669 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -47,9 +47,6 @@ spec: # This container runs the script that simulates malicious traffic. The Transfer Verifier should detect this. - name: tx-verifier-test image: tx-verifier-test - volumeMounts: - - name: log-volume-2 - mountPath: /logs command: - /bin/bash - -c @@ -62,7 +59,7 @@ spec: command: - test - -e - - "/logs/success" + - "/tmp/success" initialDelaySeconds: 30 periodSeconds: 5 # This container runs the Transfer Verifier CLI tool, monitoring the Ethereum devnet set-up by Tilt. From 4ae9da6d03f1cb12a3842e99b484fea5341b9748 Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 21:19:12 +0200 Subject: [PATCH 09/14] reverting changes --- devnet/tx-verifier-monitor/transfer-verifier-test.sh | 2 -- devnet/tx-verifier.yaml | 9 +++++---- 2 files changed, 5 insertions(+), 6 deletions(-) diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier-monitor/transfer-verifier-test.sh index 2f979127eb..4e6f2bddea 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier-monitor/transfer-verifier-test.sh @@ -26,8 +26,6 @@ set -euo pipefail RPC="${RPC_URL:-ws://eth-devnet:8545}" -touch /tmp/success - echo "Early exiting from test" exit 0 diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index cd4f6c0669..f5aa6d2c26 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -47,6 +47,9 @@ spec: # This container runs the script that simulates malicious traffic. The Transfer Verifier should detect this. - name: tx-verifier-test image: tx-verifier-test + volumeMounts: + - name: log-volume + mountPath: /logs command: - /bin/bash - -c @@ -59,7 +62,7 @@ spec: command: - test - -e - - "/tmp/success" + - "/logs/success" initialDelaySeconds: 30 periodSeconds: 5 # This container runs the Transfer Verifier CLI tool, monitoring the Ethereum devnet set-up by Tilt. @@ -92,6 +95,4 @@ spec: periodSeconds: 5 volumes: - name: log-volume - emptyDir: {} - - name: log-volume-2 - emptyDir: {} + emptyDir: {} \ No newline at end of file From 074d9248dc919651866ce65c870a47e877b60523 Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 21:46:43 +0200 Subject: [PATCH 10/14] short-circuit monitor --- devnet/tx-verifier-monitor/monitor.sh | 2 ++ 1 file changed, 2 insertions(+) diff --git a/devnet/tx-verifier-monitor/monitor.sh b/devnet/tx-verifier-monitor/monitor.sh index 695041e265..a23319641c 100755 --- a/devnet/tx-verifier-monitor/monitor.sh +++ b/devnet/tx-verifier-monitor/monitor.sh @@ -12,6 +12,8 @@ done echo "Monitoring file '${log_file}' for ${TARGET} total instance(s) of error pattern: '${error_pattern}'" +exit 0 + # Poll until we find the target number of instances while true; do current_count=$(grep -c "$error_pattern" "$log_file") From 27b7bb6515c304732b653474ab398d79c333b18f Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 22:16:22 +0200 Subject: [PATCH 11/14] add activeDeadline to make sure guardian gets killed --- devnet/tx-verifier.yaml | 1 + 1 file changed, 1 insertion(+) diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index f5aa6d2c26..508c199255 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -11,6 +11,7 @@ spec: name: tx-verifier spec: restartPolicy: Never + activeDeadlineSeconds: 900 shareProcessNamespace: true securityContext: runAsUser: 1000 From 3ce4b6b9c74b08f3fa039f51102be37004a30923 Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Thu, 6 Mar 2025 22:41:35 +0200 Subject: [PATCH 12/14] change command to be same as tests.yaml --- devnet/tx-verifier.yaml | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml index 508c199255..15aa8627ba 100644 --- a/devnet/tx-verifier.yaml +++ b/devnet/tx-verifier.yaml @@ -11,7 +11,6 @@ spec: name: tx-verifier spec: restartPolicy: Never - activeDeadlineSeconds: 900 shareProcessNamespace: true securityContext: runAsUser: 1000 @@ -31,12 +30,16 @@ spec: value: "invalid receipt: no deposits and no transfers" - name: ERROR_LOG_PATH value: "/logs/error.log" - command: ["/bin/sh", "-c"] - args: - - | - # Run the monitoring script - echo "staring to run the monitor script" - /monitor.sh && touch /logs/success + # command: ["/bin/sh", "-c"] + # args: + # - | + # # Run the monitoring script + # echo "staring to run the monitor script" + # /monitor.sh && touch /logs/success + command: + - /bin/sh + - -c + - "bash /monitor.sh && touch /logs/success" readinessProbe: exec: command: @@ -54,7 +57,7 @@ spec: command: - /bin/bash - -c - - "/transfer-verifier-test.sh" + - "bash /transfer-verifier-test.sh" env: - name: RPC_URL value: "ws://eth-devnet:8545" From 9b7cdf02681a3a11ca2468d2f9db1551a11c2a69 Mon Sep 17 00:00:00 2001 From: pleasew8t Date: Fri, 7 Mar 2025 12:46:13 +0200 Subject: [PATCH 13/14] consolidate all jobs into one --- Tiltfile | 19 ++-- devnet/tx-verifier-evm.yaml | 36 +++++++ devnet/tx-verifier.yaml | 102 ------------------ .../Dockerfile | 0 .../Dockerfile.cast | 0 devnet/tx-verifier/Dockerfile.tx-verifier-evm | 23 ++++ .../README.md | 0 .../monitor.sh | 2 - devnet/tx-verifier/tx-verifier-evm-runner.sh | 31 ++++++ .../tx-verifier-evm-tests.sh} | 3 - 10 files changed, 96 insertions(+), 120 deletions(-) create mode 100644 devnet/tx-verifier-evm.yaml delete mode 100644 devnet/tx-verifier.yaml rename devnet/{tx-verifier-monitor => tx-verifier}/Dockerfile (100%) rename devnet/{tx-verifier-monitor => tx-verifier}/Dockerfile.cast (100%) create mode 100644 devnet/tx-verifier/Dockerfile.tx-verifier-evm rename devnet/{tx-verifier-monitor => tx-verifier}/README.md (100%) rename devnet/{tx-verifier-monitor => tx-verifier}/monitor.sh (99%) create mode 100644 devnet/tx-verifier/tx-verifier-evm-runner.sh rename devnet/{tx-verifier-monitor/transfer-verifier-test.sh => tx-verifier/tx-verifier-evm-tests.sh} (99%) diff --git a/Tiltfile b/Tiltfile index 72c0b20786..1752c357b1 100644 --- a/Tiltfile +++ b/Tiltfile @@ -641,15 +641,11 @@ if ci_tests: ], ) docker_build( - ref = "tx-verifier-monitor", - context = "./devnet/tx-verifier-monitor/", - dockerfile = "./devnet/tx-verifier-monitor/Dockerfile" - ) - docker_build( - ref = "tx-verifier-test", - context = "./devnet/tx-verifier-monitor/", - dockerfile = "./devnet/tx-verifier-monitor/Dockerfile.cast" + ref = "tx-verifier-evm", + context = "./devnet/tx-verifier/", + dockerfile = "./devnet/tx-verifier/Dockerfile.tx-verifier-evm" ) + k8s_yaml_with_ns("devnet/tx-verifier-evm.yaml") k8s_yaml_with_ns( encode_yaml_stream( @@ -660,9 +656,6 @@ if ci_tests: "MAX_WORKERS", max_workers)) ) - # transfer-verifier -- daemon and log monitoring - k8s_yaml_with_ns("devnet/tx-verifier.yaml") - # separate resources to parallelize docker builds k8s_resource( "sdk-ci-tests", @@ -696,8 +689,8 @@ if ci_tests: ) # launches Transfer Verifier binary and sets up monitoring script k8s_resource( - "tx-verifier-test", - labels = ["tx-verifier"], + "tx-verifier-evm", + labels = ["tx-verifier-evm"], trigger_mode = trigger_mode, resource_deps = ["eth-devnet"], ) diff --git a/devnet/tx-verifier-evm.yaml b/devnet/tx-verifier-evm.yaml new file mode 100644 index 0000000000..356b81ecc6 --- /dev/null +++ b/devnet/tx-verifier-evm.yaml @@ -0,0 +1,36 @@ +apiVersion: batch/v1 +kind: Job +metadata: + name: tx-verifier-evm +spec: + backoffLimit: 0 + template: + spec: + restartPolicy: Never + # required, as the guardian cannot run as root + securityContext: + runAsUser: 1000 + runAsGroup: 1000 + fsGroup: 1000 + containers: + - name: tx-verifier-evm + image: tx-verifier-evm + env: + - name: ERROR_PATTERN + value: "invalid receipt: no deposits and no transfers" + - name: ERROR_LOG_PATH + value: "/tmp/error.log" + - name: RPC_URL + value: "ws://eth-devnet:8545" + command: + - /bin/bash + - -c + - "bash /tx-verifier-evm-runner.sh" + readinessProbe: + exec: + command: + - test + - -e + - "/tmp/success" + initialDelaySeconds: 5 + periodSeconds: 5 \ No newline at end of file diff --git a/devnet/tx-verifier.yaml b/devnet/tx-verifier.yaml deleted file mode 100644 index 15aa8627ba..0000000000 --- a/devnet/tx-verifier.yaml +++ /dev/null @@ -1,102 +0,0 @@ -apiVersion: batch/v1 -kind: Job -metadata: - name: tx-verifier-test -spec: - backoffLimit: 0 - template: - metadata: - labels: - app: tx-verifier - name: tx-verifier - spec: - restartPolicy: Never - shareProcessNamespace: true - securityContext: - runAsUser: 1000 - runAsGroup: 1000 - fsGroup: 1000 - containers: - # This container monitors the logs generated by Transfer Verifier and signals whether the test was successful. - # The readiness probe for the other containers relies on the file written by the command invoked here. - - name: tx-verifier-monitor - image: tx-verifier-monitor - volumeMounts: - - name: log-volume - mountPath: /logs - env: - - name: ERROR_PATTERN - # This error string comes from the Transfer Verifier package in node/pkg/txverifier - value: "invalid receipt: no deposits and no transfers" - - name: ERROR_LOG_PATH - value: "/logs/error.log" - # command: ["/bin/sh", "-c"] - # args: - # - | - # # Run the monitoring script - # echo "staring to run the monitor script" - # /monitor.sh && touch /logs/success - command: - - /bin/sh - - -c - - "bash /monitor.sh && touch /logs/success" - readinessProbe: - exec: - command: - - test - - -e - - "/logs/success" - initialDelaySeconds: 30 - periodSeconds: 5 - # This container runs the script that simulates malicious traffic. The Transfer Verifier should detect this. - - name: tx-verifier-test - image: tx-verifier-test - volumeMounts: - - name: log-volume - mountPath: /logs - command: - - /bin/bash - - -c - - "bash /transfer-verifier-test.sh" - env: - - name: RPC_URL - value: "ws://eth-devnet:8545" - readinessProbe: - exec: - command: - - test - - -e - - "/logs/success" - initialDelaySeconds: 30 - periodSeconds: 5 - # This container runs the Transfer Verifier CLI tool, monitoring the Ethereum devnet set-up by Tilt. - - name: tx-verifier - image: guardiand-image - volumeMounts: - - name: log-volume - mountPath: /logs - command: - ["/bin/sh", "-c"] - # See `ethereum/.env.test` and related shell scripts for how these values are configured in localnet testing. - args: - - | - exec /guardiand \ - transfer-verifier \ - evm \ - --rpcUrl ws://eth-devnet:8545 \ - --coreContract 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550 \ - --tokenContract 0x0290FB167208Af455bB137780163b7B7a9a10C16 \ - --wrappedNativeContract 0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E \ - --logLevel=info \ - 2> /logs/error.log \ - readinessProbe: - exec: - command: - - test - - -e - - "/logs/success" - initialDelaySeconds: 30 - periodSeconds: 5 - volumes: - - name: log-volume - emptyDir: {} \ No newline at end of file diff --git a/devnet/tx-verifier-monitor/Dockerfile b/devnet/tx-verifier/Dockerfile similarity index 100% rename from devnet/tx-verifier-monitor/Dockerfile rename to devnet/tx-verifier/Dockerfile diff --git a/devnet/tx-verifier-monitor/Dockerfile.cast b/devnet/tx-verifier/Dockerfile.cast similarity index 100% rename from devnet/tx-verifier-monitor/Dockerfile.cast rename to devnet/tx-verifier/Dockerfile.cast diff --git a/devnet/tx-verifier/Dockerfile.tx-verifier-evm b/devnet/tx-verifier/Dockerfile.tx-verifier-evm new file mode 100644 index 0000000000..7dca8ac24f --- /dev/null +++ b/devnet/tx-verifier/Dockerfile.tx-verifier-evm @@ -0,0 +1,23 @@ +# We need the built guardiand image +FROM guardiand-image as guardiand + +# These versions are pinned to match the Dockerfile in the `ethereum/` +# directory. Otherwise, there is nothing special about them and they can be +# updated alongside the other Dockerfile. +FROM --platform=linux/amd64 ghcr.io/foundry-rs/foundry:nightly-55bf41564f605cae3ca4c95ac5d468b1f14447f9@sha256:8c15d322da81a6deaf827222e173f3f81c653136a3518d5eeb41250a0f2e17ea as foundry + +# node is required to install Foundry +FROM node:19.6.1-slim@sha256:a1ba21bf0c92931d02a8416f0a54daad66cb36a85d2b73af9d73b044f5f57cfc + +# prepare cast +COPY --from=foundry /usr/local/bin/cast /bin/cast + +# prepare guardiand +COPY --from=guardiand /guardiand /bin/guardiand +COPY --from=guardiand /usr/lib/libwasmvm.*.so /usr/lib/ + +# prepare test scripts +COPY tx-verifier-evm-tests.sh /tx-verifier-evm-tests.sh +COPY tx-verifier-evm-runner.sh /tx-verifier-evm-runner.sh +RUN chmod +x /tx-verifier-evm-tests.sh +RUN chmod +x /tx-verifier-evm-runner.sh diff --git a/devnet/tx-verifier-monitor/README.md b/devnet/tx-verifier/README.md similarity index 100% rename from devnet/tx-verifier-monitor/README.md rename to devnet/tx-verifier/README.md diff --git a/devnet/tx-verifier-monitor/monitor.sh b/devnet/tx-verifier/monitor.sh similarity index 99% rename from devnet/tx-verifier-monitor/monitor.sh rename to devnet/tx-verifier/monitor.sh index a23319641c..695041e265 100755 --- a/devnet/tx-verifier-monitor/monitor.sh +++ b/devnet/tx-verifier/monitor.sh @@ -12,8 +12,6 @@ done echo "Monitoring file '${log_file}' for ${TARGET} total instance(s) of error pattern: '${error_pattern}'" -exit 0 - # Poll until we find the target number of instances while true; do current_count=$(grep -c "$error_pattern" "$log_file") diff --git a/devnet/tx-verifier/tx-verifier-evm-runner.sh b/devnet/tx-verifier/tx-verifier-evm-runner.sh new file mode 100644 index 0000000000..52c8b818e8 --- /dev/null +++ b/devnet/tx-verifier/tx-verifier-evm-runner.sh @@ -0,0 +1,31 @@ +#!/bin/sh + +log_file="${ERROR_LOG_PATH:-/logs/error.log}" +error_pattern="${ERROR_PATTERN:-ERROR}" +TARGET=2 + +# start the guardian node +guardiand \ + transfer-verifier \ + evm \ + --rpcUrl ws://eth-devnet:8545 \ + --coreContract 0xC89Ce4735882C9F0f0FE26686c53074E09B0D550 \ + --tokenContract 0x0290FB167208Af455bB137780163b7B7a9a10C16 \ + --wrappedNativeContract 0xDDb64fE46a91D46ee29420539FC25FD07c5FEa3E \ + --logLevel=info \ + 2> /tmp/error.log & + +# start the test script +/tx-verifier-evm-tests.sh + +# run the checks to see if the tests succeeded +current_count=$(grep -c "$error_pattern" "$log_file") +echo "Found ${current_count} of ${TARGET} instances" + +# if we found the requisite number of error messages, we can exit +if [ $current_count -ne $TARGET ]; then + echo "Tests failed. Only found ${current_count} of ${TARGET} required log messages" + exit 1 +fi + +touch /tmp/success \ No newline at end of file diff --git a/devnet/tx-verifier-monitor/transfer-verifier-test.sh b/devnet/tx-verifier/tx-verifier-evm-tests.sh similarity index 99% rename from devnet/tx-verifier-monitor/transfer-verifier-test.sh rename to devnet/tx-verifier/tx-verifier-evm-tests.sh index 4e6f2bddea..cd0f2511b8 100755 --- a/devnet/tx-verifier-monitor/transfer-verifier-test.sh +++ b/devnet/tx-verifier/tx-verifier-evm-tests.sh @@ -26,9 +26,6 @@ set -euo pipefail RPC="${RPC_URL:-ws://eth-devnet:8545}" -echo "Early exiting from test" -exit 0 - # mainnet values # export CORE_CONTRACT="0x98f3c9e6E3fAce36bAAd05FE09d375Ef1464288B" # export TOKEN_BRIDGE_CONTRACT="0x3ee18B2214AFF97000D974cf647E7C347E8fa585" From c2312f415b4c2758b897d1ab973f953f15e297ad Mon Sep 17 00:00:00 2001 From: John Saigle Date: Fri, 7 Mar 2025 08:43:05 -0500 Subject: [PATCH 14/14] Add guardiand to allow-list of unpinned images - Adds an exception for the guardiand docker image used by tx-verifier integration testing - Fixes various shellcheck errors in the script 1. egrep is deprecated 2. checking $? is redundant 3. regex "Dockerfile*" was being used as a glob --- scripts/check-docker-pin.sh | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/check-docker-pin.sh b/scripts/check-docker-pin.sh index 35d43801f5..73d7b4fd8a 100755 --- a/scripts/check-docker-pin.sh +++ b/scripts/check-docker-pin.sh @@ -12,9 +12,13 @@ # - We ignore solana AS (builder|ci_tests) because it's a relative reference to another FROM call # - We ignore cosmwasm_artifacts AS artifacts because it's a local reference only, is built in tilt # - We ignore base AS (ignite-go-build|ignite-vue-build) because the base image is already pinned in wormchain/Dockerfile.proto +# - We ignore guardiand-image AS guardian because this is it's a local reference built in tilt # -git ls-files -z | grep -z "Dockerfile*" | xargs -r -0 grep -s "FROM" | egrep -v 'sha256|scratch|solana|aptos|sui|base|cosmwasm_artifacts|cli-gen|const-gen|dev AS (application|base|builder|ci_tests|tests|artifacts|ignite-go-build|ignite-vue-build|cli-export|const-export|build)' -if [ $? -eq 0 ]; then +if git ls-files -z \ + | grep -Ez "(Dockerfile)" \ + | xargs -r -0 grep -s "FROM" \ + | grep -E -v 'sha256|scratch|solana|aptos|sui|base|cosmwasm_artifacts|cli-gen|const-gen|dev|guardiand-image AS (application|base|builder|ci_tests|tests|artifacts|ignite-go-build|ignite-vue-build|cli-export|const-export|build|guardian)' +then echo "[!] Unpinned docker files" >&2 exit 1 else