mirror of
https://github.com/tornadocash/tornado-core.git
synced 2025-05-08 17:25:04 -04:00
contracts fixed
This commit is contained in:
parent
3c4def1e64
commit
c6b442713a
11 changed files with 220 additions and 71 deletions
|
@ -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;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue