contracts fixed

This commit is contained in:
poma 2021-02-11 09:03:43 +03:00
parent 3c4def1e64
commit c6b442713a
No known key found for this signature in database
GPG key ID: BA20CB01FE165657
11 changed files with 220 additions and 71 deletions

View file

@ -1,6 +1,3 @@
// SPDX-License-Identifier: MIT
// SPDX-License-Identifier: MIT
// https://tornado.cash
/*
* d888888P dP a88888b. dP
@ -12,10 +9,11 @@
* ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo
*/
pragma solidity 0.6.12;
// SPDX-License-Identifier: MIT
pragma solidity ^0.6.0;
interface Hasher {
function MiMCSponge(uint256 in_xL, uint256 in_xR) public pure returns (uint256 xL, uint256 xR);
function MiMCSponge(uint256 in_xL, uint256 in_xR) external pure returns (uint256 xL, uint256 xR);
}
contract MerkleTreeWithHistory {
@ -46,25 +44,25 @@ contract MerkleTreeWithHistory {
filledSubtrees.push(currentZero);
for (uint32 i = 1; i < levels; i++) {
currentZero = hashLeftRight(currentZero, currentZero);
currentZero = hashLeftRight(_hasher, currentZero, currentZero);
zeros.push(currentZero);
filledSubtrees.push(currentZero);
}
roots[0] = hashLeftRight(currentZero, currentZero);
roots[0] = hashLeftRight(_hasher, currentZero, currentZero);
}
/**
@dev Hash 2 tree leaves, returns MiMC(_left, _right)
*/
function hashLeftRight(bytes32 _left, bytes32 _right) public pure returns (bytes32) {
function hashLeftRight(Hasher _hasher, bytes32 _left, bytes32 _right) public pure returns (bytes32) {
require(uint256(_left) < FIELD_SIZE, "_left should be inside the field");
require(uint256(_right) < FIELD_SIZE, "_right should be inside the field");
uint256 R = uint256(_left);
uint256 C = 0;
(R, C) = hasher.MiMCSponge(R, C);
(R, C) = _hasher.MiMCSponge(R, C);
R = addmod(R, uint256(_right), FIELD_SIZE);
(R, C) = hasher.MiMCSponge(R, C);
(R, C) = _hasher.MiMCSponge(R, C);
return bytes32(R);
}
@ -87,7 +85,7 @@ contract MerkleTreeWithHistory {
right = currentLevelHash;
}
currentLevelHash = hashLeftRight(left, right);
currentLevelHash = hashLeftRight(hasher, left, right);
currentIndex /= 2;
}