-
Notifications
You must be signed in to change notification settings - Fork 4
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
Bridge v3 #7
base: bridge-v2
Are you sure you want to change the base?
Bridge v3 #7
Changes from 4 commits
134623c
af35127
bc512ee
7b8db4a
a3de913
7fdf7b0
c1599c2
9d212bb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,7 @@ import "./Ownable.sol"; | |
import "./ERC20Burnable.sol"; | ||
import "./SafeERC20.sol"; | ||
import "./EthTokenReciever.sol"; | ||
import "./IUSDT.sol"; | ||
|
||
/** | ||
* Provides functionality of the HASHI bridge | ||
|
@@ -43,6 +44,8 @@ contract Bridge is EthTokenReciever { | |
/** EVM netowrk ID */ | ||
bytes32 public immutable _networkId; | ||
|
||
IUSDT public immutable _addressUSDT; | ||
|
||
event Withdrawal(bytes32 txHash); | ||
event Deposit( | ||
bytes32 destination, | ||
|
@@ -68,6 +71,7 @@ contract Bridge is EthTokenReciever { | |
address[] memory erc20Addresses, | ||
address addressVAL, | ||
address addressXOR, | ||
address addressUSDT, | ||
bytes32 networkId | ||
) { | ||
require( | ||
|
@@ -97,6 +101,7 @@ contract Bridge is EthTokenReciever { | |
for (uint256 i; i < erc20TokensCount; i++) { | ||
acceptedEthTokens[erc20Addresses[i]] = true; | ||
} | ||
_addressUSDT = IUSDT(addressUSDT); | ||
} | ||
|
||
modifier shouldBeInitialized() { | ||
|
@@ -167,7 +172,8 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
abi.encode( | ||
"addToken", | ||
address(this), | ||
newToken, | ||
ticker, | ||
|
@@ -205,7 +211,7 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
abi.encode( | ||
"prepareMigration", | ||
address(this), | ||
salt, | ||
|
@@ -245,7 +251,8 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
abi.encode( | ||
"migrate", | ||
address(this), | ||
newContractAddress, | ||
salt, | ||
|
@@ -273,6 +280,10 @@ contract Bridge is EthTokenReciever { | |
token.balanceOf(address(this)) | ||
); | ||
} | ||
_addressUSDT.transfer( | ||
newContractAddress, | ||
_addressUSDT.balanceOf(address(this)) | ||
); | ||
EthTokenReciever(newContractAddress).receivePayment{ | ||
value: address(this).balance | ||
}(); | ||
|
@@ -306,7 +317,8 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
abi.encode( | ||
"addAsset", | ||
address(this), | ||
name, | ||
symbol, | ||
|
@@ -381,13 +393,23 @@ contract Bridge is EthTokenReciever { | |
acceptedEthTokens[tokenAddress], | ||
"The Token is not accepted for transfer to sidechain" | ||
); | ||
uint256 balanceBefore = token.balanceOf(address(this)); | ||
token.safeTransferFrom(msg.sender, address(this), amount); | ||
uint256 balanceAfter = token.balanceOf(address(this)); | ||
require( | ||
balanceAfter - balanceBefore >= amount, | ||
"Not enough tokens transferred" | ||
); | ||
if (tokenAddress == address(_addressUSDT)) { | ||
uint256 balanceBefore = _addressUSDT.balanceOf(address(this)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. balanceOf in usdt and other ERC20 are the same, so i guess there is no need to split using if |
||
_addressUSDT.transferFrom(msg.sender, address(this), amount); | ||
uint256 balanceAfter = _addressUSDT.balanceOf(address(this)); | ||
require( | ||
balanceAfter - balanceBefore >= amount, | ||
"Not enough tokens transferred" | ||
); | ||
} else { | ||
uint256 balanceBefore = token.balanceOf(address(this)); | ||
token.safeTransferFrom(msg.sender, address(this), amount); | ||
uint256 balanceAfter = token.balanceOf(address(this)); | ||
require( | ||
balanceAfter - balanceBefore >= amount, | ||
"Not enough tokens transferred" | ||
); | ||
} | ||
} | ||
emit Deposit(to, amount, tokenAddress, sidechainAssetId); | ||
} | ||
|
@@ -412,9 +434,9 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
address(this), | ||
abi.encode( | ||
"addPeer", | ||
address(this), | ||
newPeerAddress, | ||
txHash, | ||
_networkId | ||
|
@@ -453,9 +475,9 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
address(this), | ||
abi.encode( | ||
"removePeer", | ||
address(this), | ||
peerAddress, | ||
txHash, | ||
_networkId | ||
|
@@ -499,7 +521,8 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
abi.encode( | ||
"transfer", | ||
address(this), | ||
tokenAddress, | ||
amount, | ||
|
@@ -521,9 +544,13 @@ contract Bridge is EthTokenReciever { | |
// untrusted transfer, relies on provided cryptographic proof | ||
to.transfer(amount); | ||
} else { | ||
IERC20 coin = IERC20(tokenAddress); | ||
// untrusted call, relies on provided cryptographic proof | ||
coin.safeTransfer(to, amount); | ||
if (tokenAddress == address(_addressUSDT)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. have you tested safeERC20 with USDT token? it's supposed to work correctly |
||
_addressUSDT.transfer(to, amount); | ||
} else { | ||
IERC20 coin = IERC20(tokenAddress); | ||
// untrusted call, relies on provided cryptographic proof | ||
coin.safeTransfer(to, amount); | ||
} | ||
} | ||
emit Withdrawal(txHash); | ||
} | ||
|
@@ -557,7 +584,8 @@ contract Bridge is EthTokenReciever { | |
require( | ||
checkSignatures( | ||
keccak256( | ||
abi.encodePacked( | ||
abi.encode( | ||
"transferOwned", | ||
address(this), | ||
sidechainAssetId, | ||
amount, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// SPDX-License-Identifier: Apache 2.0 | ||
|
||
pragma solidity =0.8.17; | ||
|
||
// Taken from https://etherscan.io/address/0xdac17f958d2ee523a2206206994597c13d831ec7#code | ||
|
||
/** | ||
* @title ERC20Basic | ||
* @dev Simpler version of ERC20 interface | ||
* @dev see https://github.com/ethereum/EIPs/issues/20 | ||
*/ | ||
interface IUSDT { | ||
function totalSupply() external returns (uint); | ||
|
||
function balanceOf(address who) external returns (uint); | ||
|
||
function transfer(address to, uint value) external; | ||
|
||
event Transfer(address indexed from, address indexed to, uint value); | ||
|
||
function allowance(address owner, address spender) external returns (uint); | ||
|
||
function transferFrom( | ||
address from, | ||
address to, | ||
uint value | ||
) external; | ||
|
||
function approve(address spender, uint value) external; | ||
|
||
event Approval(address indexed owner, address indexed spender, uint value); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
import DeployConfig from "./config"; | ||
|
||
const config: DeployConfig = { | ||
"xorAddress": "0x9826ecfcd937c4518e1c42b3703c7cb908b61197", | ||
"valAddress": "0x88ee18defc56d78417b0d331e794ef75799ca6d1", | ||
usdtAddress: undefined, | ||
"sidechainAssets": [ | ||
], | ||
"erc20Addresses": [ | ||
], | ||
"peers": [ | ||
"0x981bccf6d8593dc49c22cf744a59afa5a2b23118", | ||
"0x90dca3c91c10e802093318123ad8bb8809061765", | ||
"0x457d710255184dbf63c019ab50f65743c6cb072f" | ||
] | ||
}; | ||
|
||
export default config; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ import { resolve } from "path"; | |
import "solidity-coverage" | ||
|
||
import * as gen_config from "./tasks/gen-config"; | ||
import * as send from "./tasks/send"; | ||
|
||
dotenv({ path: resolve(__dirname, ".env") }); | ||
|
||
|
@@ -57,6 +58,11 @@ const config: HardhatUserConfig = { | |
url: 'https://rpc.sepolia.org', | ||
accounts: [sepoliaPrivateKey], | ||
}, | ||
sepolia2: { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? they are the same (sepolia and sepolia2) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. To have deployment data for test and stage environment |
||
chainId: 11155111, | ||
url: 'https://rpc.sepolia.org', | ||
accounts: [sepoliaPrivateKey], | ||
}, | ||
mainnet: { | ||
chainId: 1, | ||
url: `https://mainnet.infura.io/v3/${infuraKey}`, | ||
|
@@ -87,7 +93,25 @@ const config: HardhatUserConfig = { | |
timeout: 60000 | ||
}, | ||
etherscan: { | ||
apiKey: etherscanKey | ||
apiKey: etherscanKey, | ||
customChains: [ | ||
{ | ||
network: "sepolia", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 2 exactly the same chains |
||
chainId: 11155111, | ||
urls: { | ||
apiURL: "https://api-sepolia.etherscan.io/api", | ||
browserURL: "https://sepolia.etherscan.io" | ||
} | ||
}, | ||
{ | ||
network: "sepolia", | ||
chainId: 11155111, | ||
urls: { | ||
apiURL: "https://api-sepolia.etherscan.io/api", | ||
browserURL: "https://sepolia.etherscan.io" | ||
} | ||
} | ||
] | ||
} | ||
}; | ||
|
||
|
@@ -97,4 +121,9 @@ task("gen-config", "Generate config file for given network") | |
.addParam("peers") | ||
.addParam("output").setAction(gen_config.main); | ||
|
||
task("send", "Generate config file for given network") | ||
.addParam("to") | ||
.addParam("amount") | ||
.addParam("token", "Token address", undefined, undefined, true) | ||
.setAction(send.main); | ||
export default config; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Transition from encode to encodePacked is not that necessary but might be taken as it may only affect the order of the params for the statement we sign but not the signature itself
Just make sure that it works fine when passing params to recoverAddress, now it looks okay, but it will not be superfluous to double check it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's needed to prevent signature collision