Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Support Solidity endianess with fdp-contracts #10

Open
molekilla opened this issue May 23, 2022 · 0 comments
Open

feat: Support Solidity endianess with fdp-contracts #10

molekilla opened this issue May 23, 2022 · 0 comments

Comments

@molekilla
Copy link

In BMTFile.sol, in the unit tests we add an additional property to ChunkInclusionProof named spanValue, that is the value return by getSpanValue, which is a little endian uint32 value.

The unit test fills this value using BN.js which has support for endianess.

      // TODO: Move this logic to bmt.js
      const proofChunksBigNumber = proofChunks.map((i: { span: Uint8Array; sisterSegments: Uint8Array[] }) => {
        return {
          // eslint-disable-next-line node/no-unsupported-features/es-syntax
          ...i,
          // Note: It has to be exactly little endian with length of 8 bytes
          spanValue: new BN(i.span).toBuffer('le', 8),
        }
      })

The struct in Solidity is:

  struct ChunkInclusionProof{
    // big endian value
    uint64 span;
    // little endian value
    uint64 spanValue;
    bytes32[] sisterSegments;
  }

Ideally, bmt.js must implement spanValue and use BN.js to calculate the endianess, thus the unit test implementation can be removed, making for an easier fdp-contracts API to use for developers.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant