account fix

This commit is contained in:
Alexey 2021-10-04 19:28:08 +03:00
parent eef612e5ae
commit e7889c4010
3 changed files with 31 additions and 12 deletions

View File

@ -70,10 +70,14 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver {
bytes32 extDataHash; bytes32 extDataHash;
} }
struct Account {
address owner;
bytes publicKey;
}
event NewCommitment(bytes32 commitment, uint256 index, bytes encryptedOutput); event NewCommitment(bytes32 commitment, uint256 index, bytes encryptedOutput);
event NewNullifier(bytes32 nullifier); event NewNullifier(bytes32 nullifier);
event PublicKey(address indexed owner, bytes key); event PublicKey(address indexed owner, bytes key);
event EncryptedAccount(address indexed owner, bytes account);
/** /**
@dev The constructor @dev The constructor
@ -200,16 +204,21 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver {
} }
} }
function register(bytes memory _publicKey) public { function register(Account memory _account) public {
emit PublicKey(msg.sender, _publicKey); require(_account.owner == msg.sender, "only owner can be registered");
_register(_account);
}
function _register(Account memory _account) internal {
emit PublicKey(_account.owner, _account.publicKey);
} }
function registerAndTransact( function registerAndTransact(
bytes memory _publicKey, Account memory _account,
Proof memory _proofArgs, Proof memory _proofArgs,
ExtData memory _extData ExtData memory _extData
) public { ) public {
register(_publicKey); register(_account);
transact(_proofArgs, _extData); transact(_proofArgs, _extData);
} }
@ -218,7 +227,7 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver {
uint256 _amount, uint256 _amount,
bytes calldata _data bytes calldata _data
) external override { ) external override {
(bytes memory _publicKey, Proof memory _args, ExtData memory _extData) = abi.decode(_data, (bytes, Proof, ExtData)); (Account memory _account, Proof memory _args, ExtData memory _extData) = abi.decode(_data, (Account, Proof, ExtData));
require(_token == token, "provided token is not supported"); require(_token == token, "provided token is not supported");
require(msg.sender == omniBridge, "only omni bridge"); require(msg.sender == omniBridge, "only omni bridge");
require(_amount == uint256(_extData.extAmount), "amount from bridge is incorrect"); require(_amount == uint256(_extData.extAmount), "amount from bridge is incorrect");
@ -226,8 +235,8 @@ contract TornadoPool is MerkleTreeWithHistory, IERC20Receiver {
totalDeposited += uint256(_extData.extAmount); totalDeposited += uint256(_extData.extAmount);
if (_publicKey.length != 0) { if (_account.owner != address(0) && _account.publicKey.length > 0) {
register(_publicKey); _register(_account);
} }
_transact(_args, _extData); _transact(_args, _extData);
} }

View File

@ -149,13 +149,13 @@ async function transaction({ tornadoPool, ...rest }) {
return await receipt.wait() return await receipt.wait()
} }
async function registerAndTransact({ tornadoPool, poolAddress, ...rest }) { async function registerAndTransact({ tornadoPool, account, ...rest }) {
const { args, extData } = await prepareTransaction({ const { args, extData } = await prepareTransaction({
tornadoPool, tornadoPool,
...rest, ...rest,
}) })
const receipt = await tornadoPool.registerAndTransact(poolAddress, args, extData, { const receipt = await tornadoPool.registerAndTransact(account, args, extData, {
gasLimit: 2e6, gasLimit: 2e6,
}) })
await receipt.wait() await receipt.wait()

View File

@ -115,7 +115,10 @@ describe('TornadoPool', function () {
await registerAndTransact({ await registerAndTransact({
tornadoPool, tornadoPool,
outputs: [aliceDepositUtxo], outputs: [aliceDepositUtxo],
poolAddress: aliceDepositUtxo.keypair.address(), account: {
owner: sender.address,
publicKey: aliceDepositUtxo.keypair.address(),
},
}) })
const filter = tornadoPool.filters.NewCommitment() const filter = tornadoPool.filters.NewCommitment()
@ -208,7 +211,14 @@ describe('TornadoPool', function () {
tornadoPool, tornadoPool,
outputs: [aliceDepositUtxo], outputs: [aliceDepositUtxo],
}) })
const transactTx = await tornadoPool.populateTransaction.registerAndTransact([], args, extData) const transactTx = await tornadoPool.populateTransaction.registerAndTransact(
{
owner: '0x0000000000000000000000000000000000000000',
publicKey: [],
},
args,
extData,
)
const onTokenBridgedData = '0x' + transactTx.data.slice(10) const onTokenBridgedData = '0x' + transactTx.data.slice(10)
const onTokenBridgedTx = await tornadoPool.populateTransaction.onTokenBridged( const onTokenBridgedTx = await tornadoPool.populateTransaction.onTokenBridged(
token.address, token.address,