ora-io / zkgraph

Template for zkGraph.

Home Page:https://docs.hyperoracle.io/zkgraph

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Error: Abort execution

ltfschoen opened this issue · comments

Refer to this PR #56 where I tried to setup this repo by following the README file, but when I got up to the step of running npm run exec-local -- 9438792, it crashed with error

[-] zkwasm require condition is false
file:///Users/luke/code/github/ltfschoen/zkgraph/api/common/zkwasm_mock.js:79
      throw Error("Abort execution");
            ^

Error: Abort execution

which happens on this line https://github.com/hyperoracle/zkgraph/blob/master/api/exec.js#L81

Can you add the mapping.ts file in the issue?

It says [-] zkwasm require condition is false. So it means in this block (9438792), the given event will make the require statement inside mapping.ts to be false, then make execution abort.

i haven't modified the mapping.ts file since forking it from this repo, the changes are shown here https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/src/mapping.ts. the only changes i made are shown in this pull request #56
so the contents of it are:

//@ts-ignore
import { require } from "../lib/common/zkwasm";
import { Bytes, Event, BigInt } from "../lib/common/type";

export function handleEvents(events: Event[]): Bytes {
  let state = new Bytes(0);
  if (events.length > 0) {
    state = events[0].address;
  }
  require(state.length == 20);
  return state;
}

Got it. Thanks for sharing the code.

Is the error output like this?

> exec-local
> node api/exec.js 9438792

[*] Source contract address: 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
[*] Source events signatures: [
  '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1'
] 

[*] 174 receipts fetched from block 9438792
[*] 0 event matched
[-] zkwasm require condition is false
file:///Users/msfew/github/zkgraph/api/common/zkwasm_mock.js:79
      throw Error("Abort execution");

yes the output is:

> exec-local
> node api/exec.js 9438792

[*] Source contract address: 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
[*] Source events signatures: [
  '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1'
] 

filteredRawReceiptList []
filteredEventList []
[*] 85 receipts fetched from block 9438792
[*] 0 event matched
[-] zkwasm require condition is false
file:///Users/luke/code/github/ltfschoen/zkgraph/api/common/zkwasm_mock.js:79
      throw Error("Abort execution");
            ^

Error: Abort execution

In the output, it is shown that [*] 0 event matched. It means, in this block, the source event signature is not found. This is why zkwasm require condition is false.

You can fix this by:

  • Use another block number, for example the one in the test.sh (npm run exec-local -- 17633573).
  • Or, update the zkgraph.yaml file to search for other events emitted at 9438792th block.

Hope this helps.

so i'm using the code with my changes in this pull request #56

in that pull request i modified config.js to use a Goerli testnet JSON RPC endpoint https://ethereum-goerli-rpc.allthatnode.com and to use the private key of an Ethereum address that has 0.1 Goerli testnet eth tokens. i provided the them as environment variables from a .env file, and confirmed they were successfully being read by the config.ts file.

