diff --git a/.env-example b/.env-example new file mode 100644 index 0000000..4832629 --- /dev/null +++ b/.env-example @@ -0,0 +1,3 @@ +# ethereum-mainnet-rpc.allthatnode.com +URL_ANKR_JSON_RPC_GOERLI=ethereum-goerli-rpc.allthatnode.com +PRIVATE_KEY_GOERLI= diff --git a/README.md b/README.md index 78e462e..6596309 100644 --- a/README.md +++ b/README.md @@ -18,20 +18,31 @@ gh repo create zkgraph-new --public --template="https://github.com/hyperoracle/z ### Configuration -After clone your project, you need to create `config.js` file at root folder based on `config-example.js` +After cloning your project, you need to create `config.js` file at root folder based on `config-example.js` + +Generate an environment file by running `cp .env-example .env`. + +If you wish to use ANKR to create JSON RPC requests to the Ethereum Goerli Testnet then go to https://www.ankr.com/rpc/ and click "Base Goerli Testnet" and then copy the "HTTPS Endpoint" value and paste it as the value of `URL_ANKR_JSON_RPC_GOERLI` in the .env file. + +Lastly paste the private key of an Ethereum address that has Goerli Testnet Eth as the value of `PRIVATE_KEY_GOERLI` in the .env file. To obtain Goerli Testnet Eth refer to [this article](https://www.coingecko.com/learn/goerli-eth). ```js // ./config.js export const config = { - // Update your Etherum JSON RPC provider URL here. + // Update your Ethereum JSON RPC provider URL here. // Please note that the provider must support debug_getRawReceipts RPC method. // Recommended provider: ANKR. - JsonRpcProviderUrl: "https://{URL}", - UserPrivateKey: "0x{PRIVATE_KEY}", + JsonRpcProviderUrl: "https://{URL_ANKR_JSON_RPC_GOERLI}", + UserPrivateKey: "0x{PRIVATE_KEY_GOERLI}", // ...and other configs. }; ``` +> To check if the provider supports the [`debug_getRawReceipts`](https://github.com/ethereum/go-ethereum/pull/24773) JSON RPC method, check if the following returns a response `{"jsonrpc":"2.0","id":42,"result":["...}`. In the example below the argument is the block hash (i.e. 0x3bb580f7645e2bdeb34b226f1b559d22a4a1ba5e2474504e294088389923ebd0) of a block number (i.e. 9438739) on the Goerli Testnet where the provider JSON RPC endpoint was obtained from https://www.allthatnode.com/ethereum.dsrv +```bash +curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"debug_getRawReceipts","params":["0x3bb580f7645e2bdeb34b226f1b559d22a4a1ba5e2474504e294088389923ebd0"],"id":42}' https://ethereum-goerli-rpc.allthatnode.com +``` + Then run: ```bash @@ -64,6 +75,10 @@ npm run compile-local npm run exec-local -- {block_id} ``` +Note: If using Ethereum Mainnet endpoint then its block 17633573 emits the event `Sync(uint112,uint112)` as specified in src/zkgraph.yaml so when you run `npm run exec-local -- 17633573` it outputs that 1 event matched. The same block number on another network like Goerli may not have emitted that event, so it may be necessary to find a block where it did (if at all) or deploy your own smart contract to a network that emits an event and then add that event to src/zkgraph.yaml with it configured to use that network. + +Note: If using Ethereum Goerli Testnet then replace the `block_id` above with a block from https://goerli.etherscan.io/blocks + ### Set Up Local Image ```bash diff --git a/api/compile.js b/api/compile.js index 096b1b7..70b175b 100644 --- a/api/compile.js +++ b/api/compile.js @@ -84,7 +84,7 @@ if (currentNpmScriptName() === "compile-local") { // Compile Locally localCompile(config.LocalWasmBinPath, watPath); } else if (currentNpmScriptName() === "compile") { - // Test Compile Erro with Local Compile + // Test Compile Error with Local Compile localCompile("build/tmp.wasm", "build/tmp.wat"); // Only Call Compile Server When No Local Compile Errors diff --git a/api/exec.js b/api/exec.js index 3863d94..801d0f8 100644 --- a/api/exec.js +++ b/api/exec.js @@ -44,6 +44,8 @@ const [filteredRawReceiptList, filteredEventList] = rlpDecodeAndEventFilter( fromHexString(source_address), source_esigs.map((esig) => fromHexString(esig)), ); +console.log('filteredRawReceiptList', filteredRawReceiptList) +console.log('filteredEventList', filteredEventList) // Gen Offsets let [rawReceipts, matchedEventOffsets] = genStreamAndMatchedEventOffsets( @@ -67,6 +69,7 @@ let wasmPath; let asmain_exported; if (currentNpmScriptName() === "exec-local") { + // e.g. build/zkgraph_local.wasm wasmPath = config.LocalWasmBinPath; const { asmain } = await instantiateWasm(wasmPath); asmain_exported = asmain; diff --git a/config-example.js b/config-example.js index c8971d3..c25ab9d 100644 --- a/config-example.js +++ b/config-example.js @@ -1,10 +1,12 @@ +import 'dotenv/config' + export const config = { - // Update your Etherum JSON RPC provider URL here. + // Update your Ethereum JSON RPC provider URL here. // Please note that the provider must support debug_getRawReceipts RPC method. - JsonRpcProviderUrl: "https://{URL}", - // Update your private key here to sign zkwasm messages. - // Please note that (during testnet phrase) your address balance (in zkwasm server) should > 0; - UserPrivateKey: "0x{PRIVATE_KEY}", + JsonRpcProviderUrl: `https://${process.env.URL_ANKR_JSON_RPC_GOERLI}`, + // Update your private key here to sign zkWasm messages. + // Please note that (during testnet phrase) your address balance (in zkWasm server) should > 0; + UserPrivateKey: `0x${process.env.PRIVATE_KEY_GOERLI}`, ZkwasmProviderUrl: "https://zkwasm-explorer.delphinuslab.com:8090", CompilerServerEndpoint: "https://compiler.hyperoracle.io/compile", diff --git a/lib/common/entries.ts b/lib/common/entries.ts index c2cc968..8d5beab 100644 --- a/lib/common/entries.ts +++ b/lib/common/entries.ts @@ -30,6 +30,6 @@ export function zkmain(): void { matched_event_offset.length / 7, matched_event_offset.dataStart, ) as Bytes; - + require(state == expected_state ? 1 : 0); } diff --git a/package-lock.json b/package-lock.json index 3129c50..0817da2 100644 --- a/package-lock.json +++ b/package-lock.json @@ -8,6 +8,7 @@ "dependencies": { "axios": "^1.4.0", "commander": "^11.0.0", + "dotenv": "^16.3.1", "ethers": "^5.7.2", "form-data": "^4.0.0", "js-yaml": "^4.1.0", @@ -797,6 +798,17 @@ "node": ">=0.4.0" } }, + "node_modules/dotenv": { + "version": "16.3.1", + "resolved": "https://registry.npmjs.org/dotenv/-/dotenv-16.3.1.tgz", + "integrity": "sha512-IPzF4w4/Rd94bA9imS68tZBaYyBWSCE47V1RGuMrB94iyTOIEwRmVL2x/4An+6mETpLrKJ5hQkB8W4kFAadeIQ==", + "engines": { + "node": ">=12" + }, + "funding": { + "url": "https://github.com/motdotla/dotenv?sponsor=1" + } + }, "node_modules/elliptic": { "version": "6.5.4", "license": "MIT", diff --git a/package.json b/package.json index 3181aff..3d87b12 100644 --- a/package.json +++ b/package.json @@ -19,6 +19,7 @@ "dependencies": { "axios": "^1.4.0", "commander": "^11.0.0", + "dotenv": "^16.3.1", "ethers": "^5.7.2", "form-data": "^4.0.0", "js-yaml": "^4.1.0",