-
Notifications
You must be signed in to change notification settings - Fork 90
/
prove-block.sh
executable file
·162 lines (147 loc) · 4.27 KB
/
prove-block.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
#!/usr/bin/env bash
getBlockNumber() {
# Get the latest block number from the node
output=$(curl $rpc -s -X POST -H "Content-Type: application/json" --data '{"method":"eth_blockNumber","params":[],"id":1,"jsonrpc":"2.0"}')
# Extract the hexadecimal number using jq and remove the surrounding quotes
hex_number=$(echo $output | jq -r '.result')
# Convert the hexadecimal to decimal
block_number=$(echo $((${hex_number})))
# Return the block number by echoing it
echo "$block_number"
}
# Use the first command line argument as the chain name
chain="$1"
# Use the second command line argument as the proof type
proof="$2"
# Use the third(/fourth) parameter(s) as the block number as a range
# Use the special value "sync" as the third parameter to follow the tip of the chain
rangeStart="$3"
rangeEnd="$4"
# Use the fifth parameter as a custom proofParam
customParam="$5"
# Check the chain name and set the corresponding RPC values
if [ "$chain" == "ethereum" ]; then
l1_network="ethereum"
elif [ "$chain" == "holesky" ]; then
l1_network="holesky"
elif [ "$chain" == "taiko_mainnet" ]; then
l1_network="ethereum"
elif [ "$chain" == "taiko_a7" ]; then
l1_network="holesky"
elif [ "$chain" == "taiko_dev" ]; then
l1_network="taiko_dev_l1"
else
echo "Using customized chain name $1. Please double check the RPCs."
l1_network="holesky"
fi
if [ "$proof" == "native" ]; then
proofParam='
"proof_type": "native",
"native" : {
"json_guest_input": null
}
'
elif [ "$proof" == "sp1" ]; then
proofParam='
"proof_type": "sp1",
"blob_proof_type": "proof_of_equivalence",
"sp1": {
"recursion": "plonk",
"prover": "network",
"verify": true
}
'
elif [ "$proof" == "sp1-aggregation" ]; then
proofParam='
"proof_type": "sp1",
"blob_proof_type": "proof_of_equivalence",
"sp1": {
"recursion": "compressed",
"prover": "network",
"verify": false
}
'
elif [ "$proof" == "sgx" ]; then
proofParam='
"proof_type": "sgx",
"sgx" : {
"instance_id": 123,
"setup": false,
"bootstrap": false,
"prove": true,
"input_path": null
}
'
elif [ "$proof" == "risc0" ]; then
proofParam='
"proof_type": "risc0",
"blob_proof_type": "proof_of_equivalence",
"risc0": {
"bonsai": false,
"snark": false,
"profile": true,
"execution_po2": 18
}
'
elif [ "$proof" == "risc0-bonsai" ]; then
proofParam='
"proof_type": "risc0",
"blob_proof_type": "proof_of_equivalence",
"risc0": {
"bonsai": true,
"snark": true,
"profile": false,
"execution_po2": 20
}
'
else
echo "Invalid proof name. Please use 'native', 'risc0[-bonsai]', 'sp1', or 'sgx'."
exit 1
fi
# Ovwerride the proofParam if a custom one is provided
if [ -n "$5" ]; then
proofParam=$customParam
fi
if [ "$rangeStart" == "sync" ]; then
sync="true"
rangeStart=$(getBlockNumber)
rangeEnd=$((rangeStart + 1000000))
sleep 1.0
fi
if [ "$rangeStart" == "" ]; then
echo "Please specify a valid block range like \"10\" or \"10 20\""
exit 1
fi
if [ "$rangeEnd" == "" ]; then
rangeEnd=$rangeStart
fi
prover="0x70997970C51812dc3A010C7d01b50e0d17dc79C8"
graffiti="8008500000000000000000000000000000000000000000000000000000000000"
for block in $(eval echo {$rangeStart..$rangeEnd}); do
# Special sync logic to follow the tip of the chain
if [ "$sync" == "true" ]; then
block_number=$(getBlockNumber)
# While the current block is greater than the block number from the blockchain
while [ "$block" -gt "$block_number" ]; do
sleep 0.1 # Wait for 100ms
block_number=$(getBlockNumber) # Query again to get the updated block number
done
# Sleep a bit longer because sometimes the block data isn't available yet
sleep 1.0
fi
echo "- proving block $block"
curl --location --request POST 'http://localhost:8080/v2/proof' \
--header 'Content-Type: application/json' \
--header 'Authorization: Bearer 4cbd753fbcbc2639de804f8ce425016a50e0ecd53db00cb5397912e83f5e570e' \
--data-raw "{
\"network\": \"$chain\",
\"l1_network\": \"$l1_network\",
\"block_numbers\": [[$block, null], [$(($block+1)), null]],
\"block_number\": $block,
\"prover\": \"$prover\",
\"graffiti\": \"$graffiti\",
$proofParam
}"
echo ""
sleep 1.0
done