mirror of
https://github.com/tornadocash/tornado-nova
synced 2024-02-02 14:53:56 +01:00
refactor: functions order
This commit is contained in:
parent
0ecd02620d
commit
ebf1b1a1b4
@ -98,10 +98,6 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver, ReentrancyGuard,
|
|||||||
super._initialize();
|
super._initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
function configureLimits(uint256 _minimalWithdrawalAmount, uint256 _maximumDepositAmount) public onlyGovernance {
|
|
||||||
_configureLimits(_minimalWithdrawalAmount, _maximumDepositAmount);
|
|
||||||
}
|
|
||||||
|
|
||||||
function transact(Proof memory _args, ExtData memory _extData) public {
|
function transact(Proof memory _args, ExtData memory _extData) public {
|
||||||
if (_extData.extAmount > 0) {
|
if (_extData.extAmount > 0) {
|
||||||
// for deposits from L2
|
// for deposits from L2
|
||||||
@ -112,39 +108,36 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver, ReentrancyGuard,
|
|||||||
_transact(_args, _extData);
|
_transact(_args, _extData);
|
||||||
}
|
}
|
||||||
|
|
||||||
function _transact(Proof memory _args, ExtData memory _extData) internal nonReentrant {
|
function register(Account memory _account) public {
|
||||||
require(isKnownRoot(_args.root), "Invalid merkle root");
|
require(_account.owner == msg.sender, "only owner can be registered");
|
||||||
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
|
_register(_account);
|
||||||
require(!isSpent(_args.inputNullifiers[i]), "Input is already spent");
|
|
||||||
}
|
|
||||||
require(uint256(_args.extDataHash) == uint256(keccak256(abi.encode(_extData))) % FIELD_SIZE, "Incorrect external data hash");
|
|
||||||
require(_args.publicAmount == calculatePublicAmount(_extData.extAmount, _extData.fee), "Invalid public amount");
|
|
||||||
require(verifyProof(_args), "Invalid transaction proof");
|
|
||||||
|
|
||||||
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
|
|
||||||
nullifierHashes[_args.inputNullifiers[i]] = true;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (_extData.extAmount < 0) {
|
function registerAndTransact(
|
||||||
require(_extData.recipient != address(0), "Can't withdraw to zero address");
|
Account memory _account,
|
||||||
if (_extData.isL1Withdrawal) {
|
Proof memory _proofArgs,
|
||||||
token.transferAndCall(omniBridge, uint256(-_extData.extAmount), abi.encodePacked(l1Unwrapper, _extData.recipient));
|
ExtData memory _extData
|
||||||
} else {
|
) public {
|
||||||
token.transfer(_extData.recipient, uint256(-_extData.extAmount));
|
register(_account);
|
||||||
}
|
transact(_proofArgs, _extData);
|
||||||
require(uint256(-_extData.extAmount) >= minimalWithdrawalAmount, "amount is less than minimalWithdrawalAmount"); // prevents ddos attack to Bridge
|
|
||||||
}
|
|
||||||
if (_extData.fee > 0) {
|
|
||||||
token.transfer(_extData.relayer, _extData.fee);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastBalance = token.balanceOf(address(this));
|
function onTokenBridged(
|
||||||
_insert(_args.outputCommitments[0], _args.outputCommitments[1]);
|
IERC6777 _token,
|
||||||
emit NewCommitment(_args.outputCommitments[0], nextIndex - 2, _extData.encryptedOutput1);
|
uint256 _amount,
|
||||||
emit NewCommitment(_args.outputCommitments[1], nextIndex - 1, _extData.encryptedOutput2);
|
bytes calldata _data
|
||||||
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
|
) external override {
|
||||||
emit NewNullifier(_args.inputNullifiers[i]);
|
(Proof memory _args, ExtData memory _extData) = abi.decode(_data, (Proof, ExtData));
|
||||||
|
require(_token == token, "provided token is not supported");
|
||||||
|
require(msg.sender == omniBridge, "only omni bridge");
|
||||||
|
require(_amount >= uint256(_extData.extAmount), "amount from bridge is incorrect");
|
||||||
|
require(token.balanceOf(address(this)) >= uint256(_extData.extAmount) + lastBalance, "bridge did not send enough tokens");
|
||||||
|
require(uint256(_extData.extAmount) <= maximumDepositAmount, "amount is larger than maximumDepositAmount");
|
||||||
|
_transact(_args, _extData);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function configureLimits(uint256 _minimalWithdrawalAmount, uint256 _maximumDepositAmount) public onlyGovernance {
|
||||||
|
_configureLimits(_minimalWithdrawalAmount, _maximumDepositAmount);
|
||||||
}
|
}
|
||||||
|
|
||||||
function calculatePublicAmount(int256 _extAmount, uint256 _fee) public pure returns (uint256) {
|
function calculatePublicAmount(int256 _extAmount, uint256 _fee) public pure returns (uint256) {
|
||||||
@ -207,36 +200,43 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver, ReentrancyGuard,
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function register(Account memory _account) public {
|
|
||||||
require(_account.owner == msg.sender, "only owner can be registered");
|
|
||||||
_register(_account);
|
|
||||||
}
|
|
||||||
|
|
||||||
function _register(Account memory _account) internal {
|
function _register(Account memory _account) internal {
|
||||||
emit PublicKey(_account.owner, _account.publicKey);
|
emit PublicKey(_account.owner, _account.publicKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerAndTransact(
|
function _transact(Proof memory _args, ExtData memory _extData) internal nonReentrant {
|
||||||
Account memory _account,
|
require(isKnownRoot(_args.root), "Invalid merkle root");
|
||||||
Proof memory _proofArgs,
|
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
|
||||||
ExtData memory _extData
|
require(!isSpent(_args.inputNullifiers[i]), "Input is already spent");
|
||||||
) public {
|
}
|
||||||
register(_account);
|
require(uint256(_args.extDataHash) == uint256(keccak256(abi.encode(_extData))) % FIELD_SIZE, "Incorrect external data hash");
|
||||||
transact(_proofArgs, _extData);
|
require(_args.publicAmount == calculatePublicAmount(_extData.extAmount, _extData.fee), "Invalid public amount");
|
||||||
|
require(verifyProof(_args), "Invalid transaction proof");
|
||||||
|
|
||||||
|
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
|
||||||
|
nullifierHashes[_args.inputNullifiers[i]] = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function onTokenBridged(
|
if (_extData.extAmount < 0) {
|
||||||
IERC6777 _token,
|
require(_extData.recipient != address(0), "Can't withdraw to zero address");
|
||||||
uint256 _amount,
|
if (_extData.isL1Withdrawal) {
|
||||||
bytes calldata _data
|
token.transferAndCall(omniBridge, uint256(-_extData.extAmount), abi.encodePacked(l1Unwrapper, _extData.recipient));
|
||||||
) external override {
|
} else {
|
||||||
(Proof memory _args, ExtData memory _extData) = abi.decode(_data, (Proof, ExtData));
|
token.transfer(_extData.recipient, uint256(-_extData.extAmount));
|
||||||
require(_token == token, "provided token is not supported");
|
}
|
||||||
require(msg.sender == omniBridge, "only omni bridge");
|
require(uint256(-_extData.extAmount) >= minimalWithdrawalAmount, "amount is less than minimalWithdrawalAmount"); // prevents ddos attack to Bridge
|
||||||
require(_amount >= uint256(_extData.extAmount), "amount from bridge is incorrect");
|
}
|
||||||
require(token.balanceOf(address(this)) >= uint256(_extData.extAmount) + lastBalance, "bridge did not send enough tokens");
|
if (_extData.fee > 0) {
|
||||||
require(uint256(_extData.extAmount) <= maximumDepositAmount, "amount is larger than maximumDepositAmount");
|
token.transfer(_extData.relayer, _extData.fee);
|
||||||
_transact(_args, _extData);
|
}
|
||||||
|
|
||||||
|
lastBalance = token.balanceOf(address(this));
|
||||||
|
_insert(_args.outputCommitments[0], _args.outputCommitments[1]);
|
||||||
|
emit NewCommitment(_args.outputCommitments[0], nextIndex - 2, _extData.encryptedOutput1);
|
||||||
|
emit NewCommitment(_args.outputCommitments[1], nextIndex - 1, _extData.encryptedOutput2);
|
||||||
|
for (uint256 i = 0; i < _args.inputNullifiers.length; i++) {
|
||||||
|
emit NewNullifier(_args.inputNullifiers[i]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function _configureLimits(uint256 _minimalWithdrawalAmount, uint256 _maximumDepositAmount) internal {
|
function _configureLimits(uint256 _minimalWithdrawalAmount, uint256 _maximumDepositAmount) internal {
|
||||||
|
Loading…
Reference in New Issue
Block a user