updates:
* pragma bump to 0.8.10 * updated gravity bridge contracts * moved modified contracts to new 'test' dir for unit test clarity
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/6dfbc7f87ae3c2727d63a3fba8d02a41.json"
|
||||
"buildInfo": "../../../../../build-info/b4e7ec2fd35748689d35a44cde08a2e7.json"
|
||||
}
|
||||
|
||||
+2
-2
File diff suppressed because one or more lines are too long
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/6dfbc7f87ae3c2727d63a3fba8d02a41.json"
|
||||
"buildInfo": "../../../../../build-info/b4e7ec2fd35748689d35a44cde08a2e7.json"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../../build-info/6dfbc7f87ae3c2727d63a3fba8d02a41.json"
|
||||
"buildInfo": "../../../../../../build-info/b4e7ec2fd35748689d35a44cde08a2e7.json"
|
||||
}
|
||||
|
||||
+1
-1
@@ -1,4 +1,4 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/6dfbc7f87ae3c2727d63a3fba8d02a41.json"
|
||||
"buildInfo": "../../../../build-info/b4e7ec2fd35748689d35a44cde08a2e7.json"
|
||||
}
|
||||
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "SafeMath",
|
||||
"sourceName": "@openzeppelin/contracts/math/SafeMath.sol",
|
||||
"abi": [],
|
||||
"bytecode": "0x60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212207ceb5b9e8bb631a9723802d1487d75b0f9db1e57e569e37561e9d35cd45a718c64736f6c63430006060033",
|
||||
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212207ceb5b9e8bb631a9723802d1487d75b0f9db1e57e569e37561e9d35cd45a718c64736f6c63430006060033",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-297
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-194
@@ -1,194 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "IERC20",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
||||
"abi": [
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Approval",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"anonymous": false,
|
||||
"inputs": [
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "from",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": true,
|
||||
"internalType": "address",
|
||||
"name": "to",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"indexed": false,
|
||||
"internalType": "uint256",
|
||||
"name": "value",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "Transfer",
|
||||
"type": "event"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "owner",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "allowance",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "spender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "amount",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "approve",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "account",
|
||||
"type": "address"
|
||||
}
|
||||
],
|
||||
"name": "balanceOf",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [],
|
||||
"name": "totalSupply",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"stateMutability": "view",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "recipient",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "amount",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transfer",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
},
|
||||
{
|
||||
"inputs": [
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "sender",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "address",
|
||||
"name": "recipient",
|
||||
"type": "address"
|
||||
},
|
||||
{
|
||||
"internalType": "uint256",
|
||||
"name": "amount",
|
||||
"type": "uint256"
|
||||
}
|
||||
],
|
||||
"name": "transferFrom",
|
||||
"outputs": [
|
||||
{
|
||||
"internalType": "bool",
|
||||
"name": "",
|
||||
"type": "bool"
|
||||
}
|
||||
],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "function"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "SafeERC20",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/SafeERC20.sol",
|
||||
"abi": [],
|
||||
"bytecode": "0x60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220a10ad72c41cead301751dbbfdbfa8dc0de387237baaadf00c593410d921ba53164736f6c63430006060033",
|
||||
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220a10ad72c41cead301751dbbfdbfa8dc0de387237baaadf00c593410d921ba53164736f6c63430006060033",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "Address",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Address.sol",
|
||||
"abi": [],
|
||||
"bytecode": "0x60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220bf51151e2a4e160194baa49fc39a27bad1253743e398fefe6fb6935ec7d37a5e64736f6c63430006060033",
|
||||
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea2646970667358221220bf51151e2a4e160194baa49fc39a27bad1253743e398fefe6fb6935ec7d37a5e64736f6c63430006060033",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-10
@@ -1,10 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "Context",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Context.sol",
|
||||
"abi": [],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-16
@@ -1,16 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-artifact-1",
|
||||
"contractName": "ReentrancyGuard",
|
||||
"sourceName": "@openzeppelin/contracts/utils/ReentrancyGuard.sol",
|
||||
"abi": [
|
||||
{
|
||||
"inputs": [],
|
||||
"stateMutability": "nonpayable",
|
||||
"type": "constructor"
|
||||
}
|
||||
],
|
||||
"bytecode": "0x",
|
||||
"deployedBytecode": "0x",
|
||||
"linkReferences": {},
|
||||
"deployedLinkReferences": {}
|
||||
}
|
||||
-222
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-325
File diff suppressed because one or more lines are too long
-4
@@ -1,4 +0,0 @@
|
||||
{
|
||||
"_format": "hh-sol-dbg-1",
|
||||
"buildInfo": "../../build-info/10e5405221d21329b74f12bf00d0cd2d.json"
|
||||
}
|
||||
-678
File diff suppressed because one or more lines are too long
@@ -2,11 +2,11 @@
|
||||
"_format": "hh-sol-cache-2",
|
||||
"files": {
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/BandwidthGenerator.sol": {
|
||||
"lastModificationDate": 1639657373736,
|
||||
"contentHash": "ac31a05f19ad88d4c28011a830d29b56",
|
||||
"lastModificationDate": 1641813499577,
|
||||
"contentHash": "019fffdd8521017f63b3e923d292c025",
|
||||
"sourceName": "contracts/BandwidthGenerator.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -31,21 +31,21 @@
|
||||
"./CosmosToken.sol",
|
||||
"./Gravity.sol",
|
||||
"@openzeppelin/contracts/access/Ownable.sol",
|
||||
"@openzeppelin/contracts/math/SafeMath.sol"
|
||||
"@openzeppelin/contracts/utils/math/SafeMath.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"0.6.6"
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"BandwidthGenerator"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/CosmosToken.sol": {
|
||||
"lastModificationDate": 1639657191231,
|
||||
"contentHash": "0f05f96ee3c1151b6cd4b699aa3167e9",
|
||||
"lastModificationDate": 1641811013678,
|
||||
"contentHash": "fc5dd09fe73bc6cfece970f702a3aba1",
|
||||
"sourceName": "contracts/CosmosToken.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -70,18 +70,18 @@
|
||||
"@openzeppelin/contracts/token/ERC20/ERC20.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"^0.6.6"
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"CosmosERC20"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/Gravity.sol": {
|
||||
"lastModificationDate": 1639657191231,
|
||||
"contentHash": "eaa1cd71cea24d419ef5f67a66dc672e",
|
||||
"lastModificationDate": 1641810221576,
|
||||
"contentHash": "0d6dae561f7b541bafb892b8593a08ac",
|
||||
"sourceName": "contracts/Gravity.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -103,26 +103,26 @@
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"@openzeppelin/contracts/math/SafeMath.sol",
|
||||
"@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
||||
"@openzeppelin/contracts/token/ERC20/SafeERC20.sol",
|
||||
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol",
|
||||
"@openzeppelin/contracts/security/ReentrancyGuard.sol",
|
||||
"@openzeppelin/contracts/utils/Address.sol",
|
||||
"@openzeppelin/contracts/utils/ReentrancyGuard.sol",
|
||||
"@openzeppelin/contracts/utils/cryptography/ECDSA.sol",
|
||||
"./CosmosToken.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"^0.6.6"
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"Gravity"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/access/Ownable.sol": {
|
||||
"lastModificationDate": 1639657303711,
|
||||
"contentHash": "6748815a5b45c4aeeda56819f41190e0",
|
||||
"lastModificationDate": 1641812554274,
|
||||
"contentHash": "4fe56b59ced59d87df6b796758f62895",
|
||||
"sourceName": "@openzeppelin/contracts/access/Ownable.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -147,18 +147,18 @@
|
||||
"../utils/Context.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"Ownable"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/math/SafeMath.sol": {
|
||||
"lastModificationDate": 1639657303763,
|
||||
"contentHash": "e03e12206057e809eb76c5f681170c32",
|
||||
"sourceName": "@openzeppelin/contracts/math/SafeMath.sol",
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol": {
|
||||
"lastModificationDate": 1641812554378,
|
||||
"contentHash": "5365090efc586b728719e562ebfed0d6",
|
||||
"sourceName": "@openzeppelin/contracts/utils/math/SafeMath.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -181,18 +181,18 @@
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"SafeMath"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol": {
|
||||
"lastModificationDate": 1639657303507,
|
||||
"contentHash": "8065b340476f61365c076897199425f1",
|
||||
"lastModificationDate": 1641812553614,
|
||||
"contentHash": "2cd550cedf51b8d294607dad5023d717",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/ERC20.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -214,57 +214,23 @@
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"../../utils/Context.sol",
|
||||
"./IERC20.sol",
|
||||
"../../math/SafeMath.sol"
|
||||
"./extensions/IERC20Metadata.sol",
|
||||
"../../utils/Context.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"ERC20"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Context.sol": {
|
||||
"lastModificationDate": 1639657303395,
|
||||
"contentHash": "2adbd82f6d055a4751566d4671512b03",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Context.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"Context"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol": {
|
||||
"lastModificationDate": 1639657303639,
|
||||
"contentHash": "e0a41531d159d3a32f84b7a3ecf9fabb",
|
||||
"lastModificationDate": 1641812554110,
|
||||
"contentHash": "0eac3e1a83ee62326ca007811285b274",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -287,18 +253,18 @@
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"IERC20"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/SafeERC20.sol": {
|
||||
"lastModificationDate": 1639657303759,
|
||||
"contentHash": "33e22842646d746e5c4124c2fdc051aa",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/SafeERC20.sol",
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol": {
|
||||
"lastModificationDate": 1641812554118,
|
||||
"contentHash": "aa1be06992a99bb7393b26a6af3c4dfb",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -320,23 +286,92 @@
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"./IERC20.sol",
|
||||
"../../math/SafeMath.sol",
|
||||
"../../utils/Address.sol"
|
||||
"../IERC20.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"IERC20Metadata"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Context.sol": {
|
||||
"lastModificationDate": 1641812553346,
|
||||
"contentHash": "851485d5b925529b1a2f34a0be077891",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Context.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"Context"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol": {
|
||||
"lastModificationDate": 1641812554370,
|
||||
"contentHash": "d37406082a74a9b6b114de522fcb6349",
|
||||
"sourceName": "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"../IERC20.sol",
|
||||
"../../../utils/Address.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"SafeERC20"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Address.sol": {
|
||||
"lastModificationDate": 1639657303363,
|
||||
"contentHash": "7aa46886ff5abe7515496208a5e2ce5a",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Address.sol",
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol": {
|
||||
"lastModificationDate": 1641812554322,
|
||||
"contentHash": "53fbff678f378956efcb207fa748eaa6",
|
||||
"sourceName": "@openzeppelin/contracts/security/ReentrancyGuard.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -359,18 +394,52 @@
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
">=0.6.2 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"ReentrancyGuard"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/Address.sol": {
|
||||
"lastModificationDate": 1641812553270,
|
||||
"contentHash": "c5f6c4e4df069c789e7d84b4c3011913",
|
||||
"sourceName": "@openzeppelin/contracts/utils/Address.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"Address"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/ReentrancyGuard.sol": {
|
||||
"lastModificationDate": 1639657303747,
|
||||
"contentHash": "1c60f58cee45c61469e1aea31e4dd879",
|
||||
"sourceName": "@openzeppelin/contracts/utils/ReentrancyGuard.sol",
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/node_modules/@openzeppelin/contracts/utils/cryptography/ECDSA.sol": {
|
||||
"lastModificationDate": 1641812553414,
|
||||
"contentHash": "197dbfaf7146845fa76331a4c9980e9f",
|
||||
"sourceName": "@openzeppelin/contracts/utils/cryptography/ECDSA.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.6.6",
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
@@ -393,10 +462,87 @@
|
||||
},
|
||||
"imports": [],
|
||||
"versionPragmas": [
|
||||
">=0.6.0 <0.8.0"
|
||||
"^0.8.0"
|
||||
],
|
||||
"artifacts": [
|
||||
"ReentrancyGuard"
|
||||
"ECDSA"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/test-contracts/TestCosmosToken.sol": {
|
||||
"lastModificationDate": 1641813266722,
|
||||
"contentHash": "957b6079ee0d5a6e048fce8555c14dee",
|
||||
"sourceName": "contracts/test-contracts/TestCosmosToken.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"@openzeppelin/contracts/token/ERC20/ERC20.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"TestCosmosERC20"
|
||||
]
|
||||
},
|
||||
"/home/max/dev/nymtech/nym/contracts/basic-bandwidth-generation/contracts/test-contracts/TestGravity.sol": {
|
||||
"lastModificationDate": 1641813465624,
|
||||
"contentHash": "5c725464b149a3862c88db62891d8f66",
|
||||
"sourceName": "contracts/test-contracts/TestGravity.sol",
|
||||
"solcConfig": {
|
||||
"version": "0.8.10",
|
||||
"settings": {
|
||||
"optimizer": {
|
||||
"enabled": true,
|
||||
"runs": 200
|
||||
},
|
||||
"outputSelection": {
|
||||
"*": {
|
||||
"*": [
|
||||
"abi",
|
||||
"evm.bytecode",
|
||||
"evm.deployedBytecode",
|
||||
"evm.methodIdentifiers"
|
||||
],
|
||||
"": [
|
||||
"ast"
|
||||
]
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"imports": [
|
||||
"@openzeppelin/contracts/token/ERC20/IERC20.sol",
|
||||
"@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol",
|
||||
"@openzeppelin/contracts/security/ReentrancyGuard.sol",
|
||||
"@openzeppelin/contracts/utils/Address.sol",
|
||||
"@openzeppelin/contracts/utils/cryptography/ECDSA.sol",
|
||||
"./TestCosmosToken.sol"
|
||||
],
|
||||
"versionPragmas": [
|
||||
"0.8.10"
|
||||
],
|
||||
"artifacts": [
|
||||
"Gravity"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
pragma solidity 0.6.6;
|
||||
pragma solidity 0.8.10;
|
||||
|
||||
import "./CosmosToken.sol";
|
||||
import "./Gravity.sol";
|
||||
import "@openzeppelin/contracts/access/Ownable.sol";
|
||||
import "@openzeppelin/contracts/math/SafeMath.sol";
|
||||
import "@openzeppelin/contracts/utils/math/SafeMath.sol";
|
||||
|
||||
/**
|
||||
* @title BandwidthGenerator
|
||||
@@ -28,7 +28,7 @@ contract BandwidthGenerator is Ownable {
|
||||
uint256 Bandwidth,
|
||||
uint256 indexed VerificationKey,
|
||||
bytes SignedVerificationKey,
|
||||
bytes32 indexed CosmosRecipient
|
||||
string indexed CosmosRecipient
|
||||
);
|
||||
|
||||
event RatioChanged(
|
||||
@@ -39,7 +39,7 @@ contract BandwidthGenerator is Ownable {
|
||||
* @param _erc20 Address of the erc20NYM deployed through the Gravity Bridge.
|
||||
* @param _gravityBridge Address of the deployed Gravity Bridge.
|
||||
*/
|
||||
constructor(CosmosERC20 _erc20, Gravity _gravityBridge) public {
|
||||
constructor(CosmosERC20 _erc20, Gravity _gravityBridge) {
|
||||
require(address(_erc20) != address(0), "BandwidthGenerator: erc20 address cannot be null");
|
||||
require(address(_gravityBridge) != address(0), "BandwidthGenerator: gravity bridge address cannot be null");
|
||||
erc20 = _erc20;
|
||||
@@ -65,7 +65,7 @@ contract BandwidthGenerator is Ownable {
|
||||
* @param _signedVerificationKey Number of erc20NYMs to spend signed by _verificationKey for auth on Cosmos Blockchain.
|
||||
* @param _cosmosRecipient Address of the recipient of payment on Nym Cosmos Blockchain.
|
||||
*/
|
||||
function generateBasicBandwidthCredential(uint256 _amount, uint256 _verificationKey, bytes memory _signedVerificationKey, bytes32 _cosmosRecipient) public {
|
||||
function generateBasicBandwidthCredential(uint256 _amount, uint256 _verificationKey, bytes memory _signedVerificationKey, string memory _cosmosRecipient) public {
|
||||
require(_signedVerificationKey.length == 64, "BandwidthGenerator: Signature doesn't have 64 bytes");
|
||||
erc20.transferFrom(msg.sender, address(this), _amount);
|
||||
erc20.approve(address(gravityBridge), _amount);
|
||||
|
||||
@@ -1,33 +1,35 @@
|
||||
pragma solidity ^0.6.6;
|
||||
//SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity 0.8.10;
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
/**
|
||||
* This is a slightly modified version of the cosmos erc20 contract
|
||||
* which I have done for unit testing.
|
||||
*
|
||||
* All that has been changed is the MAX_UINT variable to allow
|
||||
* me to mint some tokens more easily in unit tests, and the
|
||||
* addition of the public mint() function.
|
||||
*/
|
||||
|
||||
contract CosmosERC20 is ERC20 {
|
||||
/* canonical amount */
|
||||
// uint256 MAX_UINT = 2**256 - 1;
|
||||
uint256 MAX_UINT = 2**256 - 1;
|
||||
uint8 private cosmosDecimals;
|
||||
address private gravityAddress;
|
||||
|
||||
/* unit testing amount */
|
||||
uint256 HALF_MAX_UINT = 2**256 / 2;
|
||||
// This override ensures we return the proper number of decimals
|
||||
// for the cosmos token
|
||||
function decimals() public view virtual override returns (uint8) {
|
||||
return cosmosDecimals;
|
||||
}
|
||||
|
||||
// This is not an accurate total supply. Instead this is the total supply
|
||||
// of the given cosmos asset on Ethereum at this moment in time. Keeping
|
||||
// a totally accurate supply would require constant updates from the Cosmos
|
||||
// side, while in theory this could be piggy-backed on some existing bridge
|
||||
// operation it's a lot of complextiy to add so we chose to forgoe it.
|
||||
function totalSupply() public view virtual override returns (uint256) {
|
||||
return MAX_UINT - balanceOf(gravityAddress);
|
||||
}
|
||||
|
||||
constructor(
|
||||
address _gravityAddress,
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
uint8 _decimals
|
||||
) public ERC20(_name, _symbol) {
|
||||
_setupDecimals(_decimals);
|
||||
_mint(_gravityAddress, HALF_MAX_UINT);
|
||||
) ERC20(_name, _symbol) {
|
||||
cosmosDecimals = _decimals;
|
||||
gravityAddress = _gravityAddress;
|
||||
_mint(_gravityAddress, MAX_UINT);
|
||||
}
|
||||
|
||||
function mintForUnitTesting(address _to, uint _amount) public {
|
||||
_mint(_to, _amount);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,27 @@
|
||||
pragma solidity ^0.6.6;
|
||||
//SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity 0.8.10;
|
||||
|
||||
import "@openzeppelin/contracts/math/SafeMath.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/SafeERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
|
||||
import "@openzeppelin/contracts/utils/Address.sol";
|
||||
import "@openzeppelin/contracts/utils/ReentrancyGuard.sol";
|
||||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
||||
import "./CosmosToken.sol";
|
||||
|
||||
pragma experimental ABIEncoderV2;
|
||||
error InvalidSignature();
|
||||
error InvalidValsetNonce(uint256 newNonce, uint256 currentNonce);
|
||||
error InvalidBatchNonce(uint256 newNonce, uint256 currentNonce);
|
||||
error InvalidLogicCallNonce(uint256 newNonce, uint256 currentNonce);
|
||||
error InvalidLogicCallTransfers();
|
||||
error InvalidLogicCallFees();
|
||||
error InvalidSendToCosmos();
|
||||
error IncorrectCheckpoint();
|
||||
error MalformedNewValidatorSet();
|
||||
error MalformedCurrentValidatorSet();
|
||||
error MalformedBatch();
|
||||
error InsufficientPower(uint256 cumulativePower, uint256 powerThreshold);
|
||||
error BatchTimedOut();
|
||||
error LogicCallTimedOut();
|
||||
|
||||
// This is being used purely to avoid stack too deep errors
|
||||
struct LogicCallArgs {
|
||||
@@ -26,10 +40,36 @@ struct LogicCallArgs {
|
||||
uint256 invalidationNonce;
|
||||
}
|
||||
|
||||
// This is used purely to avoid stack too deep errors
|
||||
// represents everything about a given validator set
|
||||
struct ValsetArgs {
|
||||
// the validators in this set, represented by an Ethereum address
|
||||
address[] validators;
|
||||
// the powers of the given validators in the same order as above
|
||||
uint256[] powers;
|
||||
// the nonce of this validator set
|
||||
uint256 valsetNonce;
|
||||
// the reward amount denominated in the below reward token, can be
|
||||
// set to zero
|
||||
uint256 rewardAmount;
|
||||
// the reward token, should be set to the zero address if not being used
|
||||
address rewardToken;
|
||||
}
|
||||
|
||||
// This represents a validator signature
|
||||
struct Signature {
|
||||
uint8 v;
|
||||
bytes32 r;
|
||||
bytes32 s;
|
||||
}
|
||||
|
||||
contract Gravity is ReentrancyGuard {
|
||||
using SafeMath for uint256;
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
// The number of 'votes' required to execute a valset
|
||||
// update or batch execution, set to 2/3 of 2^32
|
||||
uint256 constant constant_powerThreshold = 2863311530;
|
||||
|
||||
// These are updated often
|
||||
bytes32 public state_lastValsetCheckpoint;
|
||||
mapping(address => uint256) public state_lastBatchNonces;
|
||||
@@ -39,9 +79,8 @@ contract Gravity is ReentrancyGuard {
|
||||
// value indicating that no events have yet been submitted
|
||||
uint256 public state_lastEventNonce = 1;
|
||||
|
||||
// These are set once at initialization
|
||||
bytes32 public state_gravityId;
|
||||
uint256 public state_powerThreshold;
|
||||
// This is set once at initialization
|
||||
bytes32 public immutable state_gravityId;
|
||||
|
||||
// TransactionBatchExecutedEvent and SendToCosmosEvent both include the field _eventNonce.
|
||||
// This is incremented every time one of these events is emitted. It is checked by the
|
||||
@@ -57,7 +96,7 @@ contract Gravity is ReentrancyGuard {
|
||||
event SendToCosmosEvent(
|
||||
address indexed _tokenContract,
|
||||
address indexed _sender,
|
||||
bytes32 indexed _destination,
|
||||
string _destination,
|
||||
uint256 _amount,
|
||||
uint256 _eventNonce
|
||||
);
|
||||
@@ -73,6 +112,8 @@ contract Gravity is ReentrancyGuard {
|
||||
event ValsetUpdatedEvent(
|
||||
uint256 indexed _newValsetNonce,
|
||||
uint256 _eventNonce,
|
||||
uint256 _rewardAmount,
|
||||
address _rewardToken,
|
||||
address[] _validators,
|
||||
uint256[] _powers
|
||||
);
|
||||
@@ -85,42 +126,26 @@ contract Gravity is ReentrancyGuard {
|
||||
|
||||
// TEST FIXTURES
|
||||
// These are here to make it easier to measure gas usage. They should be removed before production
|
||||
function testMakeCheckpoint(
|
||||
address[] memory _validators,
|
||||
uint256[] memory _powers,
|
||||
uint256 _valsetNonce,
|
||||
bytes32 _gravityId
|
||||
) public pure {
|
||||
makeCheckpoint(_validators, _powers, _valsetNonce, _gravityId);
|
||||
function testMakeCheckpoint(ValsetArgs calldata _valsetArgs, bytes32 _gravityId) external pure {
|
||||
makeCheckpoint(_valsetArgs, _gravityId);
|
||||
}
|
||||
|
||||
function testCheckValidatorSignatures(
|
||||
address[] memory _currentValidators,
|
||||
uint256[] memory _currentPowers,
|
||||
uint8[] memory _v,
|
||||
bytes32[] memory _r,
|
||||
bytes32[] memory _s,
|
||||
ValsetArgs calldata _currentValset,
|
||||
Signature[] calldata _sigs,
|
||||
bytes32 _theHash,
|
||||
uint256 _powerThreshold
|
||||
) public pure {
|
||||
checkValidatorSignatures(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_v,
|
||||
_r,
|
||||
_s,
|
||||
_theHash,
|
||||
_powerThreshold
|
||||
);
|
||||
) external pure {
|
||||
checkValidatorSignatures(_currentValset, _sigs, _theHash, _powerThreshold);
|
||||
}
|
||||
|
||||
// END TEST FIXTURES
|
||||
|
||||
function lastBatchNonce(address _erc20Address) public view returns (uint256) {
|
||||
function lastBatchNonce(address _erc20Address) external view returns (uint256) {
|
||||
return state_lastBatchNonces[_erc20Address];
|
||||
}
|
||||
|
||||
function lastLogicCallNonce(bytes32 _invalidation_id) public view returns (uint256) {
|
||||
function lastLogicCallNonce(bytes32 _invalidation_id) external view returns (uint256) {
|
||||
return state_invalidationMapping[_invalidation_id];
|
||||
}
|
||||
|
||||
@@ -128,13 +153,23 @@ contract Gravity is ReentrancyGuard {
|
||||
function verifySig(
|
||||
address _signer,
|
||||
bytes32 _theHash,
|
||||
uint8 _v,
|
||||
bytes32 _r,
|
||||
bytes32 _s
|
||||
Signature calldata _sig
|
||||
) private pure returns (bool) {
|
||||
bytes32 messageDigest =
|
||||
keccak256(abi.encodePacked("\x19Ethereum Signed Message:\n32", _theHash));
|
||||
return _signer == ecrecover(messageDigest, _v, _r, _s);
|
||||
bytes32 messageDigest = keccak256(
|
||||
abi.encodePacked("\x19Ethereum Signed Message:\n32", _theHash)
|
||||
);
|
||||
return _signer == ECDSA.recover(messageDigest, _sig.v, _sig.r, _sig.s);
|
||||
}
|
||||
|
||||
// Utility function to determine that a validator set and signatures are well formed
|
||||
function validateValset(ValsetArgs calldata _valset, Signature[] calldata _sigs) private pure {
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
if (
|
||||
_valset.validators.length != _valset.powers.length ||
|
||||
_valset.validators.length != _sigs.length
|
||||
) {
|
||||
revert MalformedCurrentValidatorSet();
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new checkpoint from the supplied validator set
|
||||
@@ -145,47 +180,51 @@ contract Gravity is ReentrancyGuard {
|
||||
// Where h is the keccak256 hash function.
|
||||
// The validator powers must be decreasing or equal. This is important for checking the signatures on the
|
||||
// next valset, since it allows the caller to stop verifying signatures once a quorum of signatures have been verified.
|
||||
function makeCheckpoint(
|
||||
address[] memory _validators,
|
||||
uint256[] memory _powers,
|
||||
uint256 _valsetNonce,
|
||||
bytes32 _gravityId
|
||||
) private pure returns (bytes32) {
|
||||
function makeCheckpoint(ValsetArgs memory _valsetArgs, bytes32 _gravityId)
|
||||
private
|
||||
pure
|
||||
returns (bytes32)
|
||||
{
|
||||
// bytes32 encoding of the string "checkpoint"
|
||||
bytes32 methodName = 0x636865636b706f696e7400000000000000000000000000000000000000000000;
|
||||
|
||||
bytes32 checkpoint =
|
||||
keccak256(abi.encode(_gravityId, methodName, _valsetNonce, _validators, _powers));
|
||||
bytes32 checkpoint = keccak256(
|
||||
abi.encode(
|
||||
_gravityId,
|
||||
methodName,
|
||||
_valsetArgs.valsetNonce,
|
||||
_valsetArgs.validators,
|
||||
_valsetArgs.powers,
|
||||
_valsetArgs.rewardAmount,
|
||||
_valsetArgs.rewardToken
|
||||
)
|
||||
);
|
||||
|
||||
return checkpoint;
|
||||
}
|
||||
|
||||
function checkValidatorSignatures(
|
||||
// The current validator set and their powers
|
||||
address[] memory _currentValidators,
|
||||
uint256[] memory _currentPowers,
|
||||
ValsetArgs calldata _currentValset,
|
||||
// The current validator's signatures
|
||||
uint8[] memory _v,
|
||||
bytes32[] memory _r,
|
||||
bytes32[] memory _s,
|
||||
Signature[] calldata _sigs,
|
||||
// This is what we are checking they have signed
|
||||
bytes32 _theHash,
|
||||
uint256 _powerThreshold
|
||||
) private pure {
|
||||
uint256 cumulativePower = 0;
|
||||
|
||||
for (uint256 i = 0; i < _currentValidators.length; i++) {
|
||||
for (uint256 i = 0; i < _currentValset.validators.length; i++) {
|
||||
// If v is set to 0, this signifies that it was not possible to get a signature from this validator and we skip evaluation
|
||||
// (In a valid signature, it is either 27 or 28)
|
||||
if (_v[i] != 0) {
|
||||
if (_sigs[i].v != 0) {
|
||||
// Check that the current validator has signed off on the hash
|
||||
require(
|
||||
verifySig(_currentValidators[i], _theHash, _v[i], _r[i], _s[i]),
|
||||
"Validator signature does not match."
|
||||
);
|
||||
if (!verifySig(_currentValset.validators[i], _theHash, _sigs[i])) {
|
||||
revert InvalidSignature();
|
||||
}
|
||||
|
||||
// Sum up cumulative power
|
||||
cumulativePower = cumulativePower + _currentPowers[i];
|
||||
cumulativePower = cumulativePower + _currentValset.powers[i];
|
||||
|
||||
// Break early to avoid wasting gas
|
||||
if (cumulativePower > _powerThreshold) {
|
||||
@@ -195,76 +234,81 @@ contract Gravity is ReentrancyGuard {
|
||||
}
|
||||
|
||||
// Check that there was enough power
|
||||
require(
|
||||
cumulativePower > _powerThreshold,
|
||||
"Submitted validator set signatures do not have enough power."
|
||||
);
|
||||
if (cumulativePower <= _powerThreshold) {
|
||||
revert InsufficientPower(cumulativePower, _powerThreshold);
|
||||
}
|
||||
// Success
|
||||
}
|
||||
|
||||
// This updates the valset by checking that the validators in the current valset have signed off on the
|
||||
// new valset. The signatures supplied are the signatures of the current valset over the checkpoint hash
|
||||
// generated from the new valset.
|
||||
// Anyone can call this function, but they must supply valid signatures of state_powerThreshold of the current valset over
|
||||
// Anyone can call this function, but they must supply valid signatures of constant_powerThreshold of the current valset over
|
||||
// the new valset.
|
||||
function updateValset(
|
||||
// The new version of the validator set
|
||||
address[] memory _newValidators,
|
||||
uint256[] memory _newPowers,
|
||||
uint256 _newValsetNonce,
|
||||
ValsetArgs calldata _newValset,
|
||||
// The current validators that approve the change
|
||||
address[] memory _currentValidators,
|
||||
uint256[] memory _currentPowers,
|
||||
uint256 _currentValsetNonce,
|
||||
ValsetArgs calldata _currentValset,
|
||||
// These are arrays of the parts of the current validator's signatures
|
||||
uint8[] memory _v,
|
||||
bytes32[] memory _r,
|
||||
bytes32[] memory _s
|
||||
) public nonReentrant {
|
||||
Signature[] calldata _sigs
|
||||
) external {
|
||||
// CHECKS
|
||||
|
||||
// Check that the valset nonce is greater than the old one
|
||||
require(
|
||||
_newValsetNonce > _currentValsetNonce,
|
||||
"New valset nonce must be greater than the current nonce"
|
||||
);
|
||||
if (_newValset.valsetNonce <= _currentValset.valsetNonce) {
|
||||
revert InvalidValsetNonce({
|
||||
newNonce: _newValset.valsetNonce,
|
||||
currentNonce: _currentValset.valsetNonce
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the valset nonce is less than a million nonces forward from the old one
|
||||
// this makes it difficult for an attacker to lock out the contract by getting a single
|
||||
// bad validator set through with uint256 max nonce
|
||||
if (_newValset.valsetNonce > _currentValset.valsetNonce + 1000000) {
|
||||
revert InvalidValsetNonce({
|
||||
newNonce: _newValset.valsetNonce,
|
||||
currentNonce: _currentValset.valsetNonce
|
||||
});
|
||||
}
|
||||
|
||||
// Check that new validators and powers set is well-formed
|
||||
require(_newValidators.length == _newPowers.length, "Malformed new validator set");
|
||||
if (
|
||||
_newValset.validators.length != _newValset.powers.length ||
|
||||
_newValset.validators.length == 0
|
||||
) {
|
||||
revert MalformedNewValidatorSet();
|
||||
}
|
||||
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
require(
|
||||
_currentValidators.length == _currentPowers.length &&
|
||||
_currentValidators.length == _v.length &&
|
||||
_currentValidators.length == _r.length &&
|
||||
_currentValidators.length == _s.length,
|
||||
"Malformed current validator set"
|
||||
);
|
||||
validateValset(_currentValset, _sigs);
|
||||
|
||||
// Check cumulative power to ensure the contract has sufficient power to actually
|
||||
// pass a vote
|
||||
uint256 cumulativePower = 0;
|
||||
for (uint256 i = 0; i < _newValset.powers.length; i++) {
|
||||
cumulativePower = cumulativePower + _newValset.powers[i];
|
||||
if (cumulativePower > constant_powerThreshold) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cumulativePower <= constant_powerThreshold) {
|
||||
revert InsufficientPower({
|
||||
cumulativePower: cumulativePower,
|
||||
powerThreshold: constant_powerThreshold
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the supplied current validator set matches the saved checkpoint
|
||||
require(
|
||||
makeCheckpoint(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_currentValsetNonce,
|
||||
state_gravityId
|
||||
) == state_lastValsetCheckpoint,
|
||||
"Supplied current validators and powers do not match checkpoint."
|
||||
);
|
||||
if (makeCheckpoint(_currentValset, state_gravityId) != state_lastValsetCheckpoint) {
|
||||
revert IncorrectCheckpoint();
|
||||
}
|
||||
|
||||
// Check that enough current validators have signed off on the new validator set
|
||||
bytes32 newCheckpoint =
|
||||
makeCheckpoint(_newValidators, _newPowers, _newValsetNonce, state_gravityId);
|
||||
bytes32 newCheckpoint = makeCheckpoint(_newValset, state_gravityId);
|
||||
|
||||
checkValidatorSignatures(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_v,
|
||||
_r,
|
||||
_s,
|
||||
newCheckpoint,
|
||||
state_powerThreshold
|
||||
);
|
||||
checkValidatorSignatures(_currentValset, _sigs, newCheckpoint, constant_powerThreshold);
|
||||
|
||||
// ACTIONS
|
||||
|
||||
@@ -273,83 +317,87 @@ contract Gravity is ReentrancyGuard {
|
||||
state_lastValsetCheckpoint = newCheckpoint;
|
||||
|
||||
// Store new nonce
|
||||
state_lastValsetNonce = _newValsetNonce;
|
||||
state_lastValsetNonce = _newValset.valsetNonce;
|
||||
|
||||
// Send submission reward to msg.sender if reward token is a valid value
|
||||
if (_newValset.rewardToken != address(0) && _newValset.rewardAmount != 0) {
|
||||
IERC20(_newValset.rewardToken).safeTransfer(msg.sender, _newValset.rewardAmount);
|
||||
}
|
||||
|
||||
// LOGS
|
||||
state_lastEventNonce = state_lastEventNonce.add(1);
|
||||
emit ValsetUpdatedEvent(_newValsetNonce, state_lastEventNonce, _newValidators, _newPowers);
|
||||
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit ValsetUpdatedEvent(
|
||||
_newValset.valsetNonce,
|
||||
state_lastEventNonce,
|
||||
_newValset.rewardAmount,
|
||||
_newValset.rewardToken,
|
||||
_newValset.validators,
|
||||
_newValset.powers
|
||||
);
|
||||
}
|
||||
|
||||
// submitBatch processes a batch of Cosmos -> Ethereum transactions by sending the tokens in the transactions
|
||||
// to the destination addresses. It is approved by the current Cosmos validator set.
|
||||
// Anyone can call this function, but they must supply valid signatures of state_powerThreshold of the current valset over
|
||||
// Anyone can call this function, but they must supply valid signatures of constant_powerThreshold of the current valset over
|
||||
// the batch.
|
||||
function submitBatch(
|
||||
// The validators that approve the batch
|
||||
address[] memory _currentValidators,
|
||||
uint256[] memory _currentPowers,
|
||||
uint256 _currentValsetNonce,
|
||||
ValsetArgs calldata _currentValset,
|
||||
// These are arrays of the parts of the validators signatures
|
||||
uint8[] memory _v,
|
||||
bytes32[] memory _r,
|
||||
bytes32[] memory _s,
|
||||
Signature[] calldata _sigs,
|
||||
// The batch of transactions
|
||||
uint256[] memory _amounts,
|
||||
address[] memory _destinations,
|
||||
uint256[] memory _fees,
|
||||
uint256[] calldata _amounts,
|
||||
address[] calldata _destinations,
|
||||
uint256[] calldata _fees,
|
||||
uint256 _batchNonce,
|
||||
address _tokenContract,
|
||||
// a block height beyond which this batch is not valid
|
||||
// used to provide a fee-free timeout
|
||||
uint256 _batchTimeout
|
||||
) public nonReentrant {
|
||||
) external nonReentrant {
|
||||
// CHECKS scoped to reduce stack depth
|
||||
{
|
||||
// Check that the batch nonce is higher than the last nonce for this token
|
||||
require(
|
||||
state_lastBatchNonces[_tokenContract] < _batchNonce,
|
||||
"New batch nonce must be greater than the current nonce"
|
||||
);
|
||||
if (_batchNonce <= state_lastBatchNonces[_tokenContract]) {
|
||||
revert InvalidBatchNonce({
|
||||
newNonce: _batchNonce,
|
||||
currentNonce: state_lastBatchNonces[_tokenContract]
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the batch nonce is less than one million nonces forward from the old one
|
||||
// this makes it difficult for an attacker to lock out the contract by getting a single
|
||||
// bad batch through with uint256 max nonce
|
||||
if (_batchNonce > state_lastBatchNonces[_tokenContract] + 1000000) {
|
||||
revert InvalidBatchNonce({
|
||||
newNonce: _batchNonce,
|
||||
currentNonce: state_lastBatchNonces[_tokenContract]
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the block height is less than the timeout height
|
||||
require(
|
||||
block.number < _batchTimeout,
|
||||
"Batch timeout must be greater than the current block height"
|
||||
);
|
||||
if (block.number >= _batchTimeout) {
|
||||
revert BatchTimedOut();
|
||||
}
|
||||
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
require(
|
||||
_currentValidators.length == _currentPowers.length &&
|
||||
_currentValidators.length == _v.length &&
|
||||
_currentValidators.length == _r.length &&
|
||||
_currentValidators.length == _s.length,
|
||||
"Malformed current validator set"
|
||||
);
|
||||
validateValset(_currentValset, _sigs);
|
||||
|
||||
// Check that the supplied current validator set matches the saved checkpoint
|
||||
require(
|
||||
makeCheckpoint(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_currentValsetNonce,
|
||||
state_gravityId
|
||||
) == state_lastValsetCheckpoint,
|
||||
"Supplied current validators and powers do not match checkpoint."
|
||||
);
|
||||
if (makeCheckpoint(_currentValset, state_gravityId) != state_lastValsetCheckpoint) {
|
||||
revert IncorrectCheckpoint();
|
||||
}
|
||||
|
||||
// Check that the transaction batch is well-formed
|
||||
require(
|
||||
_amounts.length == _destinations.length && _amounts.length == _fees.length,
|
||||
"Malformed batch of transactions"
|
||||
);
|
||||
if (_amounts.length != _destinations.length || _amounts.length != _fees.length) {
|
||||
revert MalformedBatch();
|
||||
}
|
||||
|
||||
// Check that enough current validators have signed off on the transaction batch and valset
|
||||
checkValidatorSignatures(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_v,
|
||||
_r,
|
||||
_s,
|
||||
_currentValset,
|
||||
_sigs,
|
||||
// Get hash of the transaction batch and checkpoint
|
||||
keccak256(
|
||||
abi.encode(
|
||||
@@ -364,7 +412,7 @@ contract Gravity is ReentrancyGuard {
|
||||
_batchTimeout
|
||||
)
|
||||
),
|
||||
state_powerThreshold
|
||||
constant_powerThreshold
|
||||
);
|
||||
|
||||
// ACTIONS
|
||||
@@ -377,7 +425,7 @@ contract Gravity is ReentrancyGuard {
|
||||
uint256 totalFee;
|
||||
for (uint256 i = 0; i < _amounts.length; i++) {
|
||||
IERC20(_tokenContract).safeTransfer(_destinations[i], _amounts[i]);
|
||||
totalFee = totalFee.add(_fees[i]);
|
||||
totalFee = totalFee + _fees[i];
|
||||
}
|
||||
|
||||
// Send transaction fees to msg.sender
|
||||
@@ -387,7 +435,7 @@ contract Gravity is ReentrancyGuard {
|
||||
|
||||
// LOGS scoped to reduce stack depth
|
||||
{
|
||||
state_lastEventNonce = state_lastEventNonce.add(1);
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit TransactionBatchExecutedEvent(_batchNonce, _tokenContract, state_lastEventNonce);
|
||||
}
|
||||
}
|
||||
@@ -403,61 +451,48 @@ contract Gravity is ReentrancyGuard {
|
||||
// for each call.
|
||||
function submitLogicCall(
|
||||
// The validators that approve the call
|
||||
address[] memory _currentValidators,
|
||||
uint256[] memory _currentPowers,
|
||||
uint256 _currentValsetNonce,
|
||||
ValsetArgs calldata _currentValset,
|
||||
// These are arrays of the parts of the validators signatures
|
||||
uint8[] memory _v,
|
||||
bytes32[] memory _r,
|
||||
bytes32[] memory _s,
|
||||
Signature[] calldata _sigs,
|
||||
LogicCallArgs memory _args
|
||||
) public nonReentrant {
|
||||
) external nonReentrant {
|
||||
// CHECKS scoped to reduce stack depth
|
||||
{
|
||||
// Check that the call has not timed out
|
||||
require(block.number < _args.timeOut, "Timed out");
|
||||
if (block.number >= _args.timeOut) {
|
||||
revert LogicCallTimedOut();
|
||||
}
|
||||
|
||||
// Check that the invalidation nonce is higher than the last nonce for this invalidation Id
|
||||
require(
|
||||
state_invalidationMapping[_args.invalidationId] < _args.invalidationNonce,
|
||||
"New invalidation nonce must be greater than the current nonce"
|
||||
);
|
||||
if (state_invalidationMapping[_args.invalidationId] >= _args.invalidationNonce) {
|
||||
revert InvalidLogicCallNonce({
|
||||
newNonce: _args.invalidationNonce,
|
||||
currentNonce: state_invalidationMapping[_args.invalidationId]
|
||||
});
|
||||
}
|
||||
|
||||
// note the lack of nonce skipping check, it's not needed here since an attacker
|
||||
// will never be able to fill the invalidationId space, therefore a nonce lockout
|
||||
// is simply not possible
|
||||
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
require(
|
||||
_currentValidators.length == _currentPowers.length &&
|
||||
_currentValidators.length == _v.length &&
|
||||
_currentValidators.length == _r.length &&
|
||||
_currentValidators.length == _s.length,
|
||||
"Malformed current validator set"
|
||||
);
|
||||
validateValset(_currentValset, _sigs);
|
||||
|
||||
// Check that the supplied current validator set matches the saved checkpoint
|
||||
require(
|
||||
makeCheckpoint(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_currentValsetNonce,
|
||||
state_gravityId
|
||||
) == state_lastValsetCheckpoint,
|
||||
"Supplied current validators and powers do not match checkpoint."
|
||||
);
|
||||
if (makeCheckpoint(_currentValset, state_gravityId) != state_lastValsetCheckpoint) {
|
||||
revert IncorrectCheckpoint();
|
||||
}
|
||||
|
||||
// Check that the token transfer list is well-formed
|
||||
require(
|
||||
_args.transferAmounts.length == _args.transferTokenContracts.length,
|
||||
"Malformed list of token transfers"
|
||||
);
|
||||
if (_args.transferAmounts.length != _args.transferTokenContracts.length) {
|
||||
revert InvalidLogicCallTransfers();
|
||||
}
|
||||
|
||||
// Check that the fee list is well-formed
|
||||
require(
|
||||
_args.feeAmounts.length == _args.feeTokenContracts.length,
|
||||
"Malformed list of fees"
|
||||
);
|
||||
if (_args.feeAmounts.length != _args.feeTokenContracts.length) {
|
||||
revert InvalidLogicCallFees();
|
||||
}
|
||||
}
|
||||
|
||||
bytes32 argsHash =
|
||||
keccak256(
|
||||
{
|
||||
bytes32 argsHash = keccak256(
|
||||
abi.encode(
|
||||
state_gravityId,
|
||||
// bytes32 encoding of "logicCall"
|
||||
@@ -474,17 +509,13 @@ contract Gravity is ReentrancyGuard {
|
||||
)
|
||||
);
|
||||
|
||||
{
|
||||
// Check that enough current validators have signed off on the transaction batch and valset
|
||||
checkValidatorSignatures(
|
||||
_currentValidators,
|
||||
_currentPowers,
|
||||
_v,
|
||||
_r,
|
||||
_s,
|
||||
_currentValset,
|
||||
_sigs,
|
||||
// Get hash of the transaction batch and checkpoint
|
||||
argsHash,
|
||||
state_powerThreshold
|
||||
constant_powerThreshold
|
||||
);
|
||||
}
|
||||
|
||||
@@ -511,7 +542,7 @@ contract Gravity is ReentrancyGuard {
|
||||
|
||||
// LOGS scoped to reduce stack depth
|
||||
{
|
||||
state_lastEventNonce = state_lastEventNonce.add(1);
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit LogicCallEvent(
|
||||
_args.invalidationId,
|
||||
_args.invalidationNonce,
|
||||
@@ -523,31 +554,50 @@ contract Gravity is ReentrancyGuard {
|
||||
|
||||
function sendToCosmos(
|
||||
address _tokenContract,
|
||||
bytes32 _destination,
|
||||
string calldata _destination,
|
||||
uint256 _amount
|
||||
) public nonReentrant {
|
||||
) external nonReentrant {
|
||||
// we snapshot our current balance of this token
|
||||
uint256 ourStartingBalance = IERC20(_tokenContract).balanceOf(address(this));
|
||||
|
||||
// attempt to transfer the user specified amount
|
||||
IERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);
|
||||
state_lastEventNonce = state_lastEventNonce.add(1);
|
||||
|
||||
// check what this particular ERC20 implementation actually gave us, since it doesn't
|
||||
// have to be at all related to the _amount
|
||||
uint256 ourEndingBalance = IERC20(_tokenContract).balanceOf(address(this));
|
||||
|
||||
// a very strange ERC20 may trigger this condition, if we didn't have this we would
|
||||
// underflow, so it's mostly just an error message printer
|
||||
if (ourEndingBalance <= ourStartingBalance) {
|
||||
revert InvalidSendToCosmos();
|
||||
}
|
||||
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
|
||||
// emit to Cosmos the actual amount our balance has changed, rather than the user
|
||||
// provided amount. This protects against a small set of wonky ERC20 behavior, like
|
||||
// burning on send but not tokens that for example change every users balance every day.
|
||||
emit SendToCosmosEvent(
|
||||
_tokenContract,
|
||||
msg.sender,
|
||||
_destination,
|
||||
_amount,
|
||||
ourEndingBalance - ourStartingBalance,
|
||||
state_lastEventNonce
|
||||
);
|
||||
}
|
||||
|
||||
function deployERC20(
|
||||
string memory _cosmosDenom,
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
string calldata _cosmosDenom,
|
||||
string calldata _name,
|
||||
string calldata _symbol,
|
||||
uint8 _decimals
|
||||
) public {
|
||||
) external {
|
||||
// Deploy an ERC20 with entire supply granted to Gravity.sol
|
||||
CosmosERC20 erc20 = new CosmosERC20(address(this), _name, _symbol, _decimals);
|
||||
|
||||
// Fire an event to let the Cosmos module know
|
||||
state_lastEventNonce = state_lastEventNonce.add(1);
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit ERC20DeployedEvent(
|
||||
_cosmosDenom,
|
||||
address(erc20),
|
||||
@@ -561,41 +611,53 @@ contract Gravity is ReentrancyGuard {
|
||||
constructor(
|
||||
// A unique identifier for this gravity instance to use in signatures
|
||||
bytes32 _gravityId,
|
||||
// How much voting power is needed to approve operations
|
||||
uint256 _powerThreshold,
|
||||
// The validator set
|
||||
// The validator set, not in valset args format since many of it's
|
||||
// arguments would never be used in this case
|
||||
address[] memory _validators,
|
||||
uint256[] memory _powers
|
||||
) public {
|
||||
) {
|
||||
// CHECKS
|
||||
|
||||
// Check that validators, powers, and signatures (v,r,s) set is well-formed
|
||||
require(_validators.length == _powers.length, "Malformed current validator set");
|
||||
if (_validators.length != _powers.length || _validators.length == 0) {
|
||||
revert MalformedCurrentValidatorSet();
|
||||
}
|
||||
|
||||
// Check cumulative power to ensure the contract has sufficient power to actually
|
||||
// pass a vote
|
||||
uint256 cumulativePower = 0;
|
||||
for (uint256 i = 0; i < _powers.length; i++) {
|
||||
cumulativePower = cumulativePower + _powers[i];
|
||||
if (cumulativePower > _powerThreshold) {
|
||||
if (cumulativePower > constant_powerThreshold) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
require(
|
||||
cumulativePower > _powerThreshold,
|
||||
"Submitted validator set signatures do not have enough power."
|
||||
);
|
||||
if (cumulativePower <= constant_powerThreshold) {
|
||||
revert InsufficientPower({
|
||||
cumulativePower: cumulativePower,
|
||||
powerThreshold: constant_powerThreshold
|
||||
});
|
||||
}
|
||||
|
||||
bytes32 newCheckpoint = makeCheckpoint(_validators, _powers, 0, _gravityId);
|
||||
ValsetArgs memory _valset;
|
||||
_valset = ValsetArgs(_validators, _powers, 0, 0, address(0));
|
||||
|
||||
bytes32 newCheckpoint = makeCheckpoint(_valset, _gravityId);
|
||||
|
||||
// ACTIONS
|
||||
|
||||
state_gravityId = _gravityId;
|
||||
state_powerThreshold = _powerThreshold;
|
||||
state_lastValsetCheckpoint = newCheckpoint;
|
||||
|
||||
// LOGS
|
||||
|
||||
emit ValsetUpdatedEvent(state_lastValsetNonce, state_lastEventNonce, _validators, _powers);
|
||||
emit ValsetUpdatedEvent(
|
||||
state_lastValsetNonce,
|
||||
state_lastEventNonce,
|
||||
0,
|
||||
address(0),
|
||||
_validators,
|
||||
_powers
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
//SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity 0.8.10;
|
||||
import "@openzeppelin/contracts/token/ERC20/ERC20.sol";
|
||||
|
||||
/**
|
||||
* This is a slightly modified version of the cosmos erc20 contract
|
||||
* which I have done for unit testing.
|
||||
*
|
||||
* All that has been changed is the MAX_UINT variable to allow
|
||||
* me to mint some tokens more easily in unit tests, and the
|
||||
* addition of the public mint() function.
|
||||
*/
|
||||
|
||||
|
||||
contract TestCosmosERC20 is ERC20 {
|
||||
/* canonical amount */
|
||||
// uint256 MAX_UINT = 2**256 - 1;
|
||||
|
||||
/* unit testing amount */
|
||||
uint256 HALF_MAX_UINT = 2**256 / 2;
|
||||
|
||||
uint8 private cosmosDecimals;
|
||||
address private gravityAddress;
|
||||
|
||||
// This override ensures we return the proper number of decimals
|
||||
// for the cosmos token
|
||||
function decimals() public view virtual override returns (uint8) {
|
||||
return cosmosDecimals;
|
||||
}
|
||||
|
||||
// This is not an accurate total supply. Instead this is the total supply
|
||||
// of the given cosmos asset on Ethereum at this moment in time. Keeping
|
||||
// a totally accurate supply would require constant updates from the Cosmos
|
||||
// side, while in theory this could be piggy-backed on some existing bridge
|
||||
// operation it's a lot of complextiy to add so we chose to forgoe it.
|
||||
function totalSupply() public view virtual override returns (uint256) {
|
||||
return HALF_MAX_UINT - balanceOf(gravityAddress);
|
||||
}
|
||||
|
||||
constructor(
|
||||
address _gravityAddress,
|
||||
string memory _name,
|
||||
string memory _symbol,
|
||||
uint8 _decimals
|
||||
) ERC20(_name, _symbol) {
|
||||
cosmosDecimals = _decimals;
|
||||
gravityAddress = _gravityAddress;
|
||||
_mint(_gravityAddress, HALF_MAX_UINT);
|
||||
}
|
||||
|
||||
// Additional function for our (nym repo) unit tests with bridge
|
||||
function mintForUnitTesting(address _to, uint _amount) public {
|
||||
_mint(_to, _amount);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,671 @@
|
||||
//SPDX-License-Identifier: Apache-2.0
|
||||
pragma solidity 0.8.10;
|
||||
|
||||
import "@openzeppelin/contracts/token/ERC20/IERC20.sol";
|
||||
import "@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol";
|
||||
import "@openzeppelin/contracts/security/ReentrancyGuard.sol";
|
||||
import "@openzeppelin/contracts/utils/Address.sol";
|
||||
import "@openzeppelin/contracts/utils/cryptography/ECDSA.sol";
|
||||
import "./TestCosmosToken.sol";
|
||||
|
||||
/**
|
||||
* This is a slightly modified version of the gravity bridge contract
|
||||
* which I have done for unit testing.
|
||||
*
|
||||
* All that has been changed is ___
|
||||
*/
|
||||
|
||||
error InvalidSignature();
|
||||
error InvalidValsetNonce(uint256 newNonce, uint256 currentNonce);
|
||||
error InvalidBatchNonce(uint256 newNonce, uint256 currentNonce);
|
||||
error InvalidLogicCallNonce(uint256 newNonce, uint256 currentNonce);
|
||||
error InvalidLogicCallTransfers();
|
||||
error InvalidLogicCallFees();
|
||||
error InvalidSendToCosmos();
|
||||
error IncorrectCheckpoint();
|
||||
error MalformedNewValidatorSet();
|
||||
error MalformedCurrentValidatorSet();
|
||||
error MalformedBatch();
|
||||
error InsufficientPower(uint256 cumulativePower, uint256 powerThreshold);
|
||||
error BatchTimedOut();
|
||||
error LogicCallTimedOut();
|
||||
|
||||
// This is being used purely to avoid stack too deep errors
|
||||
struct LogicCallArgs {
|
||||
// Transfers out to the logic contract
|
||||
uint256[] transferAmounts;
|
||||
address[] transferTokenContracts;
|
||||
// The fees (transferred to msg.sender)
|
||||
uint256[] feeAmounts;
|
||||
address[] feeTokenContracts;
|
||||
// The arbitrary logic call
|
||||
address logicContractAddress;
|
||||
bytes payload;
|
||||
// Invalidation metadata
|
||||
uint256 timeOut;
|
||||
bytes32 invalidationId;
|
||||
uint256 invalidationNonce;
|
||||
}
|
||||
|
||||
// This is used purely to avoid stack too deep errors
|
||||
// represents everything about a given validator set
|
||||
struct ValsetArgs {
|
||||
// the validators in this set, represented by an Ethereum address
|
||||
address[] validators;
|
||||
// the powers of the given validators in the same order as above
|
||||
uint256[] powers;
|
||||
// the nonce of this validator set
|
||||
uint256 valsetNonce;
|
||||
// the reward amount denominated in the below reward token, can be
|
||||
// set to zero
|
||||
uint256 rewardAmount;
|
||||
// the reward token, should be set to the zero address if not being used
|
||||
address rewardToken;
|
||||
}
|
||||
|
||||
// This represents a validator signature
|
||||
struct Signature {
|
||||
uint8 v;
|
||||
bytes32 r;
|
||||
bytes32 s;
|
||||
}
|
||||
|
||||
contract Gravity is ReentrancyGuard {
|
||||
using SafeERC20 for IERC20;
|
||||
|
||||
// The number of 'votes' required to execute a valset
|
||||
// update or batch execution, set to 2/3 of 2^32
|
||||
uint256 constant constant_powerThreshold = 2863311530;
|
||||
|
||||
// These are updated often
|
||||
bytes32 public state_lastValsetCheckpoint;
|
||||
mapping(address => uint256) public state_lastBatchNonces;
|
||||
mapping(bytes32 => uint256) public state_invalidationMapping;
|
||||
uint256 public state_lastValsetNonce = 0;
|
||||
// event nonce zero is reserved by the Cosmos module as a special
|
||||
// value indicating that no events have yet been submitted
|
||||
uint256 public state_lastEventNonce = 1;
|
||||
|
||||
// This is set once at initialization
|
||||
bytes32 public immutable state_gravityId;
|
||||
|
||||
// TransactionBatchExecutedEvent and SendToCosmosEvent both include the field _eventNonce.
|
||||
// This is incremented every time one of these events is emitted. It is checked by the
|
||||
// Cosmos module to ensure that all events are received in order, and that none are lost.
|
||||
//
|
||||
// ValsetUpdatedEvent does not include the field _eventNonce because it is never submitted to the Cosmos
|
||||
// module. It is purely for the use of relayers to allow them to successfully submit batches.
|
||||
event TransactionBatchExecutedEvent(
|
||||
uint256 indexed _batchNonce,
|
||||
address indexed _token,
|
||||
uint256 _eventNonce
|
||||
);
|
||||
event SendToCosmosEvent(
|
||||
address indexed _tokenContract,
|
||||
address indexed _sender,
|
||||
string _destination,
|
||||
uint256 _amount,
|
||||
uint256 _eventNonce
|
||||
);
|
||||
event ERC20DeployedEvent(
|
||||
// FYI: Can't index on a string without doing a bunch of weird stuff
|
||||
string _cosmosDenom,
|
||||
address indexed _tokenContract,
|
||||
string _name,
|
||||
string _symbol,
|
||||
uint8 _decimals,
|
||||
uint256 _eventNonce
|
||||
);
|
||||
event ValsetUpdatedEvent(
|
||||
uint256 indexed _newValsetNonce,
|
||||
uint256 _eventNonce,
|
||||
uint256 _rewardAmount,
|
||||
address _rewardToken,
|
||||
address[] _validators,
|
||||
uint256[] _powers
|
||||
);
|
||||
event LogicCallEvent(
|
||||
bytes32 _invalidationId,
|
||||
uint256 _invalidationNonce,
|
||||
bytes _returnData,
|
||||
uint256 _eventNonce
|
||||
);
|
||||
|
||||
// TEST FIXTURES
|
||||
// These are here to make it easier to measure gas usage. They should be removed before production
|
||||
function testMakeCheckpoint(ValsetArgs calldata _valsetArgs, bytes32 _gravityId) external pure {
|
||||
makeCheckpoint(_valsetArgs, _gravityId);
|
||||
}
|
||||
|
||||
function testCheckValidatorSignatures(
|
||||
ValsetArgs calldata _currentValset,
|
||||
Signature[] calldata _sigs,
|
||||
bytes32 _theHash,
|
||||
uint256 _powerThreshold
|
||||
) external pure {
|
||||
checkValidatorSignatures(_currentValset, _sigs, _theHash, _powerThreshold);
|
||||
}
|
||||
|
||||
// END TEST FIXTURES
|
||||
|
||||
function lastBatchNonce(address _erc20Address) external view returns (uint256) {
|
||||
return state_lastBatchNonces[_erc20Address];
|
||||
}
|
||||
|
||||
function lastLogicCallNonce(bytes32 _invalidation_id) external view returns (uint256) {
|
||||
return state_invalidationMapping[_invalidation_id];
|
||||
}
|
||||
|
||||
// Utility function to verify geth style signatures
|
||||
function verifySig(
|
||||
address _signer,
|
||||
bytes32 _theHash,
|
||||
Signature calldata _sig
|
||||
) private pure returns (bool) {
|
||||
bytes32 messageDigest = keccak256(
|
||||
abi.encodePacked("\x19Ethereum Signed Message:\n32", _theHash)
|
||||
);
|
||||
return _signer == ECDSA.recover(messageDigest, _sig.v, _sig.r, _sig.s);
|
||||
}
|
||||
|
||||
// Utility function to determine that a validator set and signatures are well formed
|
||||
function validateValset(ValsetArgs calldata _valset, Signature[] calldata _sigs) private pure {
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
if (
|
||||
_valset.validators.length != _valset.powers.length ||
|
||||
_valset.validators.length != _sigs.length
|
||||
) {
|
||||
revert MalformedCurrentValidatorSet();
|
||||
}
|
||||
}
|
||||
|
||||
// Make a new checkpoint from the supplied validator set
|
||||
// A checkpoint is a hash of all relevant information about the valset. This is stored by the contract,
|
||||
// instead of storing the information directly. This saves on storage and gas.
|
||||
// The format of the checkpoint is:
|
||||
// h(gravityId, "checkpoint", valsetNonce, validators[], powers[])
|
||||
// Where h is the keccak256 hash function.
|
||||
// The validator powers must be decreasing or equal. This is important for checking the signatures on the
|
||||
// next valset, since it allows the caller to stop verifying signatures once a quorum of signatures have been verified.
|
||||
function makeCheckpoint(ValsetArgs memory _valsetArgs, bytes32 _gravityId)
|
||||
private
|
||||
pure
|
||||
returns (bytes32)
|
||||
{
|
||||
// bytes32 encoding of the string "checkpoint"
|
||||
bytes32 methodName = 0x636865636b706f696e7400000000000000000000000000000000000000000000;
|
||||
|
||||
bytes32 checkpoint = keccak256(
|
||||
abi.encode(
|
||||
_gravityId,
|
||||
methodName,
|
||||
_valsetArgs.valsetNonce,
|
||||
_valsetArgs.validators,
|
||||
_valsetArgs.powers,
|
||||
_valsetArgs.rewardAmount,
|
||||
_valsetArgs.rewardToken
|
||||
)
|
||||
);
|
||||
|
||||
return checkpoint;
|
||||
}
|
||||
|
||||
function checkValidatorSignatures(
|
||||
// The current validator set and their powers
|
||||
ValsetArgs calldata _currentValset,
|
||||
// The current validator's signatures
|
||||
Signature[] calldata _sigs,
|
||||
// This is what we are checking they have signed
|
||||
bytes32 _theHash,
|
||||
uint256 _powerThreshold
|
||||
) private pure {
|
||||
uint256 cumulativePower = 0;
|
||||
|
||||
for (uint256 i = 0; i < _currentValset.validators.length; i++) {
|
||||
// If v is set to 0, this signifies that it was not possible to get a signature from this validator and we skip evaluation
|
||||
// (In a valid signature, it is either 27 or 28)
|
||||
if (_sigs[i].v != 0) {
|
||||
// Check that the current validator has signed off on the hash
|
||||
if (!verifySig(_currentValset.validators[i], _theHash, _sigs[i])) {
|
||||
revert InvalidSignature();
|
||||
}
|
||||
|
||||
// Sum up cumulative power
|
||||
cumulativePower = cumulativePower + _currentValset.powers[i];
|
||||
|
||||
// Break early to avoid wasting gas
|
||||
if (cumulativePower > _powerThreshold) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Check that there was enough power
|
||||
if (cumulativePower <= _powerThreshold) {
|
||||
revert InsufficientPower(cumulativePower, _powerThreshold);
|
||||
}
|
||||
// Success
|
||||
}
|
||||
|
||||
// This updates the valset by checking that the validators in the current valset have signed off on the
|
||||
// new valset. The signatures supplied are the signatures of the current valset over the checkpoint hash
|
||||
// generated from the new valset.
|
||||
// Anyone can call this function, but they must supply valid signatures of constant_powerThreshold of the current valset over
|
||||
// the new valset.
|
||||
function updateValset(
|
||||
// The new version of the validator set
|
||||
ValsetArgs calldata _newValset,
|
||||
// The current validators that approve the change
|
||||
ValsetArgs calldata _currentValset,
|
||||
// These are arrays of the parts of the current validator's signatures
|
||||
Signature[] calldata _sigs
|
||||
) external {
|
||||
// CHECKS
|
||||
|
||||
// Check that the valset nonce is greater than the old one
|
||||
if (_newValset.valsetNonce <= _currentValset.valsetNonce) {
|
||||
revert InvalidValsetNonce({
|
||||
newNonce: _newValset.valsetNonce,
|
||||
currentNonce: _currentValset.valsetNonce
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the valset nonce is less than a million nonces forward from the old one
|
||||
// this makes it difficult for an attacker to lock out the contract by getting a single
|
||||
// bad validator set through with uint256 max nonce
|
||||
if (_newValset.valsetNonce > _currentValset.valsetNonce + 1000000) {
|
||||
revert InvalidValsetNonce({
|
||||
newNonce: _newValset.valsetNonce,
|
||||
currentNonce: _currentValset.valsetNonce
|
||||
});
|
||||
}
|
||||
|
||||
// Check that new validators and powers set is well-formed
|
||||
if (
|
||||
_newValset.validators.length != _newValset.powers.length ||
|
||||
_newValset.validators.length == 0
|
||||
) {
|
||||
revert MalformedNewValidatorSet();
|
||||
}
|
||||
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
validateValset(_currentValset, _sigs);
|
||||
|
||||
// Check cumulative power to ensure the contract has sufficient power to actually
|
||||
// pass a vote
|
||||
uint256 cumulativePower = 0;
|
||||
for (uint256 i = 0; i < _newValset.powers.length; i++) {
|
||||
cumulativePower = cumulativePower + _newValset.powers[i];
|
||||
if (cumulativePower > constant_powerThreshold) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cumulativePower <= constant_powerThreshold) {
|
||||
revert InsufficientPower({
|
||||
cumulativePower: cumulativePower,
|
||||
powerThreshold: constant_powerThreshold
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the supplied current validator set matches the saved checkpoint
|
||||
if (makeCheckpoint(_currentValset, state_gravityId) != state_lastValsetCheckpoint) {
|
||||
revert IncorrectCheckpoint();
|
||||
}
|
||||
|
||||
// Check that enough current validators have signed off on the new validator set
|
||||
bytes32 newCheckpoint = makeCheckpoint(_newValset, state_gravityId);
|
||||
|
||||
checkValidatorSignatures(_currentValset, _sigs, newCheckpoint, constant_powerThreshold);
|
||||
|
||||
// ACTIONS
|
||||
|
||||
// Stored to be used next time to validate that the valset
|
||||
// supplied by the caller is correct.
|
||||
state_lastValsetCheckpoint = newCheckpoint;
|
||||
|
||||
// Store new nonce
|
||||
state_lastValsetNonce = _newValset.valsetNonce;
|
||||
|
||||
// Send submission reward to msg.sender if reward token is a valid value
|
||||
if (_newValset.rewardToken != address(0) && _newValset.rewardAmount != 0) {
|
||||
IERC20(_newValset.rewardToken).safeTransfer(msg.sender, _newValset.rewardAmount);
|
||||
}
|
||||
|
||||
// LOGS
|
||||
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit ValsetUpdatedEvent(
|
||||
_newValset.valsetNonce,
|
||||
state_lastEventNonce,
|
||||
_newValset.rewardAmount,
|
||||
_newValset.rewardToken,
|
||||
_newValset.validators,
|
||||
_newValset.powers
|
||||
);
|
||||
}
|
||||
|
||||
// submitBatch processes a batch of Cosmos -> Ethereum transactions by sending the tokens in the transactions
|
||||
// to the destination addresses. It is approved by the current Cosmos validator set.
|
||||
// Anyone can call this function, but they must supply valid signatures of constant_powerThreshold of the current valset over
|
||||
// the batch.
|
||||
function submitBatch(
|
||||
// The validators that approve the batch
|
||||
ValsetArgs calldata _currentValset,
|
||||
// These are arrays of the parts of the validators signatures
|
||||
Signature[] calldata _sigs,
|
||||
// The batch of transactions
|
||||
uint256[] calldata _amounts,
|
||||
address[] calldata _destinations,
|
||||
uint256[] calldata _fees,
|
||||
uint256 _batchNonce,
|
||||
address _tokenContract,
|
||||
// a block height beyond which this batch is not valid
|
||||
// used to provide a fee-free timeout
|
||||
uint256 _batchTimeout
|
||||
) external nonReentrant {
|
||||
// CHECKS scoped to reduce stack depth
|
||||
{
|
||||
// Check that the batch nonce is higher than the last nonce for this token
|
||||
if (_batchNonce <= state_lastBatchNonces[_tokenContract]) {
|
||||
revert InvalidBatchNonce({
|
||||
newNonce: _batchNonce,
|
||||
currentNonce: state_lastBatchNonces[_tokenContract]
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the batch nonce is less than one million nonces forward from the old one
|
||||
// this makes it difficult for an attacker to lock out the contract by getting a single
|
||||
// bad batch through with uint256 max nonce
|
||||
if (_batchNonce > state_lastBatchNonces[_tokenContract] + 1000000) {
|
||||
revert InvalidBatchNonce({
|
||||
newNonce: _batchNonce,
|
||||
currentNonce: state_lastBatchNonces[_tokenContract]
|
||||
});
|
||||
}
|
||||
|
||||
// Check that the block height is less than the timeout height
|
||||
if (block.number >= _batchTimeout) {
|
||||
revert BatchTimedOut();
|
||||
}
|
||||
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
validateValset(_currentValset, _sigs);
|
||||
|
||||
// Check that the supplied current validator set matches the saved checkpoint
|
||||
if (makeCheckpoint(_currentValset, state_gravityId) != state_lastValsetCheckpoint) {
|
||||
revert IncorrectCheckpoint();
|
||||
}
|
||||
|
||||
// Check that the transaction batch is well-formed
|
||||
if (_amounts.length != _destinations.length || _amounts.length != _fees.length) {
|
||||
revert MalformedBatch();
|
||||
}
|
||||
|
||||
// Check that enough current validators have signed off on the transaction batch and valset
|
||||
checkValidatorSignatures(
|
||||
_currentValset,
|
||||
_sigs,
|
||||
// Get hash of the transaction batch and checkpoint
|
||||
keccak256(
|
||||
abi.encode(
|
||||
state_gravityId,
|
||||
// bytes32 encoding of "transactionBatch"
|
||||
0x7472616e73616374696f6e426174636800000000000000000000000000000000,
|
||||
_amounts,
|
||||
_destinations,
|
||||
_fees,
|
||||
_batchNonce,
|
||||
_tokenContract,
|
||||
_batchTimeout
|
||||
)
|
||||
),
|
||||
constant_powerThreshold
|
||||
);
|
||||
|
||||
// ACTIONS
|
||||
|
||||
// Store batch nonce
|
||||
state_lastBatchNonces[_tokenContract] = _batchNonce;
|
||||
|
||||
{
|
||||
// Send transaction amounts to destinations
|
||||
uint256 totalFee;
|
||||
for (uint256 i = 0; i < _amounts.length; i++) {
|
||||
IERC20(_tokenContract).safeTransfer(_destinations[i], _amounts[i]);
|
||||
totalFee = totalFee + _fees[i];
|
||||
}
|
||||
|
||||
// Send transaction fees to msg.sender
|
||||
IERC20(_tokenContract).safeTransfer(msg.sender, totalFee);
|
||||
}
|
||||
}
|
||||
|
||||
// LOGS scoped to reduce stack depth
|
||||
{
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit TransactionBatchExecutedEvent(_batchNonce, _tokenContract, state_lastEventNonce);
|
||||
}
|
||||
}
|
||||
|
||||
// This makes calls to contracts that execute arbitrary logic
|
||||
// First, it gives the logic contract some tokens
|
||||
// Then, it gives msg.senders tokens for fees
|
||||
// Then, it calls an arbitrary function on the logic contract
|
||||
// invalidationId and invalidationNonce are used for replay prevention.
|
||||
// They can be used to implement a per-token nonce by setting the token
|
||||
// address as the invalidationId and incrementing the nonce each call.
|
||||
// They can be used for nonce-free replay prevention by using a different invalidationId
|
||||
// for each call.
|
||||
function submitLogicCall(
|
||||
// The validators that approve the call
|
||||
ValsetArgs calldata _currentValset,
|
||||
// These are arrays of the parts of the validators signatures
|
||||
Signature[] calldata _sigs,
|
||||
LogicCallArgs memory _args
|
||||
) external nonReentrant {
|
||||
// CHECKS scoped to reduce stack depth
|
||||
{
|
||||
// Check that the call has not timed out
|
||||
if (block.number >= _args.timeOut) {
|
||||
revert LogicCallTimedOut();
|
||||
}
|
||||
|
||||
// Check that the invalidation nonce is higher than the last nonce for this invalidation Id
|
||||
if (state_invalidationMapping[_args.invalidationId] >= _args.invalidationNonce) {
|
||||
revert InvalidLogicCallNonce({
|
||||
newNonce: _args.invalidationNonce,
|
||||
currentNonce: state_invalidationMapping[_args.invalidationId]
|
||||
});
|
||||
}
|
||||
|
||||
// note the lack of nonce skipping check, it's not needed here since an attacker
|
||||
// will never be able to fill the invalidationId space, therefore a nonce lockout
|
||||
// is simply not possible
|
||||
|
||||
// Check that current validators, powers, and signatures (v,r,s) set is well-formed
|
||||
validateValset(_currentValset, _sigs);
|
||||
|
||||
// Check that the supplied current validator set matches the saved checkpoint
|
||||
if (makeCheckpoint(_currentValset, state_gravityId) != state_lastValsetCheckpoint) {
|
||||
revert IncorrectCheckpoint();
|
||||
}
|
||||
|
||||
if (_args.transferAmounts.length != _args.transferTokenContracts.length) {
|
||||
revert InvalidLogicCallTransfers();
|
||||
}
|
||||
|
||||
if (_args.feeAmounts.length != _args.feeTokenContracts.length) {
|
||||
revert InvalidLogicCallFees();
|
||||
}
|
||||
}
|
||||
{
|
||||
bytes32 argsHash = keccak256(
|
||||
abi.encode(
|
||||
state_gravityId,
|
||||
// bytes32 encoding of "logicCall"
|
||||
0x6c6f67696343616c6c0000000000000000000000000000000000000000000000,
|
||||
_args.transferAmounts,
|
||||
_args.transferTokenContracts,
|
||||
_args.feeAmounts,
|
||||
_args.feeTokenContracts,
|
||||
_args.logicContractAddress,
|
||||
_args.payload,
|
||||
_args.timeOut,
|
||||
_args.invalidationId,
|
||||
_args.invalidationNonce
|
||||
)
|
||||
);
|
||||
|
||||
// Check that enough current validators have signed off on the transaction batch and valset
|
||||
checkValidatorSignatures(
|
||||
_currentValset,
|
||||
_sigs,
|
||||
// Get hash of the transaction batch and checkpoint
|
||||
argsHash,
|
||||
constant_powerThreshold
|
||||
);
|
||||
}
|
||||
|
||||
// ACTIONS
|
||||
|
||||
// Update invaldiation nonce
|
||||
state_invalidationMapping[_args.invalidationId] = _args.invalidationNonce;
|
||||
|
||||
// Send tokens to the logic contract
|
||||
for (uint256 i = 0; i < _args.transferAmounts.length; i++) {
|
||||
IERC20(_args.transferTokenContracts[i]).safeTransfer(
|
||||
_args.logicContractAddress,
|
||||
_args.transferAmounts[i]
|
||||
);
|
||||
}
|
||||
|
||||
// Make call to logic contract
|
||||
bytes memory returnData = Address.functionCall(_args.logicContractAddress, _args.payload);
|
||||
|
||||
// Send fees to msg.sender
|
||||
for (uint256 i = 0; i < _args.feeAmounts.length; i++) {
|
||||
IERC20(_args.feeTokenContracts[i]).safeTransfer(msg.sender, _args.feeAmounts[i]);
|
||||
}
|
||||
|
||||
// LOGS scoped to reduce stack depth
|
||||
{
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit LogicCallEvent(
|
||||
_args.invalidationId,
|
||||
_args.invalidationNonce,
|
||||
returnData,
|
||||
state_lastEventNonce
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
function sendToCosmos(
|
||||
address _tokenContract,
|
||||
string calldata _destination,
|
||||
uint256 _amount
|
||||
) external nonReentrant {
|
||||
// we snapshot our current balance of this token
|
||||
uint256 ourStartingBalance = IERC20(_tokenContract).balanceOf(address(this));
|
||||
|
||||
// attempt to transfer the user specified amount
|
||||
IERC20(_tokenContract).safeTransferFrom(msg.sender, address(this), _amount);
|
||||
|
||||
// check what this particular ERC20 implementation actually gave us, since it doesn't
|
||||
// have to be at all related to the _amount
|
||||
uint256 ourEndingBalance = IERC20(_tokenContract).balanceOf(address(this));
|
||||
|
||||
// a very strange ERC20 may trigger this condition, if we didn't have this we would
|
||||
// underflow, so it's mostly just an error message printer
|
||||
if (ourEndingBalance <= ourStartingBalance) {
|
||||
revert InvalidSendToCosmos();
|
||||
}
|
||||
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
|
||||
// emit to Cosmos the actual amount our balance has changed, rather than the user
|
||||
// provided amount. This protects against a small set of wonky ERC20 behavior, like
|
||||
// burning on send but not tokens that for example change every users balance every day.
|
||||
emit SendToCosmosEvent(
|
||||
_tokenContract,
|
||||
msg.sender,
|
||||
_destination,
|
||||
ourEndingBalance - ourStartingBalance,
|
||||
state_lastEventNonce
|
||||
);
|
||||
}
|
||||
|
||||
function deployERC20(
|
||||
string calldata _cosmosDenom,
|
||||
string calldata _name,
|
||||
string calldata _symbol,
|
||||
uint8 _decimals
|
||||
) external {
|
||||
// NOTE this is an edit made for the nym codebase unit tests - in the canonical bridge it is the entire token supply
|
||||
// Deploy an ERC20 with half of entire supply granted to Gravity.sol
|
||||
TestCosmosERC20 erc20 = new TestCosmosERC20(address(this), _name, _symbol, _decimals);
|
||||
|
||||
// Fire an event to let the Cosmos module know
|
||||
state_lastEventNonce = state_lastEventNonce + 1;
|
||||
emit ERC20DeployedEvent(
|
||||
_cosmosDenom,
|
||||
address(erc20),
|
||||
_name,
|
||||
_symbol,
|
||||
_decimals,
|
||||
state_lastEventNonce
|
||||
);
|
||||
}
|
||||
|
||||
constructor(
|
||||
// A unique identifier for this gravity instance to use in signatures
|
||||
bytes32 _gravityId,
|
||||
// The validator set, not in valset args format since many of it's
|
||||
// arguments would never be used in this case
|
||||
address[] memory _validators,
|
||||
uint256[] memory _powers
|
||||
) {
|
||||
// CHECKS
|
||||
|
||||
// Check that validators, powers, and signatures (v,r,s) set is well-formed
|
||||
if (_validators.length != _powers.length || _validators.length == 0) {
|
||||
revert MalformedCurrentValidatorSet();
|
||||
}
|
||||
|
||||
// Check cumulative power to ensure the contract has sufficient power to actually
|
||||
// pass a vote
|
||||
uint256 cumulativePower = 0;
|
||||
for (uint256 i = 0; i < _powers.length; i++) {
|
||||
cumulativePower = cumulativePower + _powers[i];
|
||||
if (cumulativePower > constant_powerThreshold) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cumulativePower <= constant_powerThreshold) {
|
||||
revert InsufficientPower({
|
||||
cumulativePower: cumulativePower,
|
||||
powerThreshold: constant_powerThreshold
|
||||
});
|
||||
}
|
||||
|
||||
ValsetArgs memory _valset;
|
||||
_valset = ValsetArgs(_validators, _powers, 0, 0, address(0));
|
||||
|
||||
bytes32 newCheckpoint = makeCheckpoint(_valset, _gravityId);
|
||||
|
||||
// ACTIONS
|
||||
|
||||
state_gravityId = _gravityId;
|
||||
state_lastValsetCheckpoint = newCheckpoint;
|
||||
|
||||
// LOGS
|
||||
|
||||
emit ValsetUpdatedEvent(
|
||||
state_lastValsetNonce,
|
||||
state_lastEventNonce,
|
||||
0,
|
||||
address(0),
|
||||
_validators,
|
||||
_powers
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -8,15 +8,15 @@ require('dotenv').config({ path: require('find-config')('.env') });
|
||||
*/
|
||||
module.exports = {
|
||||
solidity: {
|
||||
version: "0.6.6",
|
||||
version: "0.8.10",
|
||||
settings: {
|
||||
optimizer: {
|
||||
enabled: true
|
||||
}
|
||||
} },
|
||||
paths: {
|
||||
artifacts: "./artifacts/contracts"
|
||||
},
|
||||
// paths: {
|
||||
// artifacts: "./artifacts/contracts"
|
||||
// },
|
||||
networks: {
|
||||
// rinkeby: {
|
||||
// url: process.env.RINKEBY_URL, //Infura url with projectId
|
||||
|
||||
+3
-3
@@ -1556,9 +1556,9 @@
|
||||
}
|
||||
},
|
||||
"@openzeppelin/contracts": {
|
||||
"version": "4.4.1",
|
||||
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.4.1.tgz",
|
||||
"integrity": "sha512-o+pHCf/yMLSlV5MkDQEzEQL402i6SoRnktru+0rdSxVEFZcTzzGhZCAtZjUFyKGazMSv1TilzMg+RbED1N8XHQ=="
|
||||
"version": "4.3.1",
|
||||
"resolved": "https://registry.npmjs.org/@openzeppelin/contracts/-/contracts-4.3.1.tgz",
|
||||
"integrity": "sha512-QjgbPPlmDK2clK1hzjw2ROfY8KA5q+PfhDUUxZFEBCZP9fi6d5FuNoh/Uq0oCTMEKPmue69vhX2jcl0N/tFKGw=="
|
||||
},
|
||||
"@openzeppelin/test-helpers": {
|
||||
"version": "0.5.15",
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
"dependencies": {
|
||||
"@nomiclabs/hardhat-truffle5": "^2.0.2",
|
||||
"@nomiclabs/hardhat-web3": "^2.0.0",
|
||||
"@openzeppelin/contracts": "^4.3.2",
|
||||
"@openzeppelin/contracts": "4.3.1",
|
||||
"@openzeppelin/test-helpers": "^0.5.15",
|
||||
"dotenv": "^10.0.0",
|
||||
"find-config": "^1.0.0"
|
||||
|
||||
Reference in New Issue
Block a user