Skip to content

Commit 96d1d17

Browse files
authored
pull fixes from testnet (#1653)
2 parents a0083e8 + e26c62f commit 96d1d17

35 files changed

+913
-520
lines changed

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ CONFIG_FILE?=config-files/config.yaml
77
export OPERATOR_ADDRESS ?= $(shell yq -r '.operator.address' $(CONFIG_FILE))
88
AGG_CONFIG_FILE?=config-files/config-aggregator.yaml
99

10-
OPERATOR_VERSION=v0.12.1
10+
OPERATOR_VERSION=v0.12.2
1111

1212
ifeq ($(OS),Linux)
1313
BUILD_ALL_FFI = $(MAKE) build_all_ffi_linux
@@ -52,7 +52,7 @@ deps: submodules go_deps build_all_ffi ## Install deps
5252

5353
go_deps:
5454
@echo "Installing Go dependencies..."
55-
go install github.com/maoueh/zap-pretty@latest
55+
go install github.com/maoueh/zap-pretty@v0.3.0
5656
go install github.com/ethereum/go-ethereum/cmd/abigen@latest
5757
go install github.com/Layr-Labs/eigenlayer-cli/cmd/eigenlayer@latest
5858

alerts/.env.devnet

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# SLACK_WEBHOOK_URL=<YOUR_SLACK_WEBHOOK_URL>
2+
# TELEGRAM_BOT_TOKEN=<YOUR_TELEGRAM_BOT_TOKEN>
3+
# TELEGRAM_CHAT_ID=<YOUR_TELEGRAM_CHAT_ID>
4+
5+
# # Variables for contract_alerts.sh
6+
# RPC_URL=<YOUR_RPC_URL>
7+
# CONTRACT_ADDRESS=<YOUR_CONTRACT_ADDRESS>
8+
# NEW_BATCH_TOPIC=<YOUR_NEW_BATCH_TOPIC>
9+
# VERIFIED_BATCH_TOPIC=<YOUR_VERIFIED_BATCH_TOPIC>
10+
# PAGER_DUTY_KEY=<YOUR_PAGER_DUTY_KEY>
11+
# PAGER_DUTY_EMAIL=<YOUR_PAGER_DUTY_EMAIL>
12+
# PAGER_DUTY_SERVICE_ID=<YOUR_PAGER_DUTY_SERVICE_ID>
13+
14+
# # Variables for process_errors_alerts.sh
15+
# SERVICE=<YOUR_SERVICE>
16+
# EXPRESSION=<GREP_EXPRESSION>
17+
18+
# # Variables for balance_alerts.sh
19+
# RPC_URL=<YOUR_RPC_URL>
20+
# PAYMENT_CONTRACT_ADDRESS=<YOUR_PAYMENT_CONTRACT_ADDRESS>
21+
# BALANCE_THRESHOLD=<YOUR_BALANCE_THRESHOLD_IN_ETH>
22+
# WALLET_ADDRESS=<YOUR_WALLET_ADDRESS>
23+
24+
# Variables for sender_with_alert.sh
25+
REPETITIONS=8
26+
SENDER_ADDRESS=0x14dC79964da2C08b23698B3D3cc7Ca32193d9955
27+
BATCHER_URL=ws://localhost:8080
28+
RPC_URL=http://localhost:8545
29+
EXPLORER_URL=http://localhost:3000
30+
NETWORK=devnet
31+
PRIVATE_KEY=0x4bbbf85ce3377467afe5d46f804f221813b2bb87f24d81f60f1fcdbf7cbf4356
32+
VERIFICATION_WAIT_TIME=30
33+
LOGS_BLOCK_RANGE=100

alerts/.env.example

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,14 @@ RPC_URL=<YOUR_RPC_URL>
2020
PAYMENT_CONTRACT_ADDRESS=<YOUR_PAYMENT_CONTRACT_ADDRESS>
2121
BALANCE_THRESHOLD=<YOUR_BALANCE_THRESHOLD_IN_ETH>
2222
WALLET_ADDRESS=<YOUR_WALLET_ADDRESS>
23+
24+
# Variables for sender_with_alert.sh
25+
REPETITIONS=<REPETITIONS>
26+
SENDER_ADDRESS=<YOUR_SENDER_ADDRESS>
27+
BATCHER_URL=<BATCHER_URL>
28+
RPC_URL=<RPC_BASE_URL>
29+
EXPLORER_URL=<EXPLORER_BASE_URL>
30+
NETWORK=<NETWORK>
31+
PRIVATE_KEY=<SENDER_PRIVATE_KEY>
32+
VERIFICATION_WAIT_TIME=<TIME_TO_WAIT_FOR_VERIFICATION>
33+
LOGS_BLOCK_RANGE=<LOGS_BLOCK_RANGE>

alerts/sender_with_alert.sh

Lines changed: 186 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
#!/bin/bash
2+
3+
# ENV VARIABLES:
4+
# - REPETITIONS
5+
# - EXPLORER_URL
6+
# - SENDER_ADDRESS
7+
# - BATCHER_URL
8+
# - RPC_URL
9+
# - EXPLORER_URL
10+
# - NETWORK
11+
# - PRIVATE_KEY
12+
# - VERIFICATION_WAIT_TIME
13+
# - LOGS_BLOCK_RANGE
14+
# - SLEEP_TIME
15+
# - PAGER_DUTY_KEY
16+
# - PAGER_DUTY_EMAIL
17+
# - PAGER_DUTY_SERVICE_ID
18+
# - SLACK_WEBHOOK_URL
19+
20+
# TODO (Improvement):
21+
# 1. This script waits VERIFICATION_WAIT_TIME seconds before fetching the explorer for the response tx hash.
22+
# We should instead poll in a loop until the batch is marked as verified
23+
24+
# ACKNOWLEDGMENTS
25+
#
26+
# Special thanks to AniV for their contribution on StackExchange regarding AWK formatting with floating point operations:
27+
# https://unix.stackexchange.com/questions/292087/how-do-i-get-bc-to-start-decimal-fractions-with-a-leading-zero
28+
29+
30+
# Load env file from $1 path
31+
source "$1"
32+
33+
# Just for debugging
34+
#set -ex
35+
36+
### FUNCTIONS ###
37+
38+
# Function to get the tx cost from the tx hash
39+
# @param tx_hash
40+
function fetch_tx_cost() {
41+
if [[ -z "$1" ]]; then
42+
echo 0
43+
else
44+
# Get the tx receipt from the blockchain
45+
receipt=$(cast receipt --rpc-url $RPC_URL $1)
46+
# Parse the gas used and gas price
47+
gas_price=$(echo "$receipt" | grep "effectiveGasPrice" | awk '{ print $2 }')
48+
gas_used=$(echo "$receipt" | grep "gasUsed" | awk '{ print $2 }')
49+
# Calculate fee in wei
50+
fee_in_wei=$(($gas_price * $gas_used))
51+
52+
echo $fee_in_wei
53+
fi
54+
}
55+
56+
# Function to send PagerDuty alert
57+
# @param message
58+
function send_pagerduty_alert() {
59+
. alerts/pagerduty.sh "$1"
60+
}
61+
62+
# Function so send Slack message
63+
# @param message
64+
function send_slack_message() {
65+
. alerts/slack.sh "$1"
66+
}
67+
68+
#################
69+
while true
70+
do
71+
72+
## Remove Proof Data
73+
rm -rf ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/*
74+
rm -rf ./aligned_verification_data/*
75+
76+
mkdir -p ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs
77+
78+
## Generate Proof
79+
nonce=$(aligned get-user-nonce --batcher_url $BATCHER_URL --user_addr $SENDER_ADDRESS 2>&1 | awk '{print $9}')
80+
x=$((nonce + 1)) # So we don't have any issues with nonce = 0
81+
echo "Generating proof $x != 0"
82+
go run ./scripts/test_files/gnark_groth16_bn254_infinite_script/cmd/main.go $x
83+
84+
## Send Proof
85+
echo "Submitting $REPETITIONS proofs $x != 0"
86+
submit=$(aligned submit \
87+
--proving_system Groth16Bn254 \
88+
--repetitions $REPETITIONS \
89+
--proof "./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_${x}_groth16.proof" \
90+
--public_input "./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_${x}_groth16.pub" \
91+
--vk "./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/ineq_${x}_groth16.vk" \
92+
--proof_generator_addr $SENDER_ADDRESS \
93+
--private_key $PRIVATE_KEY \
94+
--rpc_url $RPC_URL \
95+
--batcher_url $BATCHER_URL \
96+
--network $NETWORK \
97+
--max_fee 4000000000000000 \
98+
2>&1)
99+
100+
echo "$submit"
101+
102+
echo "Waiting $VERIFICATION_WAIT_TIME seconds for verification"
103+
sleep $VERIFICATION_WAIT_TIME
104+
105+
# Get all the batches merkle roots
106+
batch_merkle_roots=$(echo "$submit" | grep "Batch merkle root: " | grep -oE "0x[[:alnum:]]{64}" | uniq)
107+
108+
# Fetch the logs of both submission and response
109+
current_block_number=$(cast block-number --rpc-url $RPC_URL)
110+
from_block_number=$(($current_block_number - LOGS_BLOCK_RANGE))
111+
if [ $from_block_number -lt 0 ]; then
112+
from_block_number=0
113+
fi
114+
115+
total_fee_in_wei=0
116+
batch_explorer_urls=()
117+
for batch_merkle_root in $batch_merkle_roots
118+
do
119+
# Construct the batcher explorer url
120+
batch_explorer_url="$EXPLORER_URL/batches/$batch_merkle_root"
121+
batch_explorer_urls+=($batch_explorer_url)
122+
123+
log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'NewBatchV3 (bytes32 indexed batchMerkleRoot, address senderAddress, uint32 taskCreatedBlock, string batchDataPointer, uint256 respondToTaskFeeLimit)' $batch_merkle_root)
124+
submission_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }')
125+
126+
log=$(cast logs --rpc-url $RPC_URL --from-block $from_block_number --to-block latest 'BatchVerified (bytes32 indexed batchMerkleRoot, address senderAddress)' $batch_merkle_root)
127+
response_tx_hash=$(echo "$log" | grep -oE "transactionHash: 0x[[:alnum:]]{64}" | awk '{ print $2 }')
128+
129+
# Calculate fees for transactions
130+
submission_fee_in_wei=$(fetch_tx_cost $submission_tx_hash)
131+
response_fee_in_wei=$(fetch_tx_cost $response_tx_hash)
132+
batch_fee_in_wei=$((submission_fee_in_wei + response_fee_in_wei))
133+
134+
# Accumulate the fee
135+
total_fee_in_wei=$(($total_fee_in_wei + $batch_fee_in_wei))
136+
done
137+
138+
# Calculate the spent amount by converting the fee to ETH
139+
wei_to_eth_division_factor=$((10**18))
140+
spent_amount=$(echo "scale=30; $total_fee_in_wei / (10^18)" | bc -l | awk '{printf "%.15f", $0}')
141+
142+
eth_usd=$(curl -s https://cryptoprices.cc/ETH/)
143+
spent_amount_usd=$(echo "$spent_amount * $eth_usd" | bc | awk '{printf "%.2f", $1}')
144+
145+
slack_messsage=""
146+
verified=1
147+
148+
## Verify Proofs
149+
echo "Verifying $REPETITIONS proofs $x != 0"
150+
for proof in ./aligned_verification_data/*.cbor; do
151+
## Validate Proof on Chain
152+
verification=$(aligned verify-proof-onchain \
153+
--aligned-verification-data $proof \
154+
--rpc_url $RPC_URL \
155+
--network $NETWORK \
156+
2>&1)
157+
158+
## Send Alert if Verification Fails
159+
if echo "$verification" | grep -q not; then
160+
message="Proof verification failed for $proof [ ${batch_explorer_urls[@]} ]"
161+
echo "$message"
162+
send_pagerduty_alert "$message"
163+
verified=0 # Some proofs failed, so we should not send the success message
164+
break
165+
elif echo "$verification" | grep -q verified; then
166+
echo "Proof verification succeeded for $proof"
167+
fi
168+
done
169+
170+
if [ $verified -eq 1 ]; then
171+
slack_message="$REPETITIONS Proofs submitted and verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]"
172+
else
173+
slack_message="$REPETITIONS Proofs submitted but not verified. Spent amount: $spent_amount ETH ($ $spent_amount_usd) [ ${batch_explorer_urls[@]} ]"
174+
fi
175+
176+
## Send Update to Slack
177+
echo "$slack_message"
178+
send_slack_message "$slack_message"
179+
180+
## Remove Proof Data
181+
rm -rf ./scripts/test_files/gnark_groth16_bn254_infinite_script/infinite_proofs/*
182+
rm -rf ./aligned_verification_data/*
183+
184+
echo "Sleeping $SLEEP_TIME seconds"
185+
sleep $SLEEP_TIME
186+
done

alerts/slack.sh

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Function to send slack message
2+
# @param message
3+
curl -X POST -H 'Content-type: application/json' \
4+
--data "{\"text\":\"$1\"}" \
5+
$SLACK_WEBHOOK_URL
275 KB
Binary file not shown.
999 KB
Binary file not shown.

batcher/Cargo.lock

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

batcher/aligned/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "aligned"
3-
version = "0.12.1"
3+
version = "0.12.2"
44
edition = "2021"
55

66
[dependencies]

0 commit comments

Comments
 (0)