@keep-network/tbtc-v2 0.1.1-dev.23 → 0.1.1-dev.24
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.adoc +12 -0
- package/artifacts/TBTC.json +11 -10
- package/artifacts/TBTCToken.json +11 -10
- package/artifacts/VendingMachine.json +12 -11
- package/artifacts/solcInputs/2676c70e1dffa939dbf0519ef3304b34.json +191 -0
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.json +300 -29
- package/build/contracts/bridge/Bridge.sol/IRelay.dbg.json +1 -1
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
- package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
- package/build/contracts/bridge/Wallets.sol/Wallets.json +87 -0
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
- package/contracts/bridge/Bridge.sol +174 -76
- package/contracts/bridge/EcdsaLib.sol +30 -0
- package/contracts/bridge/Wallets.sol +352 -0
- package/package.json +20 -17
- package/artifacts/solcInputs/f4cbe9fa0e3015c189ba0e793fa17f51.json +0 -140
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_format": "hh-sol-artifact-1",
|
|
3
|
+
"contractName": "EcdsaLib",
|
|
4
|
+
"sourceName": "contracts/bridge/EcdsaLib.sol",
|
|
5
|
+
"abi": [],
|
|
6
|
+
"bytecode": "0x60566037600b82828239805160001a607314602a57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212203e4ee949cfe9a74982e65a4ba0a847d7818c2fe7bdbc1638863e8b26d1914ea264736f6c63430008090033",
|
|
7
|
+
"deployedBytecode": "0x73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212203e4ee949cfe9a74982e65a4ba0a847d7818c2fe7bdbc1638863e8b26d1914ea264736f6c63430008090033",
|
|
8
|
+
"linkReferences": {},
|
|
9
|
+
"deployedLinkReferences": {}
|
|
10
|
+
}
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
{
|
|
2
|
+
"_format": "hh-sol-artifact-1",
|
|
3
|
+
"contractName": "Wallets",
|
|
4
|
+
"sourceName": "contracts/bridge/Wallets.sol",
|
|
5
|
+
"abi": [
|
|
6
|
+
{
|
|
7
|
+
"anonymous": false,
|
|
8
|
+
"inputs": [
|
|
9
|
+
{
|
|
10
|
+
"indexed": true,
|
|
11
|
+
"internalType": "bytes32",
|
|
12
|
+
"name": "ecdsaWalletID",
|
|
13
|
+
"type": "bytes32"
|
|
14
|
+
},
|
|
15
|
+
{
|
|
16
|
+
"indexed": true,
|
|
17
|
+
"internalType": "bytes20",
|
|
18
|
+
"name": "walletPubKeyHash",
|
|
19
|
+
"type": "bytes20"
|
|
20
|
+
}
|
|
21
|
+
],
|
|
22
|
+
"name": "NewWalletRegistered",
|
|
23
|
+
"type": "event"
|
|
24
|
+
},
|
|
25
|
+
{
|
|
26
|
+
"anonymous": false,
|
|
27
|
+
"inputs": [],
|
|
28
|
+
"name": "NewWalletRequested",
|
|
29
|
+
"type": "event"
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
"anonymous": false,
|
|
33
|
+
"inputs": [
|
|
34
|
+
{
|
|
35
|
+
"indexed": false,
|
|
36
|
+
"internalType": "uint64",
|
|
37
|
+
"name": "newMinBtcBalance",
|
|
38
|
+
"type": "uint64"
|
|
39
|
+
},
|
|
40
|
+
{
|
|
41
|
+
"indexed": false,
|
|
42
|
+
"internalType": "uint64",
|
|
43
|
+
"name": "newMaxBtcBalance",
|
|
44
|
+
"type": "uint64"
|
|
45
|
+
}
|
|
46
|
+
],
|
|
47
|
+
"name": "WalletBtcBalanceRangeUpdated",
|
|
48
|
+
"type": "event"
|
|
49
|
+
},
|
|
50
|
+
{
|
|
51
|
+
"anonymous": false,
|
|
52
|
+
"inputs": [
|
|
53
|
+
{
|
|
54
|
+
"indexed": false,
|
|
55
|
+
"internalType": "uint32",
|
|
56
|
+
"name": "newCreationPeriod",
|
|
57
|
+
"type": "uint32"
|
|
58
|
+
}
|
|
59
|
+
],
|
|
60
|
+
"name": "WalletCreationPeriodUpdated",
|
|
61
|
+
"type": "event"
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
"anonymous": false,
|
|
65
|
+
"inputs": [
|
|
66
|
+
{
|
|
67
|
+
"indexed": true,
|
|
68
|
+
"internalType": "bytes32",
|
|
69
|
+
"name": "ecdsaWalletID",
|
|
70
|
+
"type": "bytes32"
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
"indexed": true,
|
|
74
|
+
"internalType": "bytes20",
|
|
75
|
+
"name": "walletPubKeyHash",
|
|
76
|
+
"type": "bytes20"
|
|
77
|
+
}
|
|
78
|
+
],
|
|
79
|
+
"name": "WalletTerminated",
|
|
80
|
+
"type": "event"
|
|
81
|
+
}
|
|
82
|
+
],
|
|
83
|
+
"bytecode": "0x61116061003a600b82828239805160001a60731461002d57634e487b7160e01b600052600060045260246000fd5b30600052607381538281f3fe730000000000000000000000000000000000000000301460806040526004361061007c5760003560e01c8063b4e671f41161005a578063b4e671f4146100e3578063ea2a3dcc14610103578063f832341d1461012357600080fd5b8063041aee99146100815780634fd7d486146100a3578063998b564c146100c3575b600080fd5b81801561008d57600080fd5b506100a161009c366004610e71565b610143565b005b8180156100af57600080fd5b506100a16100be366004610e9d565b6101b3565b8180156100cf57600080fd5b506100a16100de366004610ee7565b6103c2565b8180156100ef57600080fd5b506100a16100fe366004610f23565b610559565b81801561010f57600080fd5b506100a161011e366004610f5b565b61085d565b81801561012f57600080fd5b506100a161013e366004610f9d565b61086b565b81547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff16600160a01b63ffffffff83169081029190911783556040519081527f0c96a98792be84d818dd96f4167766ce3fbb8fdbfece805d7c2ec87873797b629060200160405180910390a15050565b83546001600160a01b031633146102375760405162461bcd60e51b815260206004820152602760248201527f43616c6c6572206973206e6f74207468652045434453412057616c6c6574205260448201527f656769737472790000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b600061024b610246848461099a565b610a44565b61025490610fce565b6bffffffffffffffffffffffff198116600090815260028701602052604081209192506002820154600160601b900460ff1660048111156102975761029761100a565b1461030a5760405162461bcd60e51b815260206004820152602860248201527f45434453412077616c6c657420686173206265656e20616c726561647920726560448201527f6769737465726564000000000000000000000000000000000000000000000000606482015260840161022e565b84815560028101805463ffffffff4216680100000000000000009081026cffffffffff00000000000000001990921691909117600160601b17909155600187018054606085901c9092027fffffffff0000000000000000000000000000000000000000ffffffffffffffff9092169190911790556040516bffffffffffffffffffffffff1983169086907f2dbb47dce81d6b11cca1f1e3b10143d6f7e1e7e92d2dd9aacbb1f875379d308e90600090a3505050505050565b60008267ffffffffffffffff16116104425760405162461bcd60e51b815260206004820152602160248201527f4d696e696d756d206d7573742062652067726561746572207468616e207a657260448201527f6f00000000000000000000000000000000000000000000000000000000000000606482015260840161022e565b8167ffffffffffffffff168167ffffffffffffffff16116104cb5760405162461bcd60e51b815260206004820152602860248201527f4d6178696d756d206d7573742062652067726561746572207468616e2074686560448201527f206d696e696d756d000000000000000000000000000000000000000000000000606482015260840161022e565b825477ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b67ffffffffffffffff84811691820292909217855560018501805467ffffffffffffffff191692841692831790556040805191825260208201929092527f93f75d2a1ad31d60f2381eb935c4b4d8743c9607d7bfaeabeffc62fbf4e21182910160405180910390a1505050565b8154604080517fcc56238800000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163cc562388916004808301926020929190829003018186803b1580156105b657600080fd5b505afa1580156105ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ee9190611020565b60038111156105ff576105ff61100a565b146106725760405162461bcd60e51b815260206004820152602360248201527f57616c6c6574206372656174696f6e20616c726561647920696e2070726f677260448201527f6573730000000000000000000000000000000000000000000000000000000000606482015260840161022e565b600182015468010000000000000000900460601b6bffffffffffffffffffffffff198116156107b95760006106a8848385610b1a565b6bffffffffffffffffffffffff19831660009081526002808701602052604082200154865492935063ffffffff680100000000000000009091048116926106f891600160a01b9091041683611048565b63ffffffff1642101590508080156107265750855467ffffffffffffffff600160c01b909104811690841610155b806107435750600186015467ffffffffffffffff90811690841610155b6107b55760405162461bcd60e51b815260206004820152602660248201527f57616c6c6574206372656174696f6e20636f6e646974696f6e7320617265206e60448201527f6f74206d65740000000000000000000000000000000000000000000000000000606482015260840161022e565b5050505b6040517f31fecb80caf1e1128496dd5a6f1083ba29fd5fe64c3fe04e2d1b6f9cfc27d5a390600090a18254604080517f72cc8c6d00000000000000000000000000000000000000000000000000000000815290516001600160a01b03909216916372cc8c6d9160048082019260009290919082900301818387803b15801561084057600080fd5b505af1158015610854573d6000803e3d6000fd5b50505050505050565b6108678282610c52565b5050565b6001600160a01b0381166108e75760405162461bcd60e51b815260206004820152602c60248201527f45434453412057616c6c6574205265676973747279206164647265737320636160448201527f6e6e6f74206265207a65726f0000000000000000000000000000000000000000606482015260840161022e565b81546001600160a01b0316156109655760405162461bcd60e51b815260206004820152602960248201527f45434453412057616c6c6574205265676973747279206164647265737320616c60448201527f7265616479207365740000000000000000000000000000000000000000000000606482015260840161022e565b81547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0391909116179055565b606060006109a960028461107e565b6109d457507f02000000000000000000000000000000000000000000000000000000000000006109f7565b507f03000000000000000000000000000000000000000000000000000000000000005b6040517fff00000000000000000000000000000000000000000000000000000000000000821660208201526021810185905260410160405160208183030381529060405291505092915050565b60606003600283604051610a5891906110a0565b602060405180830381855afa158015610a75573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190610a9891906110db565b604051602001610aaa91815260200190565b60408051601f1981840301815290829052610ac4916110a0565b602060405180830381855afa158015610ae1573d6000803e3d6000fd5b5050604051805160601b6bffffffffffffffffffffffff1916602082015260340190506040516020818303038152906040529050919050565b6bffffffffffffffffffffffff19821660009081526002840160205260408120600101548015610c4a57808335610b5760408601602087016110f4565b610b67606087016040880161110f565b604051602001610bd49392919092835260e09190911b7fffffffff0000000000000000000000000000000000000000000000000000000016602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166024820152602c0190565b6040516020818303038152906040528051906020012014610c375760405162461bcd60e51b815260206004820152601d60248201527f496e76616c69642077616c6c6574206d61696e205554584f2064617461000000604482015260640161022e565b610c47606084016040850161110f565b91505b509392505050565b6bffffffffffffffffffffffff1981166000908152600283016020526040902060016002820154600160601b900460ff166004811115610c9457610c9461100a565b1480610cbe5750600280820154600160601b900460ff166004811115610cbc57610cbc61100a565b145b610d305760405162461bcd60e51b815260206004820152603160248201527f45434453412077616c6c6574206d75737420626520696e204c697665206f722060448201527f4d6f76696e6746756e6473207374617465000000000000000000000000000000606482015260840161022e565b6002810180546cff00000000000000000000000019166c0400000000000000000000000017905580546040516bffffffffffffffffffffffff19841691907f9272a280b0f32f70b00ad0b546499c68e3ecc6f7bb7ef43491ec5d7b99bf69ef90600090a360018301546bffffffffffffffffffffffff198381166801000000000000000090920460601b161415610dec576001830180547fffffffff0000000000000000000000000000000000000000ffffffffffffffff1690555b82546040517f343bb9270000000000000000000000000000000000000000000000000000000081526bffffffffffffffffffffffff19841660048201526001600160a01b039091169063343bb92790602401600060405180830381600087803b15801561084057600080fd5b803563ffffffff81168114610e6c57600080fd5b919050565b60008060408385031215610e8457600080fd5b82359150610e9460208401610e58565b90509250929050565b60008060008060808587031215610eb357600080fd5b5050823594602084013594506040840135936060013592509050565b803567ffffffffffffffff81168114610e6c57600080fd5b600080600060608486031215610efc57600080fd5b83359250610f0c60208501610ecf565b9150610f1a60408501610ecf565b90509250925092565b6000808284036080811215610f3757600080fd5b833592506060601f1982011215610f4d57600080fd5b506020830190509250929050565b60008060408385031215610f6e57600080fd5b8235915060208301356bffffffffffffffffffffffff1981168114610f9257600080fd5b809150509250929050565b60008060408385031215610fb057600080fd5b8235915060208301356001600160a01b0381168114610f9257600080fd5b805160208201516bffffffffffffffffffffffff1980821692919060148310156110025780818460140360031b1b83161693505b505050919050565b634e487b7160e01b600052602160045260246000fd5b60006020828403121561103257600080fd5b81516004811061104157600080fd5b9392505050565b600063ffffffff80831681851680830382111561107557634e487b7160e01b600052601160045260246000fd5b01949350505050565b60008261109b57634e487b7160e01b600052601260045260246000fd5b500690565b6000825160005b818110156110c157602081860181015185830152016110a7565b818111156110d0576000828501525b509190910192915050565b6000602082840312156110ed57600080fd5b5051919050565b60006020828403121561110657600080fd5b61104182610e58565b60006020828403121561112157600080fd5b61104182610ecf56fea2646970667358221220cc7e3d226fb4d803c7329b0c3c4684fc02ebbbebcf6f9511da57986088085ed164736f6c63430008090033",
|
|
84
|
+
"deployedBytecode": "0x730000000000000000000000000000000000000000301460806040526004361061007c5760003560e01c8063b4e671f41161005a578063b4e671f4146100e3578063ea2a3dcc14610103578063f832341d1461012357600080fd5b8063041aee99146100815780634fd7d486146100a3578063998b564c146100c3575b600080fd5b81801561008d57600080fd5b506100a161009c366004610e71565b610143565b005b8180156100af57600080fd5b506100a16100be366004610e9d565b6101b3565b8180156100cf57600080fd5b506100a16100de366004610ee7565b6103c2565b8180156100ef57600080fd5b506100a16100fe366004610f23565b610559565b81801561010f57600080fd5b506100a161011e366004610f5b565b61085d565b81801561012f57600080fd5b506100a161013e366004610f9d565b61086b565b81547fffffffffffffffff00000000ffffffffffffffffffffffffffffffffffffffff16600160a01b63ffffffff83169081029190911783556040519081527f0c96a98792be84d818dd96f4167766ce3fbb8fdbfece805d7c2ec87873797b629060200160405180910390a15050565b83546001600160a01b031633146102375760405162461bcd60e51b815260206004820152602760248201527f43616c6c6572206973206e6f74207468652045434453412057616c6c6574205260448201527f656769737472790000000000000000000000000000000000000000000000000060648201526084015b60405180910390fd5b600061024b610246848461099a565b610a44565b61025490610fce565b6bffffffffffffffffffffffff198116600090815260028701602052604081209192506002820154600160601b900460ff1660048111156102975761029761100a565b1461030a5760405162461bcd60e51b815260206004820152602860248201527f45434453412077616c6c657420686173206265656e20616c726561647920726560448201527f6769737465726564000000000000000000000000000000000000000000000000606482015260840161022e565b84815560028101805463ffffffff4216680100000000000000009081026cffffffffff00000000000000001990921691909117600160601b17909155600187018054606085901c9092027fffffffff0000000000000000000000000000000000000000ffffffffffffffff9092169190911790556040516bffffffffffffffffffffffff1983169086907f2dbb47dce81d6b11cca1f1e3b10143d6f7e1e7e92d2dd9aacbb1f875379d308e90600090a3505050505050565b60008267ffffffffffffffff16116104425760405162461bcd60e51b815260206004820152602160248201527f4d696e696d756d206d7573742062652067726561746572207468616e207a657260448201527f6f00000000000000000000000000000000000000000000000000000000000000606482015260840161022e565b8167ffffffffffffffff168167ffffffffffffffff16116104cb5760405162461bcd60e51b815260206004820152602860248201527f4d6178696d756d206d7573742062652067726561746572207468616e2074686560448201527f206d696e696d756d000000000000000000000000000000000000000000000000606482015260840161022e565b825477ffffffffffffffffffffffffffffffffffffffffffffffff16600160c01b67ffffffffffffffff84811691820292909217855560018501805467ffffffffffffffff191692841692831790556040805191825260208201929092527f93f75d2a1ad31d60f2381eb935c4b4d8743c9607d7bfaeabeffc62fbf4e21182910160405180910390a1505050565b8154604080517fcc56238800000000000000000000000000000000000000000000000000000000815290516000926001600160a01b03169163cc562388916004808301926020929190829003018186803b1580156105b657600080fd5b505afa1580156105ca573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105ee9190611020565b60038111156105ff576105ff61100a565b146106725760405162461bcd60e51b815260206004820152602360248201527f57616c6c6574206372656174696f6e20616c726561647920696e2070726f677260448201527f6573730000000000000000000000000000000000000000000000000000000000606482015260840161022e565b600182015468010000000000000000900460601b6bffffffffffffffffffffffff198116156107b95760006106a8848385610b1a565b6bffffffffffffffffffffffff19831660009081526002808701602052604082200154865492935063ffffffff680100000000000000009091048116926106f891600160a01b9091041683611048565b63ffffffff1642101590508080156107265750855467ffffffffffffffff600160c01b909104811690841610155b806107435750600186015467ffffffffffffffff90811690841610155b6107b55760405162461bcd60e51b815260206004820152602660248201527f57616c6c6574206372656174696f6e20636f6e646974696f6e7320617265206e60448201527f6f74206d65740000000000000000000000000000000000000000000000000000606482015260840161022e565b5050505b6040517f31fecb80caf1e1128496dd5a6f1083ba29fd5fe64c3fe04e2d1b6f9cfc27d5a390600090a18254604080517f72cc8c6d00000000000000000000000000000000000000000000000000000000815290516001600160a01b03909216916372cc8c6d9160048082019260009290919082900301818387803b15801561084057600080fd5b505af1158015610854573d6000803e3d6000fd5b50505050505050565b6108678282610c52565b5050565b6001600160a01b0381166108e75760405162461bcd60e51b815260206004820152602c60248201527f45434453412057616c6c6574205265676973747279206164647265737320636160448201527f6e6e6f74206265207a65726f0000000000000000000000000000000000000000606482015260840161022e565b81546001600160a01b0316156109655760405162461bcd60e51b815260206004820152602960248201527f45434453412057616c6c6574205265676973747279206164647265737320616c60448201527f7265616479207365740000000000000000000000000000000000000000000000606482015260840161022e565b81547fffffffffffffffffffffffff0000000000000000000000000000000000000000166001600160a01b0391909116179055565b606060006109a960028461107e565b6109d457507f02000000000000000000000000000000000000000000000000000000000000006109f7565b507f03000000000000000000000000000000000000000000000000000000000000005b6040517fff00000000000000000000000000000000000000000000000000000000000000821660208201526021810185905260410160405160208183030381529060405291505092915050565b60606003600283604051610a5891906110a0565b602060405180830381855afa158015610a75573d6000803e3d6000fd5b5050506040513d601f19601f82011682018060405250810190610a9891906110db565b604051602001610aaa91815260200190565b60408051601f1981840301815290829052610ac4916110a0565b602060405180830381855afa158015610ae1573d6000803e3d6000fd5b5050604051805160601b6bffffffffffffffffffffffff1916602082015260340190506040516020818303038152906040529050919050565b6bffffffffffffffffffffffff19821660009081526002840160205260408120600101548015610c4a57808335610b5760408601602087016110f4565b610b67606087016040880161110f565b604051602001610bd49392919092835260e09190911b7fffffffff0000000000000000000000000000000000000000000000000000000016602083015260c01b7fffffffffffffffff000000000000000000000000000000000000000000000000166024820152602c0190565b6040516020818303038152906040528051906020012014610c375760405162461bcd60e51b815260206004820152601d60248201527f496e76616c69642077616c6c6574206d61696e205554584f2064617461000000604482015260640161022e565b610c47606084016040850161110f565b91505b509392505050565b6bffffffffffffffffffffffff1981166000908152600283016020526040902060016002820154600160601b900460ff166004811115610c9457610c9461100a565b1480610cbe5750600280820154600160601b900460ff166004811115610cbc57610cbc61100a565b145b610d305760405162461bcd60e51b815260206004820152603160248201527f45434453412077616c6c6574206d75737420626520696e204c697665206f722060448201527f4d6f76696e6746756e6473207374617465000000000000000000000000000000606482015260840161022e565b6002810180546cff00000000000000000000000019166c0400000000000000000000000017905580546040516bffffffffffffffffffffffff19841691907f9272a280b0f32f70b00ad0b546499c68e3ecc6f7bb7ef43491ec5d7b99bf69ef90600090a360018301546bffffffffffffffffffffffff198381166801000000000000000090920460601b161415610dec576001830180547fffffffff0000000000000000000000000000000000000000ffffffffffffffff1690555b82546040517f343bb9270000000000000000000000000000000000000000000000000000000081526bffffffffffffffffffffffff19841660048201526001600160a01b039091169063343bb92790602401600060405180830381600087803b15801561084057600080fd5b803563ffffffff81168114610e6c57600080fd5b919050565b60008060408385031215610e8457600080fd5b82359150610e9460208401610e58565b90509250929050565b60008060008060808587031215610eb357600080fd5b5050823594602084013594506040840135936060013592509050565b803567ffffffffffffffff81168114610e6c57600080fd5b600080600060608486031215610efc57600080fd5b83359250610f0c60208501610ecf565b9150610f1a60408501610ecf565b90509250925092565b6000808284036080811215610f3757600080fd5b833592506060601f1982011215610f4d57600080fd5b506020830190509250929050565b60008060408385031215610f6e57600080fd5b8235915060208301356bffffffffffffffffffffffff1981168114610f9257600080fd5b809150509250929050565b60008060408385031215610fb057600080fd5b8235915060208301356001600160a01b0381168114610f9257600080fd5b805160208201516bffffffffffffffffffffffff1980821692919060148310156110025780818460140360031b1b83161693505b505050919050565b634e487b7160e01b600052602160045260246000fd5b60006020828403121561103257600080fd5b81516004811061104157600080fd5b9392505050565b600063ffffffff80831681851680830382111561107557634e487b7160e01b600052601160045260246000fd5b01949350505050565b60008261109b57634e487b7160e01b600052601260045260246000fd5b500690565b6000825160005b818110156110c157602081860181015185830152016110a7565b818111156110d0576000828501525b509190910192915050565b6000602082840312156110ed57600080fd5b5051919050565b60006020828403121561110657600080fd5b61104182610e58565b60006020828403121561112157600080fd5b61104182610ecf56fea2646970667358221220cc7e3d226fb4d803c7329b0c3c4684fc02ebbbebcf6f9511da57986088085ed164736f6c63430008090033",
|
|
85
|
+
"linkReferences": {},
|
|
86
|
+
"deployedLinkReferences": {}
|
|
87
|
+
}
|
|
@@ -19,9 +19,12 @@ import "@openzeppelin/contracts/access/Ownable.sol";
|
|
|
19
19
|
|
|
20
20
|
import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
|
|
21
21
|
import {BytesLib} from "@keep-network/bitcoin-spv-sol/contracts/BytesLib.sol";
|
|
22
|
+
import {IWalletOwner as EcdsaWalletOwner} from "@keep-network/ecdsa/contracts/api/IWalletOwner.sol";
|
|
22
23
|
|
|
23
24
|
import "../bank/Bank.sol";
|
|
24
25
|
import "./BitcoinTx.sol";
|
|
26
|
+
import "./EcdsaLib.sol";
|
|
27
|
+
import "./Wallets.sol";
|
|
25
28
|
|
|
26
29
|
/// @title Interface for the Bitcoin relay
|
|
27
30
|
/// @notice Contains only the methods needed by tBTC v2. The Bitcoin relay
|
|
@@ -54,10 +57,11 @@ interface IRelay {
|
|
|
54
57
|
/// wallet informs the Bridge about the sweep increasing appropriate
|
|
55
58
|
/// balances in the Bank.
|
|
56
59
|
/// @dev Bridge is an upgradeable component of the Bank.
|
|
57
|
-
contract Bridge is Ownable {
|
|
60
|
+
contract Bridge is Ownable, EcdsaWalletOwner {
|
|
58
61
|
using BTCUtils for bytes;
|
|
59
62
|
using BTCUtils for uint256;
|
|
60
63
|
using BytesLib for bytes;
|
|
64
|
+
using Wallets for Wallets.Data;
|
|
61
65
|
|
|
62
66
|
/// @notice Represents data which must be revealed by the depositor during
|
|
63
67
|
/// deposit reveal.
|
|
@@ -165,36 +169,6 @@ contract Bridge is Ownable {
|
|
|
165
169
|
uint64 changeValue;
|
|
166
170
|
}
|
|
167
171
|
|
|
168
|
-
/// @notice Represents wallet state:
|
|
169
|
-
enum WalletState {
|
|
170
|
-
/// @dev The wallet is unknown to the Bridge.
|
|
171
|
-
Unknown,
|
|
172
|
-
/// @dev The wallet can sweep deposits and accept redemption requests.
|
|
173
|
-
Active,
|
|
174
|
-
/// @dev The wallet was deemed unhealthy and is expected to move their
|
|
175
|
-
/// outstanding funds to another wallet. The wallet can still
|
|
176
|
-
/// fulfill their pending redemption requests although new
|
|
177
|
-
/// redemption requests and new deposit reveals are not accepted.
|
|
178
|
-
MovingFunds,
|
|
179
|
-
/// @dev The wallet moved or redeemed all their funds and cannot
|
|
180
|
-
/// perform any action.
|
|
181
|
-
Closed,
|
|
182
|
-
/// @dev The wallet committed a fraud that was reported. The wallet is
|
|
183
|
-
/// blocked and can not perform any actions in the Bridge.
|
|
184
|
-
/// Off-chain coordination with the wallet operators is needed to
|
|
185
|
-
/// recover funds.
|
|
186
|
-
Terminated
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
/// @notice Holds information about a wallet.
|
|
190
|
-
struct Wallet {
|
|
191
|
-
// Current state of the wallet.
|
|
192
|
-
WalletState state;
|
|
193
|
-
// The total redeemable value of pending redemption requests targeting
|
|
194
|
-
// that wallet.
|
|
195
|
-
uint64 pendingRedemptionsValue;
|
|
196
|
-
}
|
|
197
|
-
|
|
198
172
|
/// @notice The number of confirmations on the Bitcoin chain required to
|
|
199
173
|
/// successfully evaluate an SPV proof.
|
|
200
174
|
uint256 public immutable txProofDifficultyFactor;
|
|
@@ -287,15 +261,6 @@ contract Bridge is Ownable {
|
|
|
287
261
|
/// validating them before attempting to execute a sweep.
|
|
288
262
|
mapping(uint256 => DepositRequest) public deposits;
|
|
289
263
|
|
|
290
|
-
/// @notice Maps the 20-byte wallet public key hash (computed using
|
|
291
|
-
/// Bitcoin HASH160 over the compressed ECDSA public key) to
|
|
292
|
-
/// the latest wallet's main UTXO computed as
|
|
293
|
-
/// keccak256(txHash | txOutputIndex | txOutputValue). The `tx`
|
|
294
|
-
/// prefix refers to the transaction which created that main UTXO.
|
|
295
|
-
/// The txHash is bytes32 (ordered as in Bitcoin internally),
|
|
296
|
-
/// txOutputIndex an uint32, and txOutputValue an uint64 value.
|
|
297
|
-
mapping(bytes20 => bytes32) public mainUtxos;
|
|
298
|
-
|
|
299
264
|
/// @notice Collection of all pending redemption requests indexed by
|
|
300
265
|
/// redemption key built as
|
|
301
266
|
/// keccak256(walletPubKeyHash | redeemerOutputScript). The
|
|
@@ -332,14 +297,27 @@ contract Bridge is Ownable {
|
|
|
332
297
|
// slither-disable-next-line uninitialized-state
|
|
333
298
|
mapping(uint256 => RedemptionRequest) public timedOutRedemptions;
|
|
334
299
|
|
|
335
|
-
/// @notice
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
300
|
+
/// @notice State related with wallets.
|
|
301
|
+
Wallets.Data internal wallets;
|
|
302
|
+
|
|
303
|
+
event WalletCreationPeriodUpdated(uint32 newCreationPeriod);
|
|
304
|
+
|
|
305
|
+
event WalletBtcBalanceRangeUpdated(
|
|
306
|
+
uint64 newMinBtcBalance,
|
|
307
|
+
uint64 newMaxBtcBalance
|
|
308
|
+
);
|
|
309
|
+
|
|
310
|
+
event NewWalletRequested();
|
|
311
|
+
|
|
312
|
+
event NewWalletRegistered(
|
|
313
|
+
bytes32 indexed ecdsaWalletID,
|
|
314
|
+
bytes20 indexed walletPubKeyHash
|
|
315
|
+
);
|
|
316
|
+
|
|
317
|
+
event WalletTerminated(
|
|
318
|
+
bytes32 indexed ecdsaWalletID,
|
|
319
|
+
bytes20 indexed walletPubKeyHash
|
|
320
|
+
);
|
|
343
321
|
|
|
344
322
|
event VaultStatusUpdated(address indexed vault, bool isTrusted);
|
|
345
323
|
|
|
@@ -375,6 +353,7 @@ contract Bridge is Ownable {
|
|
|
375
353
|
address _bank,
|
|
376
354
|
address _relay,
|
|
377
355
|
address _treasury,
|
|
356
|
+
address _ecdsaWalletRegistry,
|
|
378
357
|
uint256 _txProofDifficultyFactor
|
|
379
358
|
) {
|
|
380
359
|
require(_bank != address(0), "Bank address cannot be zero");
|
|
@@ -396,10 +375,48 @@ contract Bridge is Ownable {
|
|
|
396
375
|
redemptionTreasuryFeeDivisor = 2000; // 1/2000 == 5bps == 0.05% == 0.0005
|
|
397
376
|
redemptionTxMaxFee = 1000; // 1000 satoshi
|
|
398
377
|
redemptionTimeout = 172800; // 48 hours
|
|
378
|
+
|
|
379
|
+
// TODO: Revisit initial values.
|
|
380
|
+
wallets.init(_ecdsaWalletRegistry);
|
|
381
|
+
wallets.setCreationPeriod(1 weeks);
|
|
382
|
+
wallets.setBtcBalanceRange(1 * 1e8, 10 * 1e8); // [1 BTC, 10 BTC]
|
|
399
383
|
}
|
|
400
384
|
|
|
401
|
-
|
|
402
|
-
|
|
385
|
+
/// @notice Updates parameters used by the `Wallets` library.
|
|
386
|
+
/// @param creationPeriod New value of the wallet creation period
|
|
387
|
+
/// @param minBtcBalance New value of the minimum BTC balance
|
|
388
|
+
/// @param maxBtcBalance New value of the maximum BTC balance
|
|
389
|
+
/// @dev Requirements:
|
|
390
|
+
/// - Caller must be the contract owner.
|
|
391
|
+
/// - Minimum BTC balance must be greater than zero
|
|
392
|
+
/// - Maximum BTC balance must be greater than minimum BTC balance
|
|
393
|
+
function updateWalletsParameters(
|
|
394
|
+
uint32 creationPeriod,
|
|
395
|
+
uint64 minBtcBalance,
|
|
396
|
+
uint64 maxBtcBalance
|
|
397
|
+
) external onlyOwner {
|
|
398
|
+
wallets.setCreationPeriod(creationPeriod);
|
|
399
|
+
wallets.setBtcBalanceRange(minBtcBalance, maxBtcBalance);
|
|
400
|
+
}
|
|
401
|
+
|
|
402
|
+
/// @return creationPeriod Value of the wallet creation period
|
|
403
|
+
/// @return minBtcBalance Value of the minimum BTC balance
|
|
404
|
+
/// @return maxBtcBalance Value of the maximum BTC balance
|
|
405
|
+
function getWalletsParameters()
|
|
406
|
+
external
|
|
407
|
+
view
|
|
408
|
+
returns (
|
|
409
|
+
uint32 creationPeriod,
|
|
410
|
+
uint64 minBtcBalance,
|
|
411
|
+
uint64 maxBtcBalance
|
|
412
|
+
)
|
|
413
|
+
{
|
|
414
|
+
creationPeriod = wallets.creationPeriod;
|
|
415
|
+
minBtcBalance = wallets.minBtcBalance;
|
|
416
|
+
maxBtcBalance = wallets.maxBtcBalance;
|
|
417
|
+
|
|
418
|
+
return (creationPeriod, minBtcBalance, maxBtcBalance);
|
|
419
|
+
}
|
|
403
420
|
|
|
404
421
|
/// @notice Allows the Governance to mark the given vault address as trusted
|
|
405
422
|
/// or no longer trusted. Vaults are not trusted by default.
|
|
@@ -419,6 +436,77 @@ contract Bridge is Ownable {
|
|
|
419
436
|
emit VaultStatusUpdated(vault, isTrusted);
|
|
420
437
|
}
|
|
421
438
|
|
|
439
|
+
/// @notice Requests creation of a new wallet. This function just
|
|
440
|
+
/// forms a request and the creation process is performed
|
|
441
|
+
/// asynchronously. Once a wallet is created, the ECDSA Wallet
|
|
442
|
+
/// Registry will notify this contract by calling the
|
|
443
|
+
/// `__ecdsaWalletCreatedCallback` function.
|
|
444
|
+
/// @param activeWalletMainUtxo Data of the active wallet's main UTXO, as
|
|
445
|
+
/// currently known on the Ethereum chain.
|
|
446
|
+
/// @dev Requirements:
|
|
447
|
+
/// - `activeWalletMainUtxo` components must point to the recent main
|
|
448
|
+
/// UTXO of the given active wallet, as currently known on the
|
|
449
|
+
/// Ethereum chain. If there is no active wallet at the moment, or
|
|
450
|
+
/// the active wallet has no main UTXO, this parameter can be
|
|
451
|
+
/// empty as it is ignored.
|
|
452
|
+
/// - Wallet creation must not be in progress
|
|
453
|
+
/// - If the active wallet is set, one of the following
|
|
454
|
+
/// conditions must be true:
|
|
455
|
+
/// - The active wallet BTC balance is above the minimum threshold
|
|
456
|
+
/// and the active wallet is old enough, i.e. the creation period
|
|
457
|
+
/// was elapsed since its creation time
|
|
458
|
+
/// - The active wallet BTC balance is above the maximum threshold
|
|
459
|
+
function requestNewWallet(BitcoinTx.UTXO calldata activeWalletMainUtxo)
|
|
460
|
+
external
|
|
461
|
+
{
|
|
462
|
+
wallets.requestNewWallet(activeWalletMainUtxo);
|
|
463
|
+
}
|
|
464
|
+
|
|
465
|
+
/// @notice A callback function that is called by the ECDSA Wallet Registry
|
|
466
|
+
/// once a new ECDSA wallet is created.
|
|
467
|
+
/// @param ecdsaWalletID Wallet's unique identifier.
|
|
468
|
+
/// @param publicKeyX Wallet's public key's X coordinate.
|
|
469
|
+
/// @param publicKeyY Wallet's public key's Y coordinate.
|
|
470
|
+
/// @dev Requirements:
|
|
471
|
+
/// - The only caller authorized to call this function is `registry`
|
|
472
|
+
/// - Given wallet data must not belong to an already registered wallet
|
|
473
|
+
function __ecdsaWalletCreatedCallback(
|
|
474
|
+
bytes32 ecdsaWalletID,
|
|
475
|
+
bytes32 publicKeyX,
|
|
476
|
+
bytes32 publicKeyY
|
|
477
|
+
) external override {
|
|
478
|
+
wallets.registerNewWallet(ecdsaWalletID, publicKeyX, publicKeyY);
|
|
479
|
+
}
|
|
480
|
+
|
|
481
|
+
// TODO: Documentation.
|
|
482
|
+
function __ecdsaWalletHeartbeatFailedCallback(
|
|
483
|
+
bytes32 ecdsaWalletID,
|
|
484
|
+
bytes32 publicKeyX,
|
|
485
|
+
bytes32 publicKeyY
|
|
486
|
+
) external override {
|
|
487
|
+
// TODO: Implementation.
|
|
488
|
+
}
|
|
489
|
+
|
|
490
|
+
/// @notice Gets details about a registered wallet.
|
|
491
|
+
/// @param walletPubKeyHash The 20-byte wallet public key hash (computed
|
|
492
|
+
/// using Bitcoin HASH160 over the compressed ECDSA public key)
|
|
493
|
+
/// @return Wallet details.
|
|
494
|
+
function getWallet(bytes20 walletPubKeyHash)
|
|
495
|
+
external
|
|
496
|
+
view
|
|
497
|
+
returns (Wallets.Wallet memory)
|
|
498
|
+
{
|
|
499
|
+
return wallets.registeredWallets[walletPubKeyHash];
|
|
500
|
+
}
|
|
501
|
+
|
|
502
|
+
/// @notice Gets the public key hash of the active wallet.
|
|
503
|
+
/// @return The 20-byte public key hash (computed using Bitcoin HASH160
|
|
504
|
+
/// over the compressed ECDSA public key) of the active wallet.
|
|
505
|
+
/// Returns bytes20(0) if there is no active wallet at the moment.
|
|
506
|
+
function getActiveWalletPubKeyHash() external view returns (bytes20) {
|
|
507
|
+
return wallets.activeWalletPubKeyHash;
|
|
508
|
+
}
|
|
509
|
+
|
|
422
510
|
/// @notice Determines the current Bitcoin SPV proof difficulty context.
|
|
423
511
|
/// @return proofDifficulty Bitcoin proof difficulty context.
|
|
424
512
|
function proofDifficultyContext()
|
|
@@ -477,7 +565,7 @@ contract Bridge is Ownable {
|
|
|
477
565
|
"Vault is not trusted"
|
|
478
566
|
);
|
|
479
567
|
|
|
480
|
-
// TODO: Validate if `walletPubKeyHash` is a known and
|
|
568
|
+
// TODO: Validate if `walletPubKeyHash` is a known and live wallet.
|
|
481
569
|
// TODO: Should we enforce a specific locktime at contract level?
|
|
482
570
|
|
|
483
571
|
bytes memory expectedScript = abi.encodePacked(
|
|
@@ -646,7 +734,11 @@ contract Bridge is Ownable {
|
|
|
646
734
|
uint64 sweepTxOutputValue
|
|
647
735
|
) = processSweepTxOutput(sweepTx.outputVector);
|
|
648
736
|
|
|
649
|
-
|
|
737
|
+
Wallets.Wallet storage wallet = wallets.registeredWallets[
|
|
738
|
+
walletPubKeyHash
|
|
739
|
+
];
|
|
740
|
+
|
|
741
|
+
// TODO: Validate if `walletPubKeyHash` is a known and live wallet.
|
|
650
742
|
|
|
651
743
|
// Check if the main UTXO for given wallet exists. If so, validate
|
|
652
744
|
// passed main UTXO data against the stored hash and use them for
|
|
@@ -656,7 +748,7 @@ contract Bridge is Ownable {
|
|
|
656
748
|
0,
|
|
657
749
|
0
|
|
658
750
|
);
|
|
659
|
-
bytes32 mainUtxoHash =
|
|
751
|
+
bytes32 mainUtxoHash = wallet.mainUtxoHash;
|
|
660
752
|
if (mainUtxoHash != bytes32(0)) {
|
|
661
753
|
require(
|
|
662
754
|
keccak256(
|
|
@@ -724,7 +816,7 @@ contract Bridge is Ownable {
|
|
|
724
816
|
// Record this sweep data and assign them to the wallet public key hash
|
|
725
817
|
// as new main UTXO. Transaction output index is always 0 as sweep
|
|
726
818
|
// transaction always contains only one output.
|
|
727
|
-
|
|
819
|
+
wallet.mainUtxoHash = keccak256(
|
|
728
820
|
abi.encodePacked(sweepTxHash, uint32(0), sweepTxOutputValue)
|
|
729
821
|
);
|
|
730
822
|
|
|
@@ -995,7 +1087,7 @@ contract Bridge is Ownable {
|
|
|
995
1087
|
/// @notice Requests redemption of the given amount from the specified
|
|
996
1088
|
/// wallet to the redeemer Bitcoin output script.
|
|
997
1089
|
/// @param walletPubKeyHash The 20-byte wallet public key hash (computed
|
|
998
|
-
|
|
1090
|
+
/// using Bitcoin HASH160 over the compressed ECDSA public key)
|
|
999
1091
|
/// @param mainUtxo Data of the wallet's main UTXO, as currently known on
|
|
1000
1092
|
/// the Ethereum chain
|
|
1001
1093
|
/// @param redeemerOutputScript The redeemer's length-prefixed output
|
|
@@ -1010,7 +1102,7 @@ contract Bridge is Ownable {
|
|
|
1010
1102
|
/// `amount - (amount / redemptionTreasuryFeeDivisor) - redemptionTxMaxFee`.
|
|
1011
1103
|
/// Fees values are taken at the moment of request creation.
|
|
1012
1104
|
/// @dev Requirements:
|
|
1013
|
-
/// - Wallet behind `walletPubKeyHash` must be
|
|
1105
|
+
/// - Wallet behind `walletPubKeyHash` must be live
|
|
1014
1106
|
/// - `mainUtxo` components must point to the recent main UTXO
|
|
1015
1107
|
/// of the given wallet, as currently known on the Ethereum chain.
|
|
1016
1108
|
/// - `redeemerOutputScript` must be a proper Bitcoin script
|
|
@@ -1027,12 +1119,16 @@ contract Bridge is Ownable {
|
|
|
1027
1119
|
bytes calldata redeemerOutputScript,
|
|
1028
1120
|
uint64 amount
|
|
1029
1121
|
) external {
|
|
1122
|
+
Wallets.Wallet storage wallet = wallets.registeredWallets[
|
|
1123
|
+
walletPubKeyHash
|
|
1124
|
+
];
|
|
1125
|
+
|
|
1030
1126
|
require(
|
|
1031
|
-
|
|
1032
|
-
"Wallet must be in
|
|
1127
|
+
wallet.state == Wallets.WalletState.Live,
|
|
1128
|
+
"Wallet must be in Live state"
|
|
1033
1129
|
);
|
|
1034
1130
|
|
|
1035
|
-
bytes32 mainUtxoHash =
|
|
1131
|
+
bytes32 mainUtxoHash = wallet.mainUtxoHash;
|
|
1036
1132
|
require(
|
|
1037
1133
|
mainUtxoHash != bytes32(0),
|
|
1038
1134
|
"No main UTXO for the given wallet"
|
|
@@ -1094,7 +1190,7 @@ contract Bridge is Ownable {
|
|
|
1094
1190
|
|
|
1095
1191
|
// Check if given redemption key is not used by a pending redemption.
|
|
1096
1192
|
// There is no need to check for existence in `timedOutRedemptions`
|
|
1097
|
-
// since the wallet's state is changed to other than
|
|
1193
|
+
// since the wallet's state is changed to other than Live after
|
|
1098
1194
|
// first time out is reported so making new requests is not possible.
|
|
1099
1195
|
// slither-disable-next-line incorrect-equality
|
|
1100
1196
|
require(
|
|
@@ -1115,12 +1211,9 @@ contract Bridge is Ownable {
|
|
|
1115
1211
|
// wallet we need to subtract the total value of all pending redemptions
|
|
1116
1212
|
// from that wallet's main UTXO value. Given that the treasury fee is
|
|
1117
1213
|
// not redeemed from the wallet, we are subtracting it.
|
|
1118
|
-
|
|
1119
|
-
amount -
|
|
1120
|
-
treasuryFee;
|
|
1214
|
+
wallet.pendingRedemptionsValue += amount - treasuryFee;
|
|
1121
1215
|
require(
|
|
1122
|
-
mainUtxo.txOutputValue >=
|
|
1123
|
-
wallets[walletPubKeyHash].pendingRedemptionsValue,
|
|
1216
|
+
mainUtxo.txOutputValue >= wallet.pendingRedemptionsValue,
|
|
1124
1217
|
"Insufficient wallet funds"
|
|
1125
1218
|
);
|
|
1126
1219
|
|
|
@@ -1217,11 +1310,15 @@ contract Bridge is Ownable {
|
|
|
1217
1310
|
walletPubKeyHash
|
|
1218
1311
|
);
|
|
1219
1312
|
|
|
1220
|
-
|
|
1313
|
+
Wallets.Wallet storage wallet = wallets.registeredWallets[
|
|
1314
|
+
walletPubKeyHash
|
|
1315
|
+
];
|
|
1316
|
+
|
|
1317
|
+
Wallets.WalletState walletState = wallet.state;
|
|
1221
1318
|
require(
|
|
1222
|
-
walletState == WalletState.
|
|
1223
|
-
walletState == WalletState.MovingFunds,
|
|
1224
|
-
"Wallet must be in
|
|
1319
|
+
walletState == Wallets.WalletState.Live ||
|
|
1320
|
+
walletState == Wallets.WalletState.MovingFunds,
|
|
1321
|
+
"Wallet must be in Live or MovingFuds state"
|
|
1225
1322
|
);
|
|
1226
1323
|
|
|
1227
1324
|
// Process redemption transaction outputs to extract some info required
|
|
@@ -1234,7 +1331,7 @@ contract Bridge is Ownable {
|
|
|
1234
1331
|
if (outputsInfo.changeValue > 0) {
|
|
1235
1332
|
// If the change value is grater than zero, it means the change
|
|
1236
1333
|
// output exists and can be used as new wallet's main UTXO.
|
|
1237
|
-
|
|
1334
|
+
wallet.mainUtxoHash = keccak256(
|
|
1238
1335
|
abi.encodePacked(
|
|
1239
1336
|
redemptionTxHash,
|
|
1240
1337
|
outputsInfo.changeIndex,
|
|
@@ -1245,11 +1342,10 @@ contract Bridge is Ownable {
|
|
|
1245
1342
|
// If the change value is zero, it means the change output doesn't
|
|
1246
1343
|
// exists and no funds left on the wallet. Delete the main UTXO
|
|
1247
1344
|
// for that wallet to represent that state in a proper way.
|
|
1248
|
-
delete
|
|
1345
|
+
delete wallet.mainUtxoHash;
|
|
1249
1346
|
}
|
|
1250
1347
|
|
|
1251
|
-
|
|
1252
|
-
.totalBurnableValue;
|
|
1348
|
+
wallet.pendingRedemptionsValue -= outputsInfo.totalBurnableValue;
|
|
1253
1349
|
|
|
1254
1350
|
emit RedemptionsCompleted(walletPubKeyHash, redemptionTxHash);
|
|
1255
1351
|
|
|
@@ -1275,7 +1371,9 @@ contract Bridge is Ownable {
|
|
|
1275
1371
|
bytes20 walletPubKeyHash
|
|
1276
1372
|
) internal view {
|
|
1277
1373
|
// Assert that main UTXO for passed wallet exists in storage.
|
|
1278
|
-
bytes32 mainUtxoHash =
|
|
1374
|
+
bytes32 mainUtxoHash = wallets
|
|
1375
|
+
.registeredWallets[walletPubKeyHash]
|
|
1376
|
+
.mainUtxoHash;
|
|
1279
1377
|
require(mainUtxoHash != bytes32(0), "No main UTXO for given wallet");
|
|
1280
1378
|
|
|
1281
1379
|
// Assert that passed main UTXO parameter is the same as in storage and
|
|
@@ -1538,7 +1636,7 @@ contract Bridge is Ownable {
|
|
|
1538
1636
|
// by copying the entire `RedemptionRequest` struct there. No need
|
|
1539
1637
|
// to check if `timedOutRedemptions` mapping already contains
|
|
1540
1638
|
// that key because `requestRedemption` blocks requests targeting
|
|
1541
|
-
// non-
|
|
1639
|
+
// non-live wallets. Because `notifyRedemptionTimeout` changes
|
|
1542
1640
|
// wallet state after first call (point 9), there is no possibility
|
|
1543
1641
|
// that the given redemption key could be reported as timed out
|
|
1544
1642
|
// multiple times. At the same time, if the given redemption key
|
|
@@ -1591,7 +1689,7 @@ contract Bridge is Ownable {
|
|
|
1591
1689
|
// to have a bad input vector.
|
|
1592
1690
|
// 2. Perform SPV proof to make sure it occurred on Bitcoin chain.
|
|
1593
1691
|
// If not - revert.
|
|
1594
|
-
// 3. Check if wallet state is
|
|
1692
|
+
// 3. Check if wallet state is Live or MovingFunds. If not, revert.
|
|
1595
1693
|
// 4. Validate the number of inputs. If there is one input and it
|
|
1596
1694
|
// points to the wallet's main UTXO - move to point 5. If there
|
|
1597
1695
|
// are multiple inputs and there is wallet's main UTXO in the set,
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
pragma solidity ^0.8.9;
|
|
2
|
+
|
|
3
|
+
import "@keep-network/bitcoin-spv-sol/contracts/BytesLib.sol";
|
|
4
|
+
|
|
5
|
+
library EcdsaLib {
|
|
6
|
+
using BytesLib for bytes;
|
|
7
|
+
|
|
8
|
+
/// @notice Converts public key X and Y coordinates (32-byte each) to a
|
|
9
|
+
/// compressed public key (33-byte). Compressed public key is X
|
|
10
|
+
/// coordinate prefixed with `02` or `03` based on the Y coordinate parity.
|
|
11
|
+
/// It is expected that the uncompressed public key is stripped
|
|
12
|
+
/// (i.e. it is not prefixed with `04`).
|
|
13
|
+
/// @param x Wallet's public key's X coordinate.
|
|
14
|
+
/// @param y Wallet's public key's Y coordinate.
|
|
15
|
+
/// @return Compressed public key (33-byte), prefixed with `02` or `03`.
|
|
16
|
+
function compressPublicKey(bytes32 x, bytes32 y)
|
|
17
|
+
internal
|
|
18
|
+
pure
|
|
19
|
+
returns (bytes memory)
|
|
20
|
+
{
|
|
21
|
+
bytes1 prefix;
|
|
22
|
+
if (uint256(y) % 2 == 0) {
|
|
23
|
+
prefix = hex"02";
|
|
24
|
+
} else {
|
|
25
|
+
prefix = hex"03";
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return bytes.concat(prefix, x);
|
|
29
|
+
}
|
|
30
|
+
}
|