style: format code

This commit is contained in:
cedoor
2022-07-21 11:22:14 +02:00
parent f6eaa90002
commit cb3a73f8a0
4 changed files with 24 additions and 10 deletions

View File

@@ -39,6 +39,7 @@ library IncrementalBinaryTree {
for (uint8 i = 0; i < depth; ) {
self.zeroes[i] = zero;
zero = PoseidonT3.poseidon([zero, zero]);
unchecked {
++i;
}
@@ -51,8 +52,9 @@ library IncrementalBinaryTree {
/// @param self: Tree data.
/// @param leaf: Leaf to be inserted.
function insert(IncrementalTreeData storage self, uint256 leaf) public {
require(leaf < SNARK_SCALAR_FIELD, "IncrementalBinaryTree: leaf must be < SNARK_SCALAR_FIELD");
uint256 depth = self.depth;
require(leaf < SNARK_SCALAR_FIELD, "IncrementalBinaryTree: leaf must be < SNARK_SCALAR_FIELD");
require(self.numberOfLeaves < 2**depth, "IncrementalBinaryTree: tree is full");
uint256 index = self.numberOfLeaves;
@@ -67,6 +69,7 @@ library IncrementalBinaryTree {
hash = PoseidonT3.poseidon(self.lastSubtrees[i]);
index >>= 1;
unchecked {
++i;
}
@@ -94,9 +97,9 @@ library IncrementalBinaryTree {
"IncrementalBinaryTree: leaf is not part of the tree"
);
uint256 depth = self.depth;
uint256 hash = newLeaf;
uint256 depth = self.depth;
for (uint8 i = 0; i < depth; ) {
if (proofPathIndices[i] == 0) {
if (proofSiblings[i] == self.lastSubtrees[i][1]) {
@@ -111,6 +114,7 @@ library IncrementalBinaryTree {
hash = PoseidonT3.poseidon([proofSiblings[i], hash]);
}
unchecked {
++i;
}
@@ -135,9 +139,9 @@ library IncrementalBinaryTree {
"IncrementalBinaryTree: leaf is not part of the tree"
);
uint256 depth = self.depth;
uint256 hash = self.zeroes[0];
uint256 depth = self.depth;
for (uint8 i = 0; i < depth; ) {
if (proofPathIndices[i] == 0) {
if (proofSiblings[i] == self.lastSubtrees[i][1]) {
@@ -152,6 +156,7 @@ library IncrementalBinaryTree {
hash = PoseidonT3.poseidon([proofSiblings[i], hash]);
}
unchecked {
++i;
}
@@ -192,6 +197,7 @@ library IncrementalBinaryTree {
} else {
hash = PoseidonT3.poseidon([proofSiblings[i], hash]);
}
unchecked {
++i;
}

View File

@@ -35,6 +35,7 @@ library IncrementalQuinTree {
require(depth > 0 && depth <= MAX_DEPTH, "IncrementalQuinTree: tree depth must be between 1 and 32");
self.depth = depth;
for (uint8 i = 0; i < depth; ) {
self.zeroes[i] = zero;
uint256[5] memory zeroChildren;
@@ -47,6 +48,7 @@ library IncrementalQuinTree {
}
zero = PoseidonT6.poseidon(zeroChildren);
unchecked {
++i;
}
@@ -59,8 +61,9 @@ library IncrementalQuinTree {
/// @param self: Tree data.
/// @param leaf: Leaf to be inserted.
function insert(IncrementalTreeData storage self, uint256 leaf) public {
require(leaf < SNARK_SCALAR_FIELD, "IncrementalQuinTree: leaf must be < SNARK_SCALAR_FIELD");
uint256 depth = self.depth;
require(leaf < SNARK_SCALAR_FIELD, "IncrementalQuinTree: leaf must be < SNARK_SCALAR_FIELD");
require(self.numberOfLeaves < 5**depth, "IncrementalQuinTree: tree is full");
uint256 index = self.numberOfLeaves;
@@ -82,6 +85,7 @@ library IncrementalQuinTree {
hash = PoseidonT6.poseidon(self.lastSubtrees[i]);
index /= 5;
unchecked {
++i;
}
@@ -109,9 +113,9 @@ library IncrementalQuinTree {
"IncrementalQuinTree: leaf is not part of the tree"
);
uint256 depth = self.depth;
uint256 hash = newLeaf;
uint256 depth = self.depth;
for (uint8 i = 0; i < depth; ) {
uint256[5] memory nodes;
@@ -133,6 +137,7 @@ library IncrementalQuinTree {
}
hash = PoseidonT6.poseidon(nodes);
unchecked {
++i;
}
@@ -157,9 +162,9 @@ library IncrementalQuinTree {
"IncrementalQuinTree: leaf is not part of the tree"
);
uint256 depth = self.depth;
uint256 hash = self.zeroes[0];
uint256 depth = self.depth;
for (uint8 i = 0; i < depth; ) {
uint256[5] memory nodes;
@@ -181,6 +186,7 @@ library IncrementalQuinTree {
}
hash = PoseidonT6.poseidon(nodes);
unchecked {
++i;
}
@@ -231,12 +237,14 @@ library IncrementalQuinTree {
nodes[j] = proofSiblings[i][j - 1];
}
unchecked {
++j;
}
}
hash = PoseidonT6.poseidon(nodes);
unchecked {
++i;
}

View File

@@ -7,14 +7,14 @@ import "../IncrementalBinaryTree.sol";
contract IncrementalBinaryTreeTest {
using IncrementalBinaryTree for IncrementalTreeData;
event TreeCreated(bytes32 id, uint8 depth);
event TreeCreated(bytes32 id, uint256 depth);
event LeafInserted(bytes32 indexed treeId, uint256 leaf, uint256 root);
event LeafUpdated(bytes32 indexed treeId, uint256 leaf, uint256 root);
event LeafRemoved(bytes32 indexed treeId, uint256 leaf, uint256 root);
mapping(bytes32 => IncrementalTreeData) public trees;
function createTree(bytes32 _id, uint8 _depth) external {
function createTree(bytes32 _id, uint256 _depth) external {
require(trees[_id].depth == 0, "IncrementalBinaryTreeTest: tree already exists");
trees[_id].init(_depth, 0);

View File

@@ -7,14 +7,14 @@ import "../IncrementalQuinTree.sol";
contract IncrementalQuinTreeTest {
using IncrementalQuinTree for IncrementalTreeData;
event TreeCreated(bytes32 id, uint8 depth);
event TreeCreated(bytes32 id, uint256 depth);
event LeafInserted(bytes32 indexed treeId, uint256 leaf, uint256 root);
event LeafUpdated(bytes32 indexed treeId, uint256 leaf, uint256 root);
event LeafRemoved(bytes32 indexed treeId, uint256 leaf, uint256 root);
mapping(bytes32 => IncrementalTreeData) public trees;
function createTree(bytes32 _id, uint8 _depth) external {
function createTree(bytes32 _id, uint256 _depth) external {
require(trees[_id].depth == 0, "IncrementalQuinTreeTest: tree already exists");
trees[_id].init(_depth, 0);