1 << 32 to (1 << 32) - 1 to allow compiling on 32-bit targets#250
1 << 32 to (1 << 32) - 1 to allow compiling on 32-bit targets#250KaffinPX wants to merge 1 commit intoNeptune-Crypto:masterfrom
Conversation
|
I appreciate the intention. However, the suggested solution does not work with the current implementation of Merkle trees, as the number of leafs and the number of nodes must be a power of 2. |
|
It's interesting to see that no tests fail. That means there are tests missing. Elaborating a bit, in the current implementation, the number of leafs in a Merkle tree must be a power of two. To simplify the index arithmetic, the number of non-leaf nodes is equal to the number of leafs. As an artifact of this design choice, the node with index 0 is never used. In order to support Merkle trees with |
|
If the objective is to allow compiling to 32-bit targets, what options are there that do not involve changing indexation? |
Note that changing the internal indexing scheme does not imply a (big) change to the public API since the backing storage, i.e., the field Footnotes
|
|
In regards to
|
|
I won't shed tears if that method gets refactored into the dustbin. |
|
btw I know 32 bit is not widely used on practice anymore but compiling into WASM32 is still a practical application. |
|
Here's a limitation I hadn't been aware of so far: A correct first step is to relax the requirement of constant Footnotes |
This commit introduces type aliases:
- `MerkleTreeNodeIndex` for `u64`
- `MerkleTreeLeafIndex` for `u64`
- `MerkleTreeHeight` for `u32`.
It also refactors `MerkleTree` to avoid using `usize` where-ever
possible, particularly in public functions. Instead, these types
aliases are used.
`MerkleTree` internally stores a `Vec<Digest>`, which induces two
limitations:
1. The index type is `usize`, which complicates matters when
targeting compilation on 32-bit machines (including 32-bit WASM).
2. This vector can store at most 2^25 nodes, whereas we would like
functions associated with Merkle trees to work for Merkle trees
that are far larger (without needing to store all the internal
nodes explicitly).
The second limitation persists. However, the first limitation is fixed
by this commit.
Also, public functions `nodes()` and `leafs()` now return iterators
instead of slices. As these functions were public, this change is
breaking.
Addresses #250.
This commit introduces type aliases:
- `MerkleTreeNodeIndex` for `u64`
- `MerkleTreeLeafIndex` for `u64`
- `MerkleTreeHeight` for `u32`.
It also refactors `MerkleTree` to avoid using `usize` where-ever
possible, particularly in public functions. Instead, these types
aliases are used.
`MerkleTree` internally stores a `Vec<Digest>`, which induces two
limitations:
1. The index type is `usize`, which complicates matters when
targeting compilation on 32-bit machines (including 32-bit WASM).
2. This vector can store at most 2^25 nodes, whereas we would like
functions associated with Merkle trees to work for Merkle trees
that are far larger (without needing to store all the internal
nodes explicitly).
The second limitation persists. However, the first limitation is fixed
by this commit.
Also, public functions `nodes()` and `leafs()` now return iterators
instead of slices. As these functions were public, this change is
breaking.
Addresses #250.
|
@KaffinPX, what is the target triple you had in mind? For the record (and to help me remember), on this branch, both |
wasm32-unknown-unknown via wasm-bindgen. |
This PR introduces type aliases: - `MerkleTreeNodeIndex` for `usize` - `MerkleTreeLeafIndex` for `usize` - `MerkleTreeHeight` for `u32` with the objective of documenting the conventions for arithmetic with these index types. Also: - Public function `nodes()` dropped in favor of `node(i)`. - Public function `leafs()` now returns an iterator instead of a slice. - Private function `authentication_structure_node_indices` is marked `pub` as it is needed downstream. Displaces #250. --------- Co-authored-by: Jan Ferdinand Sauer <ferdinand@neptune.cash>
No description provided.