ProvableHQ / sdk

A Software Development Kit (SDK) for Zero-Knowledge Transactions
https://provable.tools
GNU General Public License v3.0
584 stars 467 forks source link

[Bug] Block data parsing loses precision and typing of bigInts #892

Open WietzeSlagman opened 1 month ago

WietzeSlagman commented 1 month ago

🐛 Bug Report

Using response.json() as a parser for results fetched from Aleo nodes removes precision from bigInts and transforms them into strings (leading to users needing to handle casting and handling them correctly).

Steps to Reproduce

get a block containing a solution generated by a prover i.e block 4844 on testnet-beta, and check the values returned in the solutions part of the block, the result is that the counter element in the partial_solutions has lost the last 4 digits in precision and is now unexpectedly a string.

Code snippet to reproduce

import { AleoNetworkClient } from "sdk"
const networkClient = new AleoNetworkClient(ALEO_NODE_ENDPOINT)

const block = await networkClient.getBlock(4844)

Check the results of the blocks and verify wrong types: counter: "4175780142384957400" but it should be counter: 4175780142384957663 (as a bigInt)

Stack trace & error message

no error message to be shown

Expected Behavior

Expected behaviour is for the blocks to be returned with the right precision and having the correct typing such as bigInt allowing clients using the SDK.

Your Environment

WietzeSlagman commented 1 month ago

Proposed fix Use json-bigint to parse the response data instead of using response.json() in fetchData. No PR for this atm as I do not have the full understanding of the impact of this throughout the whole SDK, however it should address the data issue.

iamalwaysuncomfortable commented 1 month ago

@WietzeSlagman Thanks for noting this. Would you be interested in making the PR to fix it?

I'll ensure the SDK maintainers are aware of this.

WietzeSlagman commented 1 month ago

@WietzeSlagman Thanks for noting this. Would you be interested in making the PR to fix it?

I'll ensure the SDK maintainers are aware of this.

Yes i can make a PR with a fix for this, i'll have something ready within a day or 2

WietzeSlagman commented 1 month ago

PR opened: #901