@keep-network/tbtc-v2 0.1.1-dev.21 → 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/BitcoinTx.sol/BitcoinTx.json +89 -3
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.json +337 -27
- 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/BitcoinTx.sol +107 -2
- package/contracts/bridge/Bridge.sol +212 -181
- package/contracts/bridge/EcdsaLib.sol +30 -0
- package/contracts/bridge/Wallets.sol +352 -0
- package/package.json +21 -17
- package/artifacts/solcInputs/af7a1ba64c125a6b01a6d1518b2bcc34.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
|
+
}
|
|
@@ -15,6 +15,9 @@
|
|
|
15
15
|
|
|
16
16
|
pragma solidity ^0.8.9;
|
|
17
17
|
|
|
18
|
+
import {BTCUtils} from "@keep-network/bitcoin-spv-sol/contracts/BTCUtils.sol";
|
|
19
|
+
import {ValidateSPV} from "@keep-network/bitcoin-spv-sol/contracts/ValidateSPV.sol";
|
|
20
|
+
|
|
18
21
|
/// @title Bitcoin transaction
|
|
19
22
|
/// @notice Allows to reference Bitcoin raw transaction in Solidity.
|
|
20
23
|
/// @dev See https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format
|
|
@@ -69,8 +72,12 @@ pragma solidity ^0.8.9;
|
|
|
69
72
|
/// (*) compactSize uint is often references as VarInt)
|
|
70
73
|
///
|
|
71
74
|
library BitcoinTx {
|
|
72
|
-
|
|
73
|
-
|
|
75
|
+
using BTCUtils for bytes;
|
|
76
|
+
using BTCUtils for uint256;
|
|
77
|
+
using ValidateSPV for bytes;
|
|
78
|
+
using ValidateSPV for bytes32;
|
|
79
|
+
|
|
80
|
+
/// @notice Represents Bitcoin transaction data.
|
|
74
81
|
struct Info {
|
|
75
82
|
/// @notice Bitcoin transaction version
|
|
76
83
|
/// @dev `version` from raw Bitcon transaction data.
|
|
@@ -113,6 +120,17 @@ library BitcoinTx {
|
|
|
113
120
|
bytes bitcoinHeaders;
|
|
114
121
|
}
|
|
115
122
|
|
|
123
|
+
/// @notice Determines the difficulty context for a Bitcoin SPV proof.
|
|
124
|
+
struct ProofDifficulty {
|
|
125
|
+
/// @notice Difficulty of the current epoch.
|
|
126
|
+
uint256 currentEpochDifficulty;
|
|
127
|
+
/// @notice Difficulty of the previous epoch.
|
|
128
|
+
uint256 previousEpochDifficulty;
|
|
129
|
+
/// @notice The number of confirmations on the Bitcoin chain required
|
|
130
|
+
/// to successfully evaluate an SPV proof.
|
|
131
|
+
uint256 difficultyFactor;
|
|
132
|
+
}
|
|
133
|
+
|
|
116
134
|
/// @notice Represents info about an unspent transaction output.
|
|
117
135
|
struct UTXO {
|
|
118
136
|
/// @notice Hash of the transaction the output belongs to.
|
|
@@ -123,4 +141,91 @@ library BitcoinTx {
|
|
|
123
141
|
/// @notice Value of the transaction output.
|
|
124
142
|
uint64 txOutputValue;
|
|
125
143
|
}
|
|
144
|
+
|
|
145
|
+
/// @notice Validates the SPV proof of the Bitcoin transaction.
|
|
146
|
+
/// Reverts in case the validation or proof verification fail.
|
|
147
|
+
/// @param txInfo Bitcoin transaction data
|
|
148
|
+
/// @param proof Bitcoin proof data
|
|
149
|
+
/// @param proofDifficulty Bitcoin proof difficulty context.
|
|
150
|
+
/// @return txHash Proven 32-byte transaction hash.
|
|
151
|
+
function validateProof(
|
|
152
|
+
Info calldata txInfo,
|
|
153
|
+
Proof calldata proof,
|
|
154
|
+
ProofDifficulty calldata proofDifficulty
|
|
155
|
+
) external view returns (bytes32 txHash) {
|
|
156
|
+
require(
|
|
157
|
+
txInfo.inputVector.validateVin(),
|
|
158
|
+
"Invalid input vector provided"
|
|
159
|
+
);
|
|
160
|
+
require(
|
|
161
|
+
txInfo.outputVector.validateVout(),
|
|
162
|
+
"Invalid output vector provided"
|
|
163
|
+
);
|
|
164
|
+
|
|
165
|
+
txHash = abi
|
|
166
|
+
.encodePacked(
|
|
167
|
+
txInfo.version,
|
|
168
|
+
txInfo.inputVector,
|
|
169
|
+
txInfo.outputVector,
|
|
170
|
+
txInfo.locktime
|
|
171
|
+
)
|
|
172
|
+
.hash256View();
|
|
173
|
+
|
|
174
|
+
require(
|
|
175
|
+
txHash.prove(
|
|
176
|
+
proof.bitcoinHeaders.extractMerkleRootLE(),
|
|
177
|
+
proof.merkleProof,
|
|
178
|
+
proof.txIndexInBlock
|
|
179
|
+
),
|
|
180
|
+
"Tx merkle proof is not valid for provided header and tx hash"
|
|
181
|
+
);
|
|
182
|
+
|
|
183
|
+
evaluateProofDifficulty(proof.bitcoinHeaders, proofDifficulty);
|
|
184
|
+
|
|
185
|
+
return txHash;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
/// @notice Evaluates the given Bitcoin proof difficulty against the actual
|
|
189
|
+
/// Bitcoin chain difficulty provided by the relay oracle.
|
|
190
|
+
/// Reverts in case the evaluation fails.
|
|
191
|
+
/// @param bitcoinHeaders Bitcoin headers chain being part of the SPV
|
|
192
|
+
/// proof. Used to extract the observed proof difficulty
|
|
193
|
+
/// @param proofDifficulty Bitcoin proof difficulty context.
|
|
194
|
+
function evaluateProofDifficulty(
|
|
195
|
+
bytes memory bitcoinHeaders,
|
|
196
|
+
ProofDifficulty calldata proofDifficulty
|
|
197
|
+
) internal view {
|
|
198
|
+
uint256 requestedDiff = 0;
|
|
199
|
+
uint256 firstHeaderDiff = bitcoinHeaders
|
|
200
|
+
.extractTarget()
|
|
201
|
+
.calculateDifficulty();
|
|
202
|
+
|
|
203
|
+
if (firstHeaderDiff == proofDifficulty.currentEpochDifficulty) {
|
|
204
|
+
requestedDiff = proofDifficulty.currentEpochDifficulty;
|
|
205
|
+
} else if (firstHeaderDiff == proofDifficulty.previousEpochDifficulty) {
|
|
206
|
+
requestedDiff = proofDifficulty.previousEpochDifficulty;
|
|
207
|
+
} else {
|
|
208
|
+
revert("Not at current or previous difficulty");
|
|
209
|
+
}
|
|
210
|
+
|
|
211
|
+
uint256 observedDiff = bitcoinHeaders.validateHeaderChain();
|
|
212
|
+
|
|
213
|
+
require(
|
|
214
|
+
observedDiff != ValidateSPV.getErrBadLength(),
|
|
215
|
+
"Invalid length of the headers chain"
|
|
216
|
+
);
|
|
217
|
+
require(
|
|
218
|
+
observedDiff != ValidateSPV.getErrInvalidChain(),
|
|
219
|
+
"Invalid headers chain"
|
|
220
|
+
);
|
|
221
|
+
require(
|
|
222
|
+
observedDiff != ValidateSPV.getErrLowWork(),
|
|
223
|
+
"Insufficient work in a header"
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
require(
|
|
227
|
+
observedDiff >= requestedDiff * proofDifficulty.difficultyFactor,
|
|
228
|
+
"Insufficient accumulated difficulty in header chain"
|
|
229
|
+
);
|
|
230
|
+
}
|
|
126
231
|
}
|