@keep-network/tbtc-v2 0.1.1-dev.5 → 0.1.1-dev.50
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/Bank.json +752 -0
- package/artifacts/Bridge.json +3271 -0
- package/artifacts/Deposit.json +117 -0
- package/artifacts/EcdsaDkgValidator.json +532 -0
- package/artifacts/EcdsaInactivity.json +156 -0
- package/artifacts/Fraud.json +153 -0
- package/artifacts/KeepRegistry.json +99 -0
- package/artifacts/KeepStake.json +286 -0
- package/artifacts/KeepToken.json +711 -0
- package/artifacts/KeepTokenStaking.json +483 -0
- package/artifacts/MovingFunds.json +160 -0
- package/artifacts/NuCypherStakingEscrow.json +256 -0
- package/artifacts/NuCypherToken.json +711 -0
- package/artifacts/RandomBeaconStub.json +141 -0
- package/artifacts/Redemption.json +161 -0
- package/artifacts/ReimbursementPool.json +509 -0
- package/artifacts/Relay.json +123 -0
- package/artifacts/SortitionPool.json +944 -0
- package/artifacts/Sweep.json +76 -0
- package/artifacts/T.json +1148 -0
- package/artifacts/TBTC.json +27 -26
- package/artifacts/TBTCToken.json +27 -26
- package/artifacts/TokenStaking.json +2288 -0
- package/artifacts/TokenholderGovernor.json +1795 -0
- package/artifacts/TokenholderTimelock.json +1058 -0
- package/artifacts/VendingMachine.json +30 -29
- package/artifacts/VendingMachineKeep.json +400 -0
- package/artifacts/VendingMachineNuCypher.json +400 -0
- package/artifacts/WalletRegistry.json +2709 -0
- package/artifacts/WalletRegistryGovernance.json +2364 -0
- package/artifacts/Wallets.json +186 -0
- package/artifacts/solcInputs/b0c3ed0992bd570aaaee717425c37538.json +218 -0
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
- package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
- package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
- package/build/contracts/bank/Bank.sol/Bank.json +20 -2
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
- package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
- package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
- package/build/contracts/bridge/Bridge.sol/Bridge.json +2093 -77
- package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
- package/build/contracts/bridge/BridgeState.sol/BridgeState.json +166 -0
- package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
- package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
- 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/Fraud.sol/Fraud.dbg.json +4 -0
- package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
- package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
- package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
- package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +81 -0
- package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
- package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
- package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +4 -0
- package/build/contracts/bridge/Sweep.sol/Sweep.json +30 -0
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
- package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
- package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
- package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
- package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
- package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
- package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
- package/build/contracts/vault/IVault.sol/IVault.json +19 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
- package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +36 -18
- package/contracts/GovernanceUtils.sol +1 -1
- package/contracts/bank/Bank.sol +34 -18
- package/contracts/bridge/BitcoinTx.sol +234 -0
- package/contracts/bridge/Bridge.sol +1274 -126
- package/contracts/bridge/BridgeState.sol +538 -0
- package/contracts/bridge/Deposit.sol +266 -0
- package/contracts/bridge/EcdsaLib.sol +45 -0
- package/contracts/bridge/Fraud.sol +488 -0
- package/contracts/bridge/IRelay.sol +28 -0
- package/contracts/bridge/MovingFunds.sol +511 -0
- package/contracts/bridge/Redemption.sol +846 -0
- package/contracts/bridge/Sweep.sol +514 -0
- package/contracts/bridge/VendingMachine.sol +1 -1
- package/contracts/bridge/Wallets.sol +551 -0
- package/contracts/token/TBTC.sol +1 -1
- package/contracts/vault/IVault.sol +32 -10
- package/contracts/vault/TBTCVault.sol +20 -2
- package/deploy/00_resolve_relay.ts +28 -0
- package/deploy/04_deploy_bank.ts +27 -0
- package/deploy/05_deploy_bridge.ts +64 -0
- package/deploy/06_bank_update_bridge.ts +19 -0
- package/deploy/07_transfer_ownership.ts +15 -0
- package/deploy/08_transfer_governance.ts +20 -0
- package/export.json +15173 -472
- package/package.json +27 -23
- package/artifacts/solcInputs/d71966212a658480bad5748ad85b1396.json +0 -116
|
@@ -86,17 +86,27 @@
|
|
|
86
86
|
{
|
|
87
87
|
"inputs": [
|
|
88
88
|
{
|
|
89
|
-
"internalType": "address
|
|
90
|
-
"name": "
|
|
91
|
-
"type": "address
|
|
89
|
+
"internalType": "address",
|
|
90
|
+
"name": "from",
|
|
91
|
+
"type": "address"
|
|
92
92
|
},
|
|
93
93
|
{
|
|
94
|
-
"internalType": "uint256
|
|
95
|
-
"name": "
|
|
96
|
-
"type": "uint256
|
|
94
|
+
"internalType": "uint256",
|
|
95
|
+
"name": "amount",
|
|
96
|
+
"type": "uint256"
|
|
97
|
+
},
|
|
98
|
+
{
|
|
99
|
+
"internalType": "address",
|
|
100
|
+
"name": "token",
|
|
101
|
+
"type": "address"
|
|
102
|
+
},
|
|
103
|
+
{
|
|
104
|
+
"internalType": "bytes",
|
|
105
|
+
"name": "",
|
|
106
|
+
"type": "bytes"
|
|
97
107
|
}
|
|
98
108
|
],
|
|
99
|
-
"name": "
|
|
109
|
+
"name": "receiveApproval",
|
|
100
110
|
"outputs": [],
|
|
101
111
|
"stateMutability": "nonpayable",
|
|
102
112
|
"type": "function"
|
|
@@ -105,26 +115,34 @@
|
|
|
105
115
|
"inputs": [
|
|
106
116
|
{
|
|
107
117
|
"internalType": "address",
|
|
108
|
-
"name": "
|
|
118
|
+
"name": "owner",
|
|
109
119
|
"type": "address"
|
|
110
120
|
},
|
|
111
121
|
{
|
|
112
122
|
"internalType": "uint256",
|
|
113
123
|
"name": "amount",
|
|
114
124
|
"type": "uint256"
|
|
115
|
-
}
|
|
125
|
+
}
|
|
126
|
+
],
|
|
127
|
+
"name": "receiveBalanceApproval",
|
|
128
|
+
"outputs": [],
|
|
129
|
+
"stateMutability": "nonpayable",
|
|
130
|
+
"type": "function"
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
"inputs": [
|
|
116
134
|
{
|
|
117
|
-
"internalType": "address",
|
|
118
|
-
"name": "
|
|
119
|
-
"type": "address"
|
|
135
|
+
"internalType": "address[]",
|
|
136
|
+
"name": "depositors",
|
|
137
|
+
"type": "address[]"
|
|
120
138
|
},
|
|
121
139
|
{
|
|
122
|
-
"internalType": "
|
|
123
|
-
"name": "",
|
|
124
|
-
"type": "
|
|
140
|
+
"internalType": "uint256[]",
|
|
141
|
+
"name": "depositedAmounts",
|
|
142
|
+
"type": "uint256[]"
|
|
125
143
|
}
|
|
126
144
|
],
|
|
127
|
-
"name": "
|
|
145
|
+
"name": "receiveBalanceIncrease",
|
|
128
146
|
"outputs": [],
|
|
129
147
|
"stateMutability": "nonpayable",
|
|
130
148
|
"type": "function"
|
|
@@ -156,8 +174,8 @@
|
|
|
156
174
|
"type": "function"
|
|
157
175
|
}
|
|
158
176
|
],
|
|
159
|
-
"bytecode": "
|
|
160
|
-
"deployedBytecode": "
|
|
177
|
+
"bytecode": "0x608060405234801561001057600080fd5b50604051610b62380380610b6283398101604081905261002f91610138565b6001600160a01b03821661008a5760405162461bcd60e51b815260206004820181905260248201527f42616e6b2063616e206e6f7420626520746865207a65726f206164647265737360448201526064015b60405180910390fd5b6001600160a01b0381166100ef5760405162461bcd60e51b815260206004820152602660248201527f5442544320746f6b656e2063616e206e6f7420626520746865207a65726f206160448201526564647265737360d01b6064820152608401610081565b600080546001600160a01b039384166001600160a01b03199182161790915560018054929093169116179055610172565b6001600160a01b038116811461013557600080fd5b50565b6000806040838503121561014b57600080fd5b825161015681610120565b602084015190925061016781610120565b809150509250929050565b6109e1806101816000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638f4ffcb11161005b5780638f4ffcb1146100d9578063a0712d68146100ec578063db006a75146100ff578063e5d3d7141461011257600080fd5b8063461c637314610082578063537941371461009757806376cdb03b146100aa575b600080fd5b6100956100903660046107cb565b610125565b005b6100956100a5366004610853565b61023d565b6000546100bd906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100956100e736600461087d565b6103e8565b6100956100fa366004610918565b6104a7565b61009561010d366004610918565b6105c9565b6001546100bd906001600160a01b031681565b6000546001600160a01b031633146101845760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b0000000000000000000060448201526064015b60405180910390fd5b826101d15760405162461bcd60e51b815260206004820152601760248201527f4e6f206465706f7369746f727320737065636966696564000000000000000000604482015260640161017b565b60005b83811015610236576102248585838181106101f1576101f1610931565b90506020020160208101906102069190610947565b84848481811061021857610218610931565b905060200201356105d6565b8061022e81610969565b9150506101d4565b5050505050565b6000546001600160a01b031633146102975760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000604482015260640161017b565b6000546040516370a0823160e01b81526001600160a01b038481166004830152839216906370a082319060240160206040518083038186803b1580156102dc57600080fd5b505afa1580156102f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103149190610992565b101561036d5760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61037782826105d6565b600054604051631f1b6d2760e21b81526001600160a01b0384811660048301523060248301526044820184905290911690637c6db49c906064015b600060405180830381600087803b1580156103cc57600080fd5b505af11580156103e0573d6000803e3d6000fd5b505050505050565b6001546001600160a01b038481169116146104455760405162461bcd60e51b815260206004820152601160248201527f546f6b656e206973206e6f742054425443000000000000000000000000000000604482015260640161017b565b336001600160a01b0384161461049d5760405162461bcd60e51b815260206004820152601860248201527f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000604482015260640161017b565b610236858561066b565b6000546040516370a0823160e01b815233600482018190529183916001600160a01b03909116906370a082319060240160206040518083038186803b1580156104ef57600080fd5b505afa158015610503573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105279190610992565b10156105805760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61058a81836105d6565b600054604051631f1b6d2760e21b81526001600160a01b0383811660048301523060248301526044820185905290911690637c6db49c906064016103b2565b6105d3338261066b565b50565b816001600160a01b03167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161061191815260200190565b60405180910390a26001546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906340c10f19906044016103b2565b816001600160a01b03167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b9369826040516106a691815260200190565b60405180910390a26001546040517f79cc67900000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906379cc679090604401600060405180830381600087803b15801561071557600080fd5b505af1158015610729573d6000803e3d6000fd5b50506000546040517f56a6d9ef0000000000000000000000000000000000000000000000000000000081526001600160a01b0386811660048301526024820186905290911692506356a6d9ef91506044016103b2565b60008083601f84011261079157600080fd5b50813567ffffffffffffffff8111156107a957600080fd5b6020830191508360208260051b85010111156107c457600080fd5b9250929050565b600080600080604085870312156107e157600080fd5b843567ffffffffffffffff808211156107f957600080fd5b6108058883890161077f565b9096509450602087013591508082111561081e57600080fd5b5061082b8782880161077f565b95989497509550505050565b80356001600160a01b038116811461084e57600080fd5b919050565b6000806040838503121561086657600080fd5b61086f83610837565b946020939093013593505050565b60008060008060006080868803121561089557600080fd5b61089e86610837565b9450602086013593506108b360408701610837565b9250606086013567ffffffffffffffff808211156108d057600080fd5b818801915088601f8301126108e457600080fd5b8135818111156108f357600080fd5b89602082850101111561090557600080fd5b9699959850939650602001949392505050565b60006020828403121561092a57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561095957600080fd5b61096282610837565b9392505050565b600060001982141561098b57634e487b7160e01b600052601160045260246000fd5b5060010190565b6000602082840312156109a457600080fd5b505191905056fea264697066735822122034d347dae8b0cb7669cfc1db70694636766f5fdc5f5a1be8ba243f64fcb4915964736f6c63430008090033",
|
|
178
|
+
"deployedBytecode": "0x608060405234801561001057600080fd5b506004361061007d5760003560e01c80638f4ffcb11161005b5780638f4ffcb1146100d9578063a0712d68146100ec578063db006a75146100ff578063e5d3d7141461011257600080fd5b8063461c637314610082578063537941371461009757806376cdb03b146100aa575b600080fd5b6100956100903660046107cb565b610125565b005b6100956100a5366004610853565b61023d565b6000546100bd906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100956100e736600461087d565b6103e8565b6100956100fa366004610918565b6104a7565b61009561010d366004610918565b6105c9565b6001546100bd906001600160a01b031681565b6000546001600160a01b031633146101845760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b0000000000000000000060448201526064015b60405180910390fd5b826101d15760405162461bcd60e51b815260206004820152601760248201527f4e6f206465706f7369746f727320737065636966696564000000000000000000604482015260640161017b565b60005b83811015610236576102248585838181106101f1576101f1610931565b90506020020160208101906102069190610947565b84848481811061021857610218610931565b905060200201356105d6565b8061022e81610969565b9150506101d4565b5050505050565b6000546001600160a01b031633146102975760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000604482015260640161017b565b6000546040516370a0823160e01b81526001600160a01b038481166004830152839216906370a082319060240160206040518083038186803b1580156102dc57600080fd5b505afa1580156102f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103149190610992565b101561036d5760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61037782826105d6565b600054604051631f1b6d2760e21b81526001600160a01b0384811660048301523060248301526044820184905290911690637c6db49c906064015b600060405180830381600087803b1580156103cc57600080fd5b505af11580156103e0573d6000803e3d6000fd5b505050505050565b6001546001600160a01b038481169116146104455760405162461bcd60e51b815260206004820152601160248201527f546f6b656e206973206e6f742054425443000000000000000000000000000000604482015260640161017b565b336001600160a01b0384161461049d5760405162461bcd60e51b815260206004820152601860248201527f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000604482015260640161017b565b610236858561066b565b6000546040516370a0823160e01b815233600482018190529183916001600160a01b03909116906370a082319060240160206040518083038186803b1580156104ef57600080fd5b505afa158015610503573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105279190610992565b10156105805760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61058a81836105d6565b600054604051631f1b6d2760e21b81526001600160a01b0383811660048301523060248301526044820185905290911690637c6db49c906064016103b2565b6105d3338261066b565b50565b816001600160a01b03167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161061191815260200190565b60405180910390a26001546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906340c10f19906044016103b2565b816001600160a01b03167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b9369826040516106a691815260200190565b60405180910390a26001546040517f79cc67900000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906379cc679090604401600060405180830381600087803b15801561071557600080fd5b505af1158015610729573d6000803e3d6000fd5b50506000546040517f56a6d9ef0000000000000000000000000000000000000000000000000000000081526001600160a01b0386811660048301526024820186905290911692506356a6d9ef91506044016103b2565b60008083601f84011261079157600080fd5b50813567ffffffffffffffff8111156107a957600080fd5b6020830191508360208260051b85010111156107c457600080fd5b9250929050565b600080600080604085870312156107e157600080fd5b843567ffffffffffffffff808211156107f957600080fd5b6108058883890161077f565b9096509450602087013591508082111561081e57600080fd5b5061082b8782880161077f565b95989497509550505050565b80356001600160a01b038116811461084e57600080fd5b919050565b6000806040838503121561086657600080fd5b61086f83610837565b946020939093013593505050565b60008060008060006080868803121561089557600080fd5b61089e86610837565b9450602086013593506108b360408701610837565b9250606086013567ffffffffffffffff808211156108d057600080fd5b818801915088601f8301126108e457600080fd5b8135818111156108f357600080fd5b89602082850101111561090557600080fd5b9699959850939650602001949392505050565b60006020828403121561092a57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561095957600080fd5b61096282610837565b9392505050565b600060001982141561098b57634e487b7160e01b600052601160045260246000fd5b5060010190565b6000602082840312156109a457600080fd5b505191905056fea264697066735822122034d347dae8b0cb7669cfc1db70694636766f5fdc5f5a1be8ba243f64fcb4915964736f6c63430008090033",
|
|
161
179
|
"linkReferences": {},
|
|
162
180
|
"deployedLinkReferences": {}
|
|
163
181
|
}
|
package/contracts/bank/Bank.sol
CHANGED
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
// ▐████▌ ▐████▌
|
|
14
14
|
// ▐████▌ ▐████▌
|
|
15
15
|
|
|
16
|
-
pragma solidity 0.8.
|
|
16
|
+
pragma solidity ^0.8.9;
|
|
17
17
|
|
|
18
18
|
import "@openzeppelin/contracts/access/Ownable.sol";
|
|
19
19
|
|
|
@@ -114,6 +114,21 @@ contract Bank is Ownable {
|
|
|
114
114
|
_approveBalance(msg.sender, spender, amount);
|
|
115
115
|
}
|
|
116
116
|
|
|
117
|
+
/// @notice Sets `amount` as the allowance of a smart contract `vault` over
|
|
118
|
+
/// the caller's balance and calls the vault via
|
|
119
|
+
/// `receiveBalanceApproval`.
|
|
120
|
+
/// @dev If the `amount` is set to `type(uint256).max` then the logic in
|
|
121
|
+
/// `receiveBalanceApproval` or later call to `transferBalanceFrom` by
|
|
122
|
+
/// the vault will not reduce an allowance. Beware that changing an
|
|
123
|
+
/// allowance with this function brings the risk that vault may use
|
|
124
|
+
/// both the old and the new allowance by unfortunate transaction
|
|
125
|
+
/// ordering. Please use `increaseBalanceAllowance` and
|
|
126
|
+
/// `decreaseBalanceAllowance` to eliminate the risk.
|
|
127
|
+
function approveBalanceAndCall(address vault, uint256 amount) external {
|
|
128
|
+
_approveBalance(msg.sender, vault, amount);
|
|
129
|
+
IVault(vault).receiveBalanceApproval(msg.sender, amount);
|
|
130
|
+
}
|
|
131
|
+
|
|
117
132
|
/// @notice Atomically increases the balance allowance granted to `spender`
|
|
118
133
|
/// by the caller by the given `addedValue`.
|
|
119
134
|
function increaseBalanceAllowance(address spender, uint256 addedValue)
|
|
@@ -207,23 +222,22 @@ contract Bank is Ownable {
|
|
|
207
222
|
);
|
|
208
223
|
require(v == 27 || v == 28, "Invalid signature 'v' value");
|
|
209
224
|
|
|
210
|
-
bytes32 digest =
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
deadline
|
|
223
|
-
)
|
|
225
|
+
bytes32 digest = keccak256(
|
|
226
|
+
abi.encodePacked(
|
|
227
|
+
"\x19\x01",
|
|
228
|
+
DOMAIN_SEPARATOR(),
|
|
229
|
+
keccak256(
|
|
230
|
+
abi.encode(
|
|
231
|
+
PERMIT_TYPEHASH,
|
|
232
|
+
owner,
|
|
233
|
+
spender,
|
|
234
|
+
amount,
|
|
235
|
+
nonce[owner]++,
|
|
236
|
+
deadline
|
|
224
237
|
)
|
|
225
238
|
)
|
|
226
|
-
)
|
|
239
|
+
)
|
|
240
|
+
);
|
|
227
241
|
address recoveredAddress = ecrecover(digest, v, r, s);
|
|
228
242
|
require(
|
|
229
243
|
recoveredAddress != address(0) && recoveredAddress == owner,
|
|
@@ -286,7 +300,7 @@ contract Bank is Ownable {
|
|
|
286
300
|
totalAmount += depositedAmounts[i];
|
|
287
301
|
}
|
|
288
302
|
_increaseBalance(vault, totalAmount);
|
|
289
|
-
IVault(vault).
|
|
303
|
+
IVault(vault).receiveBalanceIncrease(depositors, depositedAmounts);
|
|
290
304
|
}
|
|
291
305
|
|
|
292
306
|
/// @notice Decreases caller's balance by the provided `amount`. There is no
|
|
@@ -342,7 +356,9 @@ contract Bank is Ownable {
|
|
|
342
356
|
|
|
343
357
|
uint256 spenderBalance = balanceOf[spender];
|
|
344
358
|
require(spenderBalance >= amount, "Transfer amount exceeds balance");
|
|
345
|
-
unchecked {
|
|
359
|
+
unchecked {
|
|
360
|
+
balanceOf[spender] = spenderBalance - amount;
|
|
361
|
+
}
|
|
346
362
|
balanceOf[recipient] += amount;
|
|
347
363
|
emit BalanceTransferred(spender, recipient, amount);
|
|
348
364
|
}
|
|
@@ -0,0 +1,234 @@
|
|
|
1
|
+
// SPDX-License-Identifier: MIT
|
|
2
|
+
|
|
3
|
+
// ██████████████ ▐████▌ ██████████████
|
|
4
|
+
// ██████████████ ▐████▌ ██████████████
|
|
5
|
+
// ▐████▌ ▐████▌
|
|
6
|
+
// ▐████▌ ▐████▌
|
|
7
|
+
// ██████████████ ▐████▌ ██████████████
|
|
8
|
+
// ██████████████ ▐████▌ ██████████████
|
|
9
|
+
// ▐████▌ ▐████▌
|
|
10
|
+
// ▐████▌ ▐████▌
|
|
11
|
+
// ▐████▌ ▐████▌
|
|
12
|
+
// ▐████▌ ▐████▌
|
|
13
|
+
// ▐████▌ ▐████▌
|
|
14
|
+
// ▐████▌ ▐████▌
|
|
15
|
+
|
|
16
|
+
pragma solidity ^0.8.9;
|
|
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
|
+
|
|
21
|
+
import "./BridgeState.sol";
|
|
22
|
+
|
|
23
|
+
/// @title Bitcoin transaction
|
|
24
|
+
/// @notice Allows to reference Bitcoin raw transaction in Solidity.
|
|
25
|
+
/// @dev See https://developer.bitcoin.org/reference/transactions.html#raw-transaction-format
|
|
26
|
+
///
|
|
27
|
+
/// Raw Bitcoin transaction data:
|
|
28
|
+
///
|
|
29
|
+
/// | Bytes | Name | BTC type | Description |
|
|
30
|
+
/// |--------|--------------|------------------------|---------------------------|
|
|
31
|
+
/// | 4 | version | int32_t (LE) | TX version number |
|
|
32
|
+
/// | varies | tx_in_count | compactSize uint (LE) | Number of TX inputs |
|
|
33
|
+
/// | varies | tx_in | txIn[] | TX inputs |
|
|
34
|
+
/// | varies | tx_out count | compactSize uint (LE) | Number of TX outputs |
|
|
35
|
+
/// | varies | tx_out | txOut[] | TX outputs |
|
|
36
|
+
/// | 4 | lock_time | uint32_t (LE) | Unix time or block number |
|
|
37
|
+
///
|
|
38
|
+
//
|
|
39
|
+
/// Non-coinbase transaction input (txIn):
|
|
40
|
+
///
|
|
41
|
+
/// | Bytes | Name | BTC type | Description |
|
|
42
|
+
/// |--------|------------------|------------------------|---------------------------------------------|
|
|
43
|
+
/// | 36 | previous_output | outpoint | The previous outpoint being spent |
|
|
44
|
+
/// | varies | script bytes | compactSize uint (LE) | The number of bytes in the signature script |
|
|
45
|
+
/// | varies | signature script | char[] | The signature script, empty for P2WSH |
|
|
46
|
+
/// | 4 | sequence | uint32_t (LE) | Sequence number |
|
|
47
|
+
///
|
|
48
|
+
///
|
|
49
|
+
/// The reference to transaction being spent (outpoint):
|
|
50
|
+
///
|
|
51
|
+
/// | Bytes | Name | BTC type | Description |
|
|
52
|
+
/// |-------|-------|---------------|------------------------------------------|
|
|
53
|
+
/// | 32 | hash | char[32] | Hash of the transaction to spend |
|
|
54
|
+
/// | 4 | index | uint32_t (LE) | Index of the specific output from the TX |
|
|
55
|
+
///
|
|
56
|
+
///
|
|
57
|
+
/// Transaction output (txOut):
|
|
58
|
+
///
|
|
59
|
+
/// | Bytes | Name | BTC type | Description |
|
|
60
|
+
/// |--------|-----------------|-----------------------|--------------------------------------|
|
|
61
|
+
/// | 8 | value | int64_t (LE) | Number of satoshis to spend |
|
|
62
|
+
/// | 1+ | pk_script_bytes | compactSize uint (LE) | Number of bytes in the pubkey script |
|
|
63
|
+
/// | varies | pk_script | char[] | Pubkey script |
|
|
64
|
+
///
|
|
65
|
+
/// compactSize uint format:
|
|
66
|
+
///
|
|
67
|
+
/// | Value | Bytes | Format |
|
|
68
|
+
/// |-----------------------------------------|-------|----------------------------------------------|
|
|
69
|
+
/// | >= 0 && <= 252 | 1 | uint8_t |
|
|
70
|
+
/// | >= 253 && <= 0xffff | 3 | 0xfd followed by the number as uint16_t (LE) |
|
|
71
|
+
/// | >= 0x10000 && <= 0xffffffff | 5 | 0xfe followed by the number as uint32_t (LE) |
|
|
72
|
+
/// | >= 0x100000000 && <= 0xffffffffffffffff | 9 | 0xff followed by the number as uint64_t (LE) |
|
|
73
|
+
///
|
|
74
|
+
/// (*) compactSize uint is often references as VarInt)
|
|
75
|
+
///
|
|
76
|
+
library BitcoinTx {
|
|
77
|
+
using BTCUtils for bytes;
|
|
78
|
+
using BTCUtils for uint256;
|
|
79
|
+
using ValidateSPV for bytes;
|
|
80
|
+
using ValidateSPV for bytes32;
|
|
81
|
+
|
|
82
|
+
/// @notice Represents Bitcoin transaction data.
|
|
83
|
+
struct Info {
|
|
84
|
+
/// @notice Bitcoin transaction version
|
|
85
|
+
/// @dev `version` from raw Bitcoin transaction data.
|
|
86
|
+
/// Encoded as 4-bytes signed integer, little endian.
|
|
87
|
+
bytes4 version;
|
|
88
|
+
/// @notice All Bitcoin transaction inputs, prepended by the number of
|
|
89
|
+
/// transaction inputs.
|
|
90
|
+
/// @dev `tx_in_count | tx_in` from raw Bitcoin transaction data.
|
|
91
|
+
///
|
|
92
|
+
/// The number of transaction inputs encoded as compactSize
|
|
93
|
+
/// unsigned integer, little-endian.
|
|
94
|
+
///
|
|
95
|
+
/// Note that some popular block explorers reverse the order of
|
|
96
|
+
/// bytes from `outpoint`'s `hash` and display it as big-endian.
|
|
97
|
+
/// Solidity code of Bridge expects hashes in little-endian, just
|
|
98
|
+
/// like they are represented in a raw Bitcoin transaction.
|
|
99
|
+
bytes inputVector;
|
|
100
|
+
/// @notice All Bitcoin transaction outputs prepended by the number of
|
|
101
|
+
/// transaction outputs.
|
|
102
|
+
/// @dev `tx_out_count | tx_out` from raw Bitcoin transaction data.
|
|
103
|
+
///
|
|
104
|
+
/// The number of transaction outputs encoded as a compactSize
|
|
105
|
+
/// unsigned integer, little-endian.
|
|
106
|
+
bytes outputVector;
|
|
107
|
+
/// @notice Bitcoin transaction locktime.
|
|
108
|
+
///
|
|
109
|
+
/// @dev `lock_time` from raw Bitcoin transaction data.
|
|
110
|
+
/// Encoded as 4-bytes unsigned integer, little endian.
|
|
111
|
+
bytes4 locktime;
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
/// @notice Represents data needed to perform a Bitcoin SPV proof.
|
|
115
|
+
struct Proof {
|
|
116
|
+
/// @notice The merkle proof of transaction inclusion in a block.
|
|
117
|
+
bytes merkleProof;
|
|
118
|
+
/// @notice Transaction index in the block (0-indexed).
|
|
119
|
+
uint256 txIndexInBlock;
|
|
120
|
+
/// @notice Single byte-string of 80-byte bitcoin headers,
|
|
121
|
+
/// lowest height first.
|
|
122
|
+
bytes bitcoinHeaders;
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
/// @notice Represents info about an unspent transaction output.
|
|
126
|
+
struct UTXO {
|
|
127
|
+
/// @notice Hash of the transaction the output belongs to.
|
|
128
|
+
/// @dev Byte order corresponds to the Bitcoin internal byte order.
|
|
129
|
+
bytes32 txHash;
|
|
130
|
+
/// @notice Index of the transaction output (0-indexed).
|
|
131
|
+
uint32 txOutputIndex;
|
|
132
|
+
/// @notice Value of the transaction output.
|
|
133
|
+
uint64 txOutputValue;
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/// @notice Represents Bitcoin signature in the R/S/V format.
|
|
137
|
+
struct RSVSignature {
|
|
138
|
+
/// @notice Signature r value.
|
|
139
|
+
bytes32 r;
|
|
140
|
+
/// @notice Signature s value.
|
|
141
|
+
bytes32 s;
|
|
142
|
+
/// @notice Signature recovery value.
|
|
143
|
+
uint8 v;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/// @notice Validates the SPV proof of the Bitcoin transaction.
|
|
147
|
+
/// Reverts in case the validation or proof verification fail.
|
|
148
|
+
/// @param txInfo Bitcoin transaction data
|
|
149
|
+
/// @param proof Bitcoin proof data
|
|
150
|
+
/// @return txHash Proven 32-byte transaction hash.
|
|
151
|
+
function validateProof(
|
|
152
|
+
BridgeState.Storage storage self,
|
|
153
|
+
Info calldata txInfo,
|
|
154
|
+
Proof calldata proof
|
|
155
|
+
) internal 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(self, proof.bitcoinHeaders);
|
|
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
|
+
function evaluateProofDifficulty(
|
|
194
|
+
BridgeState.Storage storage self,
|
|
195
|
+
bytes memory bitcoinHeaders
|
|
196
|
+
) internal view {
|
|
197
|
+
IRelay relay = self.relay;
|
|
198
|
+
uint256 currentEpochDifficulty = relay.getCurrentEpochDifficulty();
|
|
199
|
+
uint256 previousEpochDifficulty = relay.getPrevEpochDifficulty();
|
|
200
|
+
|
|
201
|
+
uint256 requestedDiff = 0;
|
|
202
|
+
uint256 firstHeaderDiff = bitcoinHeaders
|
|
203
|
+
.extractTarget()
|
|
204
|
+
.calculateDifficulty();
|
|
205
|
+
|
|
206
|
+
if (firstHeaderDiff == currentEpochDifficulty) {
|
|
207
|
+
requestedDiff = currentEpochDifficulty;
|
|
208
|
+
} else if (firstHeaderDiff == previousEpochDifficulty) {
|
|
209
|
+
requestedDiff = previousEpochDifficulty;
|
|
210
|
+
} else {
|
|
211
|
+
revert("Not at current or previous difficulty");
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
uint256 observedDiff = bitcoinHeaders.validateHeaderChain();
|
|
215
|
+
|
|
216
|
+
require(
|
|
217
|
+
observedDiff != ValidateSPV.getErrBadLength(),
|
|
218
|
+
"Invalid length of the headers chain"
|
|
219
|
+
);
|
|
220
|
+
require(
|
|
221
|
+
observedDiff != ValidateSPV.getErrInvalidChain(),
|
|
222
|
+
"Invalid headers chain"
|
|
223
|
+
);
|
|
224
|
+
require(
|
|
225
|
+
observedDiff != ValidateSPV.getErrLowWork(),
|
|
226
|
+
"Insufficient work in a header"
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
require(
|
|
230
|
+
observedDiff >= requestedDiff * self.txProofDifficultyFactor,
|
|
231
|
+
"Insufficient accumulated difficulty in header chain"
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|