i also ran the following, which returned {"jsonrpc":"2.0","id":42,"result":["...}, where 0x3bb580f7645e2bdeb34b226f1b559d22a4a1ba5e2474504e294088389923ebd0 is the block hash associated with block number 9438739, which verified that the endpoint supported the debug_getRawReceipts method

curl -H "Content-Type: application/json" --data '{"jsonrpc":"2.0","method":"debug_getRawReceipts","params":["0x3bb580f7645e2bdeb34b226f1b559d22a4a1ba5e2474504e294088389923ebd0"],"id":42}' https://ethereum-goerli-rpc.allthatnode.com

then i ran the following commands by following the readme file, where i'm using Node.js v16.18.1

npm install
npm run compile-local

this was successful and generated the following files build/zkgraph_local.wasm and build/zkgraph_local.wat

but i just noticed that the contents of the default config.js file includes the following:

  WasmBinPath: "build/zkgraph_full.wasm",
  LocalWasmBinPath: "build/zkgraph_local.wasm",

Question: But when compiled it does NOT generate a build/zkgraph_full.wasm file, but i'm not sure if that file is necessary, how do I generate the build/zkgraph_full.wasm file?

also, are the following Hyper Oracle endpoints that are in the config.js file working?

  ZkwasmProviderUrl: "https://zkwasm-explorer.delphinuslab.com:8090",
  CompilerServerEndpoint: "https://compiler.hyperoracle.io/compile",

then i ran the following where i encountered the error.

npm run exec-local -- 9438792

which output

> exec-local
> node api/exec.js 9438792

[*] Source contract address: 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
[*] Source events signatures: [
  '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1'
] 

[*] 85 receipts fetched from block 9438792
[*] 0 event matched
rawReceipts:  Uint8Array(0) []
[-] zkwasm require condition is false
file:///Users/luke/code/github/ltfschoen/zkgraph/api/common/zkwasm_mock.js:79
      throw Error("Abort execution");
            ^

Error: Abort execution

i used debugging and found the error occurred when it reached this line of code https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/api/exec.js#L81

let state = asmain_exported(rawReceipts, matchedEventOffsets);

because asmain_exported is calling instantiateWasm and instantiate in ./api/common/bundle.js, which uses url to the compiled file build/zkgraph_local.wasm but gets caught in catch block here before showing the error and if i add console.log here https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/api/common/bundle.js#L17 in instantiate's require function, as shown below

      require(x) {
        console.log('x is: ', x);
        // sdk/zkwasm/require1(i32) => i64
        ZKWASMMock.require(x);
      },

it outputs x is: 0, because it calls ZKWASMMock.require(x); https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/api/common/bundle.js#L17, and that's what causes the error.

Question: But why is it calling require with a value of 0??

in the uniswap example in zkgraph/example/uniswapprice/mapping.ts they explicitely call require(false); so as to (according to the code comments) // Don't Trigger if there's no event in the block

it's actually not even running the mapping.ts file as i tried adding a console.log in it and it didn't get output when i ran npm run exec-local -- 9438792, so that's not the cause of the error.

and it's also not caused by zkgraph/lib/common/entries.ts where it has the code require(state == expected_state ? 1 : 0);, since that doesn't get run either.
but based on the variables in that file it seems like the purpose of the require function is simply to provide either 1 or 0 to communicate whether the state (generated from block header data) is the expected state or not...

i just had another look at it and found that the value of the variables were

  • matchedEventOffsets was Uint32Array(0) []
  • rawReceipts was Uint8Array(0) []
    even though earlier in that file we fetched 85 raw receipts into variable rawreceiptList from that provider for that specific block number
    and the reason for that is because when it does the RLP decode and filter step beforehand here https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/api/exec.js#L42, there aren't and raw receipts or events:
  • filteredRawReceiptList is []
  • filteredEventList is []

so there must be something wrong with the 2nd and 3rd argument that i'm providing to the function, and maybe that's why its not processing the events rlpDecodeAndEventFilter here https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/api/exec.js#L42, extract shown below

const [filteredRawReceiptList, filteredEventList] = rlpDecodeAndEventFilter(
  rawreceiptList,
  fromHexString(source_address),
  source_esigs.map((esig) => fromHexString(esig)),
);

it's getting those arguments earlier in exec.js file here https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/api/exec.js#L31, where it loads the source_address and source_esigs from the zkGraph config file src/zkgraph.yaml, where the source_address is the dataSources > source > address and the source_esigs is generated by taking the hash of each event listed under dataSources > mapping > eventHandlers.

the contents of the default src/zkgraph.yaml is shown here https://github.com/ltfschoen/zkgraph/blob/001774bd677e10629108b93c23fc65770bb817f4/src/zkgraph.yaml, extract below

specVersion: 0.0.2
description: Demo graph for zkAutomation.
repository: https://github.com/hyperoracle/zkgraph
dataSources:
  - kind: ethereum/contract
    network: mainnet
    source:
      address: '0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc'
    mapping:
      kind: ethereum/events
      apiVersion: 0.0.1
      language: wasm/assemblyscript
      file: ./mapping.ts
      eventHandlers:
        - event: Sync(uint112,uint112)
          handler: handleEvents
dataDestinations:
  - kind: ethereum/contract
    network: mainnet
    destination:
      address: '0x123abc'

where on Ethereum Mainnet the source address is https://etherscan.io/address/0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc#code, and corresponds to the UniswapV2Pair smart contract.
and that source address is also on Goerli Testnet here https://goerli.etherscan.io/token/0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc#code and also corresponds to the UniswapV2Pair smart contract.

But i'm using the Goerli Testnet provider, and I suspect there wouldn't be any events in the block on Goerli Testnet if nobody is using that contract.
Question: So is the idea that I need to create and deploy my own custom "source smart contract" on Goerli Testnet as shown in the Hyper Oracle documentation here https://docs.hyperoracle.io/zkgraph/introduction? And call functions in it to emit events in a specific block number, and then specify those events under dataSources > mapping > eventHandlers of src/zkgraph.yaml, and then later provide that block number as a CLI option when later run npm run exec-local -- <BLOCK_NUMBER>?

Question: What value should I change the "target blockchain network" network key to for dataSource and dataDestination if I want to use Goerli Testnet instead of Ethereum Mainnet? Should I just change it to a value of goerli

Question: What does apiVersion: 0.0.1 in src/zkgraph.yaml correspond to?

Question: What are the "target smart contract address" values listed in dataDestinations address used for (i.e. address: '0x123abc'), and are they necessary?

I thought the "source smart contract" that I deploy on the Goerli Testnet would be used to emit events in a specific block. Then when we run npm run exec-local -- <BLOCK_NUMBER> Hyper Oracle's zkPoS would retrieve data from the block header (including its state, tx, and receipts root), which we then recursively generate zk logic proofs from that we feed as inputs that serve as the initial state of each zkGraph, where each zkGraph is a Wasm-based data mapping that translates into AssemblyScript (so can be run in zkWasm runtime environment), which we defined in mapping.ts and that generate zk logic proofs

i just discovered https://docs.hyperoracle.io/mvp/testing-guide, so i'm going to see if that provides more insight

Question: But when compiled it does NOT generate a build/zkgraph_full.wasm file, but i'm not sure if that file is necessary, how do I generate the build/zkgraph_full.wasm file?

  • For generate zkgraph_full.wasm, you can run npm run compile which is without the -local at the end. The difference between local and full commands is that local only compiles local AssemblyScript code, while full compiles local code and also link-compiles some other C code.

Question: But why is it calling require with a value of 0??

  • This should be answered in my previous response. I'm not 100% sure, but it should be due to the fact that there's no matched event in this block num.

Question: So is the idea that I need to create and deploy my own custom "source smart contract" on Goerli Testnet as shown in the Hyper Oracle documentation here https://docs.hyperoracle.io/zkgraph/introduction? And call functions in it to emit events in a specific block number, and then specify those events under dataSources > mapping > eventHandlers of src/zkgraph.yaml, and then later provide that block number as a CLI option when later run npm run exec-local -- <BLOCK_NUMBER>?

  • You don't have to create or deploy your source smart contract. Any smart contracts on mainnet can be the source smart contract. And the rest of the workflow is correct.

Question: What value should I change the "target blockchain network" network key to for dataSource and dataDestination if I want to use Goerli Testnet instead of Ethereum Mainnet? Should I just change it to a value of goerli

  • Yes, goerli should be correct.

Question: What does apiVersion: 0.0.1 in src/zkgraph.yaml correspond to?

  • It is the version for library (the lib folder). We are still working on the version control and publishing flow of it. So you can ignore that at this stage.

Question: What are the "target smart contract address" values listed in dataDestinations address used for (i.e. address: '0x123abc'), and are they necessary?

  • It will be used in the future when developers want to trigger some onchain calls after their computation is done and the require statement they set is passed with true. This is very similar to automation networks like Gelato.

In the output, it is shown that [*] 0 event matched. It means, in this block, the source event signature is not found. This is why zkwasm require condition is false.

You can fix this by:

  • Use another block number, for example the one in the test.sh (npm run exec-local -- 17633573).
  • Or, update the zkgraph.yaml file to search for other events emitted at 9438792th block.

Hope this helps.

thanks, yes i got new endpoints from https://www.allthatnode.com/ethereum.dsrv and changed the endpoint from Goerli Testnet ethereum-goerli-rpc.allthatnode.com to Ethereum Mainnnet ethereum-mainnet-rpc.allthatnode.com, and then ran npm run exec-local -- 17633573 and it output the following, which says that 1 event matched and i believe that's referring to the event Sync(uint112,uint112) that is specified in zkgraph.yaml, which corresponds to the event deployed in the source address smart contract https://etherscan.io/address/0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc#code on line 358 event Sync(uint112 reserve0, uint112 reserve1); of the UniswapV2Pair smart contract

> exec-local
> node api/exec.js 17633573

[*] Source contract address: 0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc
[*] Source events signatures: [
  '0x1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1'
] 

filteredRawReceiptList [
  '0x02f905d4018315663bb9010010204000000000000000000080000000000000800000000000000000000000000000000000000000010000000000000002000000084000000000000000000000000000000000002008400008000000600000000000000000000000000000000000000102000000000000000000000040000000000000000000000010000000000000000010000000000000000000000001000000010000080000004000000000000000000000200200004004000000000000000000000000000002000000000000000002000000000000000002000000000000000000001000000000000000000008200000000000000000000000000000000000000000000000000000000000f904c9f89b94467bccd9d29f223bce8043b84e8c8b282827790ff863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000a8fed8c5aeb6bbcba263c8e2d8fb0e80c10c8485a0000000000000000000000000291c69fdaebd3cbe953843da243f8605a766a268a0000000000000000000000000000000000000000000000000000000000228589df89b94c02aaa39b223fe8d0a0e5c4f27ead9083c756cc2f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000291c69fdaebd3cbe953843da243f8605a766a268a0000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dca00000000000000000000000000000000000000000000000000386d3f2addbe935f87994291c69fdaebd3cbe953843da243f8605a766a268e1a01c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1b84000000000000000000000000000000000000000000000000000000000252f6878000000000000000000000000000000000000000000000000396d0f7e162fc160f8fc94291c69fdaebd3cbe953843da243f8605a766a268f863a0d78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822a0000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25effa0000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dcb880000000000000000000000000000000000000000000000000000000000228589d000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000386d3f2addbe935f89b94a0b86991c6218b36c1d19d4a2e9eb0ce3606eb48f863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000b4e16d0168e52d35cacd2c6185b44281ec28c9dca0000000000000000000000000a8fed8c5aeb6bbcba263c8e2d8fb0e80c10c8485a0000000000000000000000000000000000000000000000000000000001d151514f87994b4e16d0168e52d35cacd2c6185b44281ec28c9dce1a01c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1b84000000000000000000000000000000000000000000000000000001925d7b1b0d900000000000000000000000000000000000000000000030a5b512f61adb7dc37f8fc94b4e16d0168e52d35cacd2c6185b44281ec28c9dcf863a0d78ad95fa46c994b6551d0da85fc275fe613ce37657fb8d5e3d130840159d822a0000000000000000000000000def1c0ded9bec7f1a1670819833240f027b25effa0000000000000000000000000a8fed8c5aeb6bbcba263c8e2d8fb0e80c10c8485b88000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000386d3f2addbe935000000000000000000000000000000000000000000000000000000001d1515140000000000000000000000000000000000000000000000000000000000000000'
]
filteredEventList [
  [
    Event {
      address: [Uint8Array],
      topics: [Array],
      data: [Uint8Array],
      address_offset: [Array],
      topics_offset: [Array],
      data_offset: [Array]
    }
  ]
]
[*] 64 receipts fetched from block 17633573
[*] 1 event matched
	Tx[0]Event[0] |--addr : b4e16d0168e52d35cacd2c6185b44281ec28c9dc 
	Tx[0]Event[0] |--arg#0: 1c411e9a96e071241c2f21f7726b17ae89e3cab4c78be50e062b03a9fffbbad1 
	Tx[0]Event[0] |--data : 00000000000000000000000000000000000000000000000000001925d7b1b0d900000000000000000000000000000000000000000000030a5b512f61adb7dc37 

[+] ZKGRAPH STATE OUTPUT: b4e16d0168e52d35cacd2c6185b44281ec28c9dc