Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

validatedSignatureChainHash added to withdrawSigned #35

Merged
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
23 changes: 16 additions & 7 deletions contracts/upgradeable-Bridge/FundManager.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,19 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
string public constant VERSION = "000.004";
bytes32 constant WITHDRAW_SIGNED_METHOD =
keccak256(
"WithdrawSigned(address token,address payee,uint256 amount,bytes32 salt,uint256 expiry)"
"WithdrawSigned(address token,address payee,uint256 amount,bytes32 validatedSignatureChainHash,bytes32 salt,uint256 expiry)"
);
bytes32 constant WITHDRAW_SIGNED_ONEINCH__METHOD =
keccak256(
"WithdrawSignedOneInch(address to,uint256 amountIn,uint256 amountOut,address foundryToken,address targetToken,bytes oneInchData,bytes32 salt,uint256 expiry)"
"WithdrawSignedOneInch(address to,uint256 amountIn,uint256 amountOut,address foundryToken,address targetToken,bytes oneInchData,bytes32 validatedSignatureChainHash,bytes32 salt,uint256 expiry)"
);

event TransferBySignature(
address signer,
address receiver,
address token,
uint256 amount
uint256 amount,
bytes32 validatedSignatureChainHash
);
event BridgeLiquidityAdded(address actor, address token, uint256 amount);
event BridgeLiquidityRemoved(address actor, address token, uint256 amount);
Expand Down Expand Up @@ -194,6 +195,7 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
address token,
address payee,
uint256 amount,
bytes32 validatedSignatureChainHash,
bytes32 salt,
uint256 expiry,
bytes memory signature
Expand All @@ -202,17 +204,18 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
require(payee != address(0), "FM: bad payee");
require(salt != 0, "FM: bad salt");
require(amount != 0, "FM: bad amount");
require(validatedSignatureChainHash != 0, "FM: invalid signature chain hash");
require(block.timestamp < expiry, "FM: signature timed out");
require(expiry < block.timestamp + WEEK, "FM: expiry too far");
bytes32 message = keccak256(
abi.encode(WITHDRAW_SIGNED_METHOD, token, payee, amount, salt, expiry)
abi.encode(WITHDRAW_SIGNED_METHOD, token, payee, amount, validatedSignatureChainHash, salt, expiry)
);
address _signer = signerUnique(message, signature);
require(signers[_signer], "FM: Invalid signer");
require(!usedSalt[salt], "FM: salt already used");
usedSalt[salt] = true;
TokenReceivable.sendToken(token, payee, amount);
emit TransferBySignature(_signer, payee, token, amount);
emit TransferBySignature(_signer, payee, token, amount, validatedSignatureChainHash);
return amount;
}

Expand All @@ -223,6 +226,7 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
address foundryToken,
address targetToken,
bytes memory oneInchData,
bytes32 validatedSignatureChainHash,
bytes32 salt,
uint256 expiry,
bytes memory signature
Expand All @@ -233,6 +237,7 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
require(salt != 0, "FM: bad salt");
require(amountIn != 0, "FM: bad amount");
require(amountOut != 0, "FM: bad amount");
require(validatedSignatureChainHash != 0, "FM: invalid signature chain hash");
require(block.timestamp < expiry, "FM: signature timed out");
require(expiry < block.timestamp + WEEK, "FM: expiry too far");

Expand All @@ -245,6 +250,7 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
foundryToken,
targetToken,
oneInchData,
validatedSignatureChainHash,
salt,
expiry
)
Expand All @@ -254,20 +260,21 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
require(!usedSalt[salt], "FM: Salt already used");
usedSalt[salt] = true;
TokenReceivable.sendToken(foundryToken, router, amountIn);
emit TransferBySignature(_signer, router, foundryToken, amountIn);
emit TransferBySignature(_signer, router, foundryToken, amountIn, validatedSignatureChainHash);
return amountIn;
}

function withdrawSignedVerify(
address token,
address payee,
uint256 amount,
bytes32 validatedSignatureChainHash,
bytes32 salt,
uint256 expiry,
bytes calldata signature
) external view returns (bytes32, address) {
bytes32 message = keccak256(
abi.encode(WITHDRAW_SIGNED_METHOD, token, payee, amount, salt, expiry)
abi.encode(WITHDRAW_SIGNED_METHOD, token, payee, amount, validatedSignatureChainHash, salt, expiry)
);
(bytes32 digest, address _signer) = signer(message, signature);
return (digest, _signer);
Expand All @@ -280,6 +287,7 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
address foundryToken,
address targetToken,
bytes memory oneInchData,
bytes32 validatedSignatureChainHash,
bytes32 salt,
uint256 expiry,
bytes calldata signature
Expand All @@ -293,6 +301,7 @@ contract FundManager is SigCheckable, WithAdmin, TokenReceivable {
foundryToken,
targetToken,
oneInchData,
validatedSignatureChainHash,
salt,
expiry
)
Expand Down