diff --git a/relay/abstraction/prover-interface.ts b/relay/abstraction/prover-interface.ts index f729bc840..216000c1b 100644 --- a/relay/abstraction/prover-interface.ts +++ b/relay/abstraction/prover-interface.ts @@ -1,5 +1,5 @@ import { Proof, ProofInputType } from '../types/types'; export interface IProver { - genProof(proofInput: ProofInputType): Promise; + genProof(proofInput: ProofInputType, mock: boolean): Promise; } diff --git a/relay/implementations/prover.ts b/relay/implementations/prover.ts index 2f0974c89..3cd90970c 100644 --- a/relay/implementations/prover.ts +++ b/relay/implementations/prover.ts @@ -10,35 +10,67 @@ export class Prover implements IProver { this.proverServerURL = proverServerURL; } - async genProof(proofInput: ProofInputType): Promise { - logger.info('Starting to generate proofs'); + async genProof(proofInput: ProofInputType, mock = false): Promise { + var proof; + var publicVars; + if (!mock) { + logger.info('Starting to generate proofs'); - let st = await this.getStatus(); + let st = await this.getStatus(); - if (st.status == 'busy') { - throw new Error('Proving server is not ready'); - } - - logger.info('Server is ready sending input'); + if (st.status == 'busy') { + throw new Error('Proving server is not ready'); + } - await this.callInput(proofInput.proofInput); + logger.info('Server is ready sending input'); - logger.info('Input send waiting for proof generation'); + await this.callInput(proofInput.proofInput); - st = await this.getStatus(); + logger.info('Input send waiting for proof generation'); - while (st.status == 'busy') { st = await this.getStatus(); - // to not overload server with requests - await new Promise(r => setTimeout(r, 2000)); - } + while (st.status == 'busy') { + st = await this.getStatus(); - logger.info('Proof successfully generated'); + // to not overload server with requests + await new Promise(r => setTimeout(r, 2000)); + } - const proof = JSON.parse(st.proof); + logger.info('Proof successfully generated'); - const publicVars = JSON.parse(st.pubData); + proof = JSON.parse(st.proof); + + publicVars = JSON.parse(st.pubData); + } else { + proof = { + pi_a: [ + '12763925006581137919304949334797603802458106302550743441499138660117674458843', + '3210277313367297960978284600070647965688928976864111405932126995759004567274', + '1', + ], + pi_b: [ + [ + '13262650684780645924631597816699461845882952491020847346256482683974830302382', + '18382552761441724027130145449451577465099488205434023208725500890682382654249', + ], + [ + '5742524743116358027698900120745802615824383991987775533210879169548095928215', + '9031854286059022594570625510067083999168656248388663258862090924521740417974', + ], + ['1', '0'], + ], + pi_c: [ + '13764977866279122478221420133386876215994100264892193449636036345427191382230', + '16905083775607366928536120749218882272365033612066779646866782727491849960912', + '1', + ], + }; + publicVars = [ + '9734125334797249825003723072622467244897033234414344070397312864656672300128', + '4', + ]; + } return { pi_a: proof.pi_a, diff --git a/relay/run-relay.sh b/relay/run-relay.sh index 96fb8e8cb..1545d41c2 100755 --- a/relay/run-relay.sh +++ b/relay/run-relay.sh @@ -25,45 +25,50 @@ download_zkey_file() { fi } -download_dat_file() { - echo "Downloading .dat file from https://media.githubusercontent.com/media/metacraft-labs/DendrETH-build-artifacts/master/light_client_cpp/light_client.dat ..." +if [ $MOCK == FALSE ]; then + download_dat_file() { + echo "Downloading .dat file from https://media.githubusercontent.com/media/metacraft-labs/DendrETH-build-artifacts/master/light_client_cpp/light_client.dat ..." - curl -k https://media.githubusercontent.com/media/metacraft-labs/DendrETH-build-artifacts/master/light_client_cpp/light_client.dat > "data/light_client.dat" + curl -k https://media.githubusercontent.com/media/metacraft-labs/DendrETH-build-artifacts/master/light_client_cpp/light_client.dat > "data/light_client.dat" - CALCULATED_DAT_SUM=$(calculate_checksum data/light_client.dat) + CALCULATED_DAT_SUM=$(calculate_checksum data/light_client.dat) - if [ "$DAT_B3SUM_SUM" = "$CALCULATED_DAT_SUM" ]; then - echo ".dat file downloaded successfully to data/light_client.dat" + if [ "$DAT_B3SUM_SUM" = "$CALCULATED_DAT_SUM" ]; then + echo ".dat file downloaded successfully to data/light_client.dat" + else + echo "Failed to download .dat file from https://media.githubusercontent.com/media/metacraft-labs/DendrETH-build-artifacts/master/light_client_cpp/light_client.dat" + exit 1 + fi + } + + if [ ! -f "data/light_client.zkey" ]; then + download_zkey_file else - echo "Failed to download .dat file from https://media.githubusercontent.com/media/metacraft-labs/DendrETH-build-artifacts/master/light_client_cpp/light_client.dat" - exit 1 + CALCULATED_ZKEY_SUM=$(calculate_checksum data/light_client.zkey) + echo $CALCULATED_ZKEY_SUM + if [ "$ZKEY_B3SUM_SUM" = "$CALCULATED_ZKEY_SUM" ]; then + echo "Using cached zkey file at data/light_client.zkey" + else + echo "Wrong version of light_client.zkey cached downloading again..." + download_zkey_file + fi fi -} -if [ ! -f "data/light_client.zkey" ]; then - download_zkey_file -else - CALCULATED_ZKEY_SUM=$(calculate_checksum data/light_client.zkey) - echo $CALCULATED_ZKEY_SUM - if [ "$ZKEY_B3SUM_SUM" = "$CALCULATED_ZKEY_SUM" ]; then - echo "Using cached zkey file at data/light_client.zkey" + if [ ! -f "data/light_client.dat" ]; then + download_dat_file else - echo "Wrong version of light_client.zkey cached downloading again..." - download_zkey_file + CALCULATED_DAT_SUM=$(calculate_checksum data/light_client.dat) + echo $CALCULATED_DAT_SUM + if [ "$DAT_B3SUM_SUM" = "$CALCULATED_DAT_SUM" ]; then + echo "Using cached .dat file at data/light_client.dat" + else + echo "Wrong version of light_client.dat cached downloading again..." + download_dat_file + fi fi -fi -if [ ! -f "data/light_client.dat" ]; then - download_dat_file else - CALCULATED_DAT_SUM=$(calculate_checksum data/light_client.dat) - echo $CALCULATED_DAT_SUM - if [ "$DAT_B3SUM_SUM" = "$CALCULATED_DAT_SUM" ]; then - echo "Using cached .dat file at data/light_client.dat" - else - echo "Wrong version of light_client.dat cached downloading again..." - download_dat_file - fi + echo "Mock mode, not downloading .zkey and .dat files" fi # rapidnskark prover server searches for the witness generator exe in build directory @@ -71,13 +76,13 @@ mkdir -p build cp relay/light_client build/light_client cp data/light_client.dat light_client.dat -if [[ -z "$REDIS_HOST" ]] && [[ -z "$REDIS_PORT" ]]; then - echo "REDIS_HOST and REDIS_PORT environment variables are not set. Using default values." - REDIS_HOST="localhost" - REDIS_PORT="6379" -else - echo "Using Redis settings from environment variables" -fi +# if [[ -z "$REDIS_HOST" ]] && [[ -z "$REDIS_PORT" ]]; then +echo "REDIS_HOST and REDIS_PORT environment variables are not set. Using default values." +REDIS_HOST="localhost" +REDIS_PORT="6379" +# else + # echo "Using Redis settings from environment variables" +# fi if [[ -z "$PROVER_SERVER_HOST" ]] && [[ -z "$PROVER_SERVER_PORT" ]]; then @@ -90,37 +95,42 @@ fi -if [[ "$PROVER_SERVER_HOST" == "http://127.0.0.1" ]]; then - echo "Starting local prover server..." - process-compose process start proverserver - echo "Prover server started with command" +if [[ $MOCK == FALSE ]]; then + if [[ "$PROVER_SERVER_HOST" == "http://127.0.0.1" ]]; then + echo "Starting local prover server..." + process-compose process start proverserver + echo "Prover server started with command" - max_attempts=300 # 300 attempts * 2s delay = 10 minutes - server_started=false + max_attempts=300 # 300 attempts * 2s delay = 10 minutes + server_started=false - echo "Waiting for server to start..." + echo "Waiting for server to start..." - for ((i=1; i<=$max_attempts; i++)); do - response=$(curl -s -o /dev/null -w "%{http_code}" "$PROVER_SERVER_HOST":"$PROVER_SERVER_PORT"/status) + for ((i=1; i<=$max_attempts; i++)); do + response=$(curl -s -o /dev/null -w "%{http_code}" "$PROVER_SERVER_HOST":"$PROVER_SERVER_PORT"/status) - if [ $response -eq 200 ]; then - echo "Server is up and running." - server_started=true - break - fi + if [ $response -eq 200 ]; then + echo "Server is up and running." + server_started=true + break + fi - echo "Attempt $i: Server is not responding. Waiting for 2 seconds..." - sleep 2 - done + echo "Attempt $i: Server is not responding. Waiting for 2 seconds..." + sleep 2 + done - if [ $server_started == false ]; then - echo "Server failed to start after 5 minutes. Exiting." - exit 1 + if [ $server_started == false ]; then + echo "Server failed to start after 5 minutes. Exiting." + exit 1 + fi + else + echo "Using remote prover server at $PROVER_SERVER_HOST:$PROVER_SERVER_PORT" fi else - echo "Using remote prover server at $PROVER_SERVER_HOST:$PROVER_SERVER_PORT" + echo "Mock mode, not starting local prover server" fi +# if [[ $MOCK == FALSE ]]; then if [[ "$REDIS_HOST" == "localhost" ]] && [[ "$REDIS_PORT" == "6379" ]]; then echo "Starting local Redis server..." process-compose process start redis @@ -162,105 +172,107 @@ run_network_tasks() { else echo "Skipping Goerli network" fi + if [[ $MOCK == FALSE ]]; then + if [ -n "$LC_OPTIMISTIC_GOERLI" ]; then + echo "Starting light client for Optimistic Goerli network" + process-compose process start goeoptimisticGoerlirli + else + echo "Skipping Optimistic Goerli network" + fi - if [ -n "$LC_OPTIMISTIC_GOERLI" ]; then - echo "Starting light client for Optimistic Goerli network" - process-compose process start goeoptimisticGoerlirli - else - echo "Skipping Optimistic Goerli network" - fi - - if [ -n "$LC_BASE_GOERLI" ]; then - echo "Starting light client for Base Goerli network" - process-compose process start baseGoerli - else - echo "Skipping Base Goerli network" - fi + if [ -n "$LC_BASE_GOERLI" ]; then + echo "Starting light client for Base Goerli network" + process-compose process start baseGoerli + else + echo "Skipping Base Goerli network" + fi - if [ -n "$LC_ARBITRUM_GOERLI" ]; then - echo "Starting light client for Arbitrum Goerli network" - process-compose process start arbitrumGoerli - else - echo "Skipping Arbitrum Goerli network" - fi + if [ -n "$LC_ARBITRUM_GOERLI" ]; then + echo "Starting light client for Arbitrum Goerli network" + process-compose process start arbitrumGoerli + else + echo "Skipping Arbitrum Goerli network" + fi - if [ -n "$LC_SEPOLIA" ]; then - echo "Starting light client for Sepolia network" - process-compose process start sepolia - else - echo "Skipping Sepolia network" - fi + if [ -n "$LC_SEPOLIA" ]; then + echo "Starting light client for Sepolia network" + process-compose process start sepolia + else + echo "Skipping Sepolia network" + fi - if [ -n "$LC_MUMBAI" ]; then - echo "Starting light client for Mumbai network" - process-compose process start mumbai - else - echo "Skipping Mumbai network" - fi + if [ -n "$LC_MUMBAI" ]; then + echo "Starting light client for Mumbai network" + process-compose process start mumbai + else + echo "Skipping Mumbai network" + fi - if [ -n "$LC_FUJI" ]; then - echo "Starting light client for Fuji network" - process-compose process start fuji - else - echo "Skipping Fuji network" - fi + if [ -n "$LC_FUJI" ]; then + echo "Starting light client for Fuji network" + process-compose process start fuji + else + echo "Skipping Fuji network" + fi - if [ -n "$LC_FANTOM" ]; then - echo "Starting light client for Fantom network" - process-compose process start fantom - else - echo "Skipping Fantom network" - fi + if [ -n "$LC_FANTOM" ]; then + echo "Starting light client for Fantom network" + process-compose process start fantom + else + echo "Skipping Fantom network" + fi - if [ -n "$LC_ALFAJORES" ]; then - echo "Starting light client for Alfajores network" - process-compose process start alfajores - else - echo "Skipping Alfajores network" - fi + if [ -n "$LC_ALFAJORES" ]; then + echo "Starting light client for Alfajores network" + process-compose process start alfajores + else + echo "Skipping Alfajores network" + fi - if [ -n "$LC_BSC" ]; then - echo "Starting light client for BSC network" - process-compose process start bsc - else - echo "Skipping BSC network" - fi + if [ -n "$LC_BSC" ]; then + echo "Starting light client for BSC network" + process-compose process start bsc + else + echo "Skipping BSC network" + fi - if [ -n "$LC_AURORA" ]; then - echo "Starting light client for Aurora network" - process-compose process start aurora - else - echo "Skipping Aurora network" - fi + if [ -n "$LC_AURORA" ]; then + echo "Starting light client for Aurora network" + process-compose process start aurora + else + echo "Skipping Aurora network" + fi - if [ -n "$LC_GNOSIS" ]; then - echo "Starting light client for Gnosis network" - process-compose process start gnosis - else - echo "Skipping Gnosis network" - fi + if [ -n "$LC_GNOSIS" ]; then + echo "Starting light client for Gnosis network" + process-compose process start gnosis + else + echo "Skipping Gnosis network" + fi - if [ -n "$LC_CHIADO" ]; then - echo "Starting light client for Chiado network" - process-compose process start chiado - else - echo "Skipping Chiado network" - fi + if [ -n "$LC_CHIADO" ]; then + echo "Starting light client for Chiado network" + process-compose process start chiado + else + echo "Skipping Chiado network" + fi - if [ -n "$LC_EVMOS" ]; then - echo "Starting light client for EVMOS network" - process-compose process start evmos - else - echo "Skipping EVMOS network" - fi + if [ -n "$LC_EVMOS" ]; then + echo "Starting light client for EVMOS network" + process-compose process start evmos + else + echo "Skipping EVMOS network" + fi - if [ -n "$LC_MALAGA" ]; then - echo "Starting light client for Malaga network" - process-compose process start malaga + if [ -n "$LC_MALAGA" ]; then + echo "Starting light client for Malaga network" + process-compose process start malaga + else + echo "Skipping Malaga network" + fi else - echo "Skipping Malaga network" + echo "Mock mode, skipped all but 1 network tasks" fi - echo "Everything started for $FOLLOW_NETWORK" } diff --git a/relay/workers/prover/gen_proof.ts b/relay/workers/prover/gen_proof.ts index a08e6a8b8..e2861ae6e 100644 --- a/relay/workers/prover/gen_proof.ts +++ b/relay/workers/prover/gen_proof.ts @@ -17,7 +17,9 @@ export default async function genProof( return; } - const proof = await prover.genProof(proofInput); + let mock = Boolean(process.env.MOCK); + + const proof = await prover.genProof(proofInput, mock); await redis.saveProof(proofInput.prevUpdateSlot, proofInput.updateSlot, { ...proofInput,