@keep-network/tbtc-v2 0.1.1-dev.5 → 0.1.1-dev.52

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.
Files changed (95) hide show
  1. package/README.adoc +12 -0
  2. package/artifacts/Bank.json +752 -0
  3. package/artifacts/Bridge.json +3307 -0
  4. package/artifacts/Deposit.json +117 -0
  5. package/artifacts/EcdsaDkgValidator.json +532 -0
  6. package/artifacts/EcdsaInactivity.json +156 -0
  7. package/artifacts/Fraud.json +154 -0
  8. package/artifacts/KeepRegistry.json +99 -0
  9. package/artifacts/KeepStake.json +286 -0
  10. package/artifacts/KeepToken.json +711 -0
  11. package/artifacts/KeepTokenStaking.json +483 -0
  12. package/artifacts/MovingFunds.json +160 -0
  13. package/artifacts/NuCypherStakingEscrow.json +256 -0
  14. package/artifacts/NuCypherToken.json +711 -0
  15. package/artifacts/RandomBeaconStub.json +141 -0
  16. package/artifacts/Redemption.json +161 -0
  17. package/artifacts/ReimbursementPool.json +509 -0
  18. package/artifacts/Relay.json +123 -0
  19. package/artifacts/SortitionPool.json +944 -0
  20. package/artifacts/Sweep.json +76 -0
  21. package/artifacts/T.json +1148 -0
  22. package/artifacts/TBTC.json +27 -26
  23. package/artifacts/TBTCToken.json +27 -26
  24. package/artifacts/TokenStaking.json +2288 -0
  25. package/artifacts/TokenholderGovernor.json +1795 -0
  26. package/artifacts/TokenholderTimelock.json +1058 -0
  27. package/artifacts/VendingMachine.json +30 -29
  28. package/artifacts/VendingMachineKeep.json +400 -0
  29. package/artifacts/VendingMachineNuCypher.json +400 -0
  30. package/artifacts/WalletRegistry.json +2709 -0
  31. package/artifacts/WalletRegistryGovernance.json +2364 -0
  32. package/artifacts/Wallets.json +186 -0
  33. package/artifacts/solcInputs/dcf2fc19e497270603c798faeb0a9ba9.json +218 -0
  34. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.dbg.json +1 -1
  35. package/build/contracts/GovernanceUtils.sol/GovernanceUtils.json +2 -2
  36. package/build/contracts/bank/Bank.sol/Bank.dbg.json +1 -1
  37. package/build/contracts/bank/Bank.sol/Bank.json +20 -2
  38. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.dbg.json +4 -0
  39. package/build/contracts/bridge/BitcoinTx.sol/BitcoinTx.json +10 -0
  40. package/build/contracts/bridge/Bridge.sol/Bridge.dbg.json +1 -1
  41. package/build/contracts/bridge/Bridge.sol/Bridge.json +2114 -77
  42. package/build/contracts/bridge/BridgeState.sol/BridgeState.dbg.json +4 -0
  43. package/build/contracts/bridge/BridgeState.sol/BridgeState.json +172 -0
  44. package/build/contracts/bridge/Deposit.sol/Deposit.dbg.json +4 -0
  45. package/build/contracts/bridge/Deposit.sol/Deposit.json +72 -0
  46. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.dbg.json +4 -0
  47. package/build/contracts/bridge/EcdsaLib.sol/EcdsaLib.json +10 -0
  48. package/build/contracts/bridge/Fraud.sol/Fraud.dbg.json +4 -0
  49. package/build/contracts/bridge/Fraud.sol/Fraud.json +86 -0
  50. package/build/contracts/bridge/IRelay.sol/IRelay.dbg.json +4 -0
  51. package/build/contracts/bridge/IRelay.sol/IRelay.json +37 -0
  52. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.dbg.json +4 -0
  53. package/build/contracts/bridge/MovingFunds.sol/MovingFunds.json +81 -0
  54. package/build/contracts/bridge/Redemption.sol/OutboundTx.dbg.json +4 -0
  55. package/build/contracts/bridge/Redemption.sol/OutboundTx.json +10 -0
  56. package/build/contracts/bridge/Redemption.sol/Redemption.dbg.json +4 -0
  57. package/build/contracts/bridge/Redemption.sol/Redemption.json +92 -0
  58. package/build/contracts/bridge/Sweep.sol/Sweep.dbg.json +4 -0
  59. package/build/contracts/bridge/Sweep.sol/Sweep.json +30 -0
  60. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.dbg.json +1 -1
  61. package/build/contracts/bridge/VendingMachine.sol/VendingMachine.json +2 -2
  62. package/build/contracts/bridge/Wallets.sol/Wallets.dbg.json +4 -0
  63. package/build/contracts/bridge/Wallets.sol/Wallets.json +112 -0
  64. package/build/contracts/token/TBTC.sol/TBTC.dbg.json +1 -1
  65. package/build/contracts/token/TBTC.sol/TBTC.json +2 -2
  66. package/build/contracts/vault/IVault.sol/IVault.dbg.json +1 -1
  67. package/build/contracts/vault/IVault.sol/IVault.json +19 -1
  68. package/build/contracts/vault/TBTCVault.sol/TBTCVault.dbg.json +1 -1
  69. package/build/contracts/vault/TBTCVault.sol/TBTCVault.json +36 -18
  70. package/contracts/GovernanceUtils.sol +1 -1
  71. package/contracts/bank/Bank.sol +34 -18
  72. package/contracts/bridge/BitcoinTx.sol +234 -0
  73. package/contracts/bridge/Bridge.sol +1298 -126
  74. package/contracts/bridge/BridgeState.sol +553 -0
  75. package/contracts/bridge/Deposit.sol +266 -0
  76. package/contracts/bridge/EcdsaLib.sol +45 -0
  77. package/contracts/bridge/Fraud.sol +504 -0
  78. package/contracts/bridge/IRelay.sol +28 -0
  79. package/contracts/bridge/MovingFunds.sol +511 -0
  80. package/contracts/bridge/Redemption.sol +846 -0
  81. package/contracts/bridge/Sweep.sol +514 -0
  82. package/contracts/bridge/VendingMachine.sol +1 -1
  83. package/contracts/bridge/Wallets.sol +552 -0
  84. package/contracts/token/TBTC.sol +1 -1
  85. package/contracts/vault/IVault.sol +32 -10
  86. package/contracts/vault/TBTCVault.sol +20 -2
  87. package/deploy/00_resolve_relay.ts +28 -0
  88. package/deploy/04_deploy_bank.ts +27 -0
  89. package/deploy/05_deploy_bridge.ts +64 -0
  90. package/deploy/06_bank_update_bridge.ts +19 -0
  91. package/deploy/07_transfer_ownership.ts +15 -0
  92. package/deploy/08_transfer_governance.ts +20 -0
  93. package/export.json +15194 -472
  94. package/package.json +27 -23
  95. package/artifacts/solcInputs/d71966212a658480bad5748ad85b1396.json +0 -116
@@ -86,17 +86,27 @@
86
86
  {
87
87
  "inputs": [
88
88
  {
89
- "internalType": "address[]",
90
- "name": "depositors",
91
- "type": "address[]"
89
+ "internalType": "address",
90
+ "name": "from",
91
+ "type": "address"
92
92
  },
93
93
  {
94
- "internalType": "uint256[]",
95
- "name": "depositedAmounts",
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": "onBalanceIncreased",
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": "from",
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": "token",
119
- "type": "address"
135
+ "internalType": "address[]",
136
+ "name": "depositors",
137
+ "type": "address[]"
120
138
  },
121
139
  {
122
- "internalType": "bytes",
123
- "name": "",
124
- "type": "bytes"
140
+ "internalType": "uint256[]",
141
+ "name": "depositedAmounts",
142
+ "type": "uint256[]"
125
143
  }
126
144
  ],
127
- "name": "receiveApproval",
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": "0x60806040523480156200001157600080fd5b5060405162001300380380620013008339818101604052810190620000379190620001d4565b600073ffffffffffffffffffffffffffffffffffffffff168273ffffffffffffffffffffffffffffffffffffffff161415620000aa576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620000a19062000285565b60405180910390fd5b600073ffffffffffffffffffffffffffffffffffffffff168173ffffffffffffffffffffffffffffffffffffffff1614156200011d576040517f08c379a0000000000000000000000000000000000000000000000000000000008152600401620001149062000263565b60405180910390fd5b816000806101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555080600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff1602179055505050620003c0565b600081519050620001b7816200038c565b92915050565b600081519050620001ce81620003a6565b92915050565b60008060408385031215620001e857600080fd5b6000620001f885828601620001a6565b92505060206200020b85828601620001bd565b9150509250929050565b600062000224602683620002a7565b9150620002318262000314565b604082019050919050565b60006200024b602083620002a7565b9150620002588262000363565b602082019050919050565b600060208201905081810360008301526200027e8162000215565b9050919050565b60006020820190508181036000830152620002a0816200023c565b9050919050565b600082825260208201905092915050565b6000620002c582620002f4565b9050919050565b6000620002d982620002b8565b9050919050565b6000620002ed82620002b8565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b7f5442544320746f6b656e2063616e206e6f7420626520746865207a65726f206160008201527f6464726573730000000000000000000000000000000000000000000000000000602082015250565b7f42616e6b2063616e206e6f7420626520746865207a65726f2061646472657373600082015250565b6200039781620002cc565b8114620003a357600080fd5b50565b620003b181620002e0565b8114620003bd57600080fd5b50565b610f3080620003d06000396000f3fe608060405234801561001057600080fd5b50600436106100625760003560e01c806376cdb03b146100675780638f4ffcb114610085578063a0712d68146100a1578063ad7581e1146100bd578063db006a75146100d9578063e5d3d714146100f5575b600080fd5b61006f610113565b60405161007c9190610bdb565b60405180910390f35b61009f600480360381019061009a919061092e565b610137565b005b6100bb60048036038101906100b69190610a23565b610246565b005b6100d760048036038101906100d291906109ae565b6103d3565b005b6100f360048036038101906100ee9190610a23565b610566565b005b6100fd610573565b60405161010a9190610bf6565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146101c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101be90610c31565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610235576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022c90610c11565b60405180910390fd5b61023f8585610599565b5050505050565b60003390508160008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b81526004016102a59190610b60565b60206040518083038186803b1580156102bd57600080fd5b505afa1580156102d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102f59190610a4c565b1015610336576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161032d90610c91565b60405180910390fd5b6103408183610707565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c6db49c8230856040518463ffffffff1660e01b815260040161039d93929190610b7b565b600060405180830381600087803b1580156103b757600080fd5b505af11580156103cb573d6000803e3d6000fd5b505050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610461576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045890610c51565b60405180910390fd5b60008484905014156104a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049f90610c71565b60405180910390fd5b60005b8484905081101561055f5761054c8585838181106104f2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90506020020160208101906105079190610905565b848484818110610540577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90506020020135610707565b808061055790610d61565b9150506104ab565b5050505050565b6105703382610599565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b8173ffffffffffffffffffffffffffffffffffffffff167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b9369826040516105df9190610cb1565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166379cc679083836040518363ffffffff1660e01b8152600401610644929190610bb2565b600060405180830381600087803b15801561065e57600080fd5b505af1158015610672573d6000803e3d6000fd5b5050505060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166356a6d9ef83836040518363ffffffff1660e01b81526004016106d1929190610bb2565b600060405180830381600087803b1580156106eb57600080fd5b505af11580156106ff573d6000803e3d6000fd5b505050505050565b8173ffffffffffffffffffffffffffffffffffffffff167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161074d9190610cb1565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1983836040518363ffffffff1660e01b81526004016107b2929190610bb2565b600060405180830381600087803b1580156107cc57600080fd5b505af11580156107e0573d6000803e3d6000fd5b505050505050565b6000813590506107f781610ecc565b92915050565b60008083601f84011261080f57600080fd5b8235905067ffffffffffffffff81111561082857600080fd5b60208301915083602082028301111561084057600080fd5b9250929050565b60008083601f84011261085957600080fd5b8235905067ffffffffffffffff81111561087257600080fd5b60208301915083602082028301111561088a57600080fd5b9250929050565b60008083601f8401126108a357600080fd5b8235905067ffffffffffffffff8111156108bc57600080fd5b6020830191508360018202830111156108d457600080fd5b9250929050565b6000813590506108ea81610ee3565b92915050565b6000815190506108ff81610ee3565b92915050565b60006020828403121561091757600080fd5b6000610925848285016107e8565b91505092915050565b60008060008060006080868803121561094657600080fd5b6000610954888289016107e8565b9550506020610965888289016108db565b9450506040610976888289016107e8565b935050606086013567ffffffffffffffff81111561099357600080fd5b61099f88828901610891565b92509250509295509295909350565b600080600080604085870312156109c457600080fd5b600085013567ffffffffffffffff8111156109de57600080fd5b6109ea878288016107fd565b9450945050602085013567ffffffffffffffff811115610a0957600080fd5b610a1587828801610847565b925092505092959194509250565b600060208284031215610a3557600080fd5b6000610a43848285016108db565b91505092915050565b600060208284031215610a5e57600080fd5b6000610a6c848285016108f0565b91505092915050565b610a7e81610cdd565b82525050565b610a8d81610d19565b82525050565b610a9c81610d3d565b82525050565b6000610aaf601883610ccc565b9150610aba82610dd9565b602082019050919050565b6000610ad2601183610ccc565b9150610add82610e02565b602082019050919050565b6000610af5601683610ccc565b9150610b0082610e2b565b602082019050919050565b6000610b18601783610ccc565b9150610b2382610e54565b602082019050919050565b6000610b3b602283610ccc565b9150610b4682610e7d565b604082019050919050565b610b5a81610d0f565b82525050565b6000602082019050610b756000830184610a75565b92915050565b6000606082019050610b906000830186610a75565b610b9d6020830185610a75565b610baa6040830184610b51565b949350505050565b6000604082019050610bc76000830185610a75565b610bd46020830184610b51565b9392505050565b6000602082019050610bf06000830184610a84565b92915050565b6000602082019050610c0b6000830184610a93565b92915050565b60006020820190508181036000830152610c2a81610aa2565b9050919050565b60006020820190508181036000830152610c4a81610ac5565b9050919050565b60006020820190508181036000830152610c6a81610ae8565b9050919050565b60006020820190508181036000830152610c8a81610b0b565b9050919050565b60006020820190508181036000830152610caa81610b2e565b9050919050565b6000602082019050610cc66000830184610b51565b92915050565b600082825260208201905092915050565b6000610ce882610cef565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000610d2482610d2b565b9050919050565b6000610d3682610cef565b9050919050565b6000610d4882610d4f565b9050919050565b6000610d5a82610cef565b9050919050565b6000610d6c82610d0f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415610d9f57610d9e610daa565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000600082015250565b7f546f6b656e206973206e6f742054425443000000000000000000000000000000600082015250565b7f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000600082015250565b7f4e6f206465706f7369746f727320737065636966696564000000000000000000600082015250565b7f416d6f756e7420657863656564732062616c616e636520696e2074686520626160008201527f6e6b000000000000000000000000000000000000000000000000000000000000602082015250565b610ed581610cdd565b8114610ee057600080fd5b50565b610eec81610d0f565b8114610ef757600080fd5b5056fea26469706673582212202f0a068f7e8f74337505a425a28fbdc0bb82990dea78c1d1172b110d2c5e937464736f6c63430008040033",
160
- "deployedBytecode": "0x608060405234801561001057600080fd5b50600436106100625760003560e01c806376cdb03b146100675780638f4ffcb114610085578063a0712d68146100a1578063ad7581e1146100bd578063db006a75146100d9578063e5d3d714146100f5575b600080fd5b61006f610113565b60405161007c9190610bdb565b60405180910390f35b61009f600480360381019061009a919061092e565b610137565b005b6100bb60048036038101906100b69190610a23565b610246565b005b6100d760048036038101906100d291906109ae565b6103d3565b005b6100f360048036038101906100ee9190610a23565b610566565b005b6100fd610573565b60405161010a9190610bf6565b60405180910390f35b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff168373ffffffffffffffffffffffffffffffffffffffff16146101c7576040517f08c379a00000000000000000000000000000000000000000000000000000000081526004016101be90610c31565b60405180910390fd5b8273ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610235576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161022c90610c11565b60405180910390fd5b61023f8585610599565b5050505050565b60003390508160008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166370a08231836040518263ffffffff1660e01b81526004016102a59190610b60565b60206040518083038186803b1580156102bd57600080fd5b505afa1580156102d1573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906102f59190610a4c565b1015610336576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161032d90610c91565b60405180910390fd5b6103408183610707565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff16637c6db49c8230856040518463ffffffff1660e01b815260040161039d93929190610b7b565b600060405180830381600087803b1580156103b757600080fd5b505af11580156103cb573d6000803e3d6000fd5b505050505050565b60008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff163373ffffffffffffffffffffffffffffffffffffffff1614610461576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161045890610c51565b60405180910390fd5b60008484905014156104a8576040517f08c379a000000000000000000000000000000000000000000000000000000000815260040161049f90610c71565b60405180910390fd5b60005b8484905081101561055f5761054c8585838181106104f2577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90506020020160208101906105079190610905565b848484818110610540577f4e487b7100000000000000000000000000000000000000000000000000000000600052603260045260246000fd5b90506020020135610707565b808061055790610d61565b9150506104ab565b5050505050565b6105703382610599565b50565b600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1681565b8173ffffffffffffffffffffffffffffffffffffffff167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b9369826040516105df9190610cb1565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166379cc679083836040518363ffffffff1660e01b8152600401610644929190610bb2565b600060405180830381600087803b15801561065e57600080fd5b505af1158015610672573d6000803e3d6000fd5b5050505060008054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166356a6d9ef83836040518363ffffffff1660e01b81526004016106d1929190610bb2565b600060405180830381600087803b1580156106eb57600080fd5b505af11580156106ff573d6000803e3d6000fd5b505050505050565b8173ffffffffffffffffffffffffffffffffffffffff167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161074d9190610cb1565b60405180910390a2600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff1673ffffffffffffffffffffffffffffffffffffffff166340c10f1983836040518363ffffffff1660e01b81526004016107b2929190610bb2565b600060405180830381600087803b1580156107cc57600080fd5b505af11580156107e0573d6000803e3d6000fd5b505050505050565b6000813590506107f781610ecc565b92915050565b60008083601f84011261080f57600080fd5b8235905067ffffffffffffffff81111561082857600080fd5b60208301915083602082028301111561084057600080fd5b9250929050565b60008083601f84011261085957600080fd5b8235905067ffffffffffffffff81111561087257600080fd5b60208301915083602082028301111561088a57600080fd5b9250929050565b60008083601f8401126108a357600080fd5b8235905067ffffffffffffffff8111156108bc57600080fd5b6020830191508360018202830111156108d457600080fd5b9250929050565b6000813590506108ea81610ee3565b92915050565b6000815190506108ff81610ee3565b92915050565b60006020828403121561091757600080fd5b6000610925848285016107e8565b91505092915050565b60008060008060006080868803121561094657600080fd5b6000610954888289016107e8565b9550506020610965888289016108db565b9450506040610976888289016107e8565b935050606086013567ffffffffffffffff81111561099357600080fd5b61099f88828901610891565b92509250509295509295909350565b600080600080604085870312156109c457600080fd5b600085013567ffffffffffffffff8111156109de57600080fd5b6109ea878288016107fd565b9450945050602085013567ffffffffffffffff811115610a0957600080fd5b610a1587828801610847565b925092505092959194509250565b600060208284031215610a3557600080fd5b6000610a43848285016108db565b91505092915050565b600060208284031215610a5e57600080fd5b6000610a6c848285016108f0565b91505092915050565b610a7e81610cdd565b82525050565b610a8d81610d19565b82525050565b610a9c81610d3d565b82525050565b6000610aaf601883610ccc565b9150610aba82610dd9565b602082019050919050565b6000610ad2601183610ccc565b9150610add82610e02565b602082019050919050565b6000610af5601683610ccc565b9150610b0082610e2b565b602082019050919050565b6000610b18601783610ccc565b9150610b2382610e54565b602082019050919050565b6000610b3b602283610ccc565b9150610b4682610e7d565b604082019050919050565b610b5a81610d0f565b82525050565b6000602082019050610b756000830184610a75565b92915050565b6000606082019050610b906000830186610a75565b610b9d6020830185610a75565b610baa6040830184610b51565b949350505050565b6000604082019050610bc76000830185610a75565b610bd46020830184610b51565b9392505050565b6000602082019050610bf06000830184610a84565b92915050565b6000602082019050610c0b6000830184610a93565b92915050565b60006020820190508181036000830152610c2a81610aa2565b9050919050565b60006020820190508181036000830152610c4a81610ac5565b9050919050565b60006020820190508181036000830152610c6a81610ae8565b9050919050565b60006020820190508181036000830152610c8a81610b0b565b9050919050565b60006020820190508181036000830152610caa81610b2e565b9050919050565b6000602082019050610cc66000830184610b51565b92915050565b600082825260208201905092915050565b6000610ce882610cef565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b6000610d2482610d2b565b9050919050565b6000610d3682610cef565b9050919050565b6000610d4882610d4f565b9050919050565b6000610d5a82610cef565b9050919050565b6000610d6c82610d0f565b91507fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff821415610d9f57610d9e610daa565b5b600182019050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b7f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000600082015250565b7f546f6b656e206973206e6f742054425443000000000000000000000000000000600082015250565b7f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000600082015250565b7f4e6f206465706f7369746f727320737065636966696564000000000000000000600082015250565b7f416d6f756e7420657863656564732062616c616e636520696e2074686520626160008201527f6e6b000000000000000000000000000000000000000000000000000000000000602082015250565b610ed581610cdd565b8114610ee057600080fd5b50565b610eec81610d0f565b8114610ef757600080fd5b5056fea26469706673582212202f0a068f7e8f74337505a425a28fbdc0bb82990dea78c1d1172b110d2c5e937464736f6c63430008040033",
177
+ "bytecode": "0x608060405234801561001057600080fd5b50604051610b62380380610b6283398101604081905261002f91610138565b6001600160a01b03821661008a5760405162461bcd60e51b815260206004820181905260248201527f42616e6b2063616e206e6f7420626520746865207a65726f206164647265737360448201526064015b60405180910390fd5b6001600160a01b0381166100ef5760405162461bcd60e51b815260206004820152602660248201527f5442544320746f6b656e2063616e206e6f7420626520746865207a65726f206160448201526564647265737360d01b6064820152608401610081565b600080546001600160a01b039384166001600160a01b03199182161790915560018054929093169116179055610172565b6001600160a01b038116811461013557600080fd5b50565b6000806040838503121561014b57600080fd5b825161015681610120565b602084015190925061016781610120565b809150509250929050565b6109e1806101816000396000f3fe608060405234801561001057600080fd5b506004361061007d5760003560e01c80638f4ffcb11161005b5780638f4ffcb1146100d9578063a0712d68146100ec578063db006a75146100ff578063e5d3d7141461011257600080fd5b8063461c637314610082578063537941371461009757806376cdb03b146100aa575b600080fd5b6100956100903660046107cb565b610125565b005b6100956100a5366004610853565b61023d565b6000546100bd906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100956100e736600461087d565b6103e8565b6100956100fa366004610918565b6104a7565b61009561010d366004610918565b6105c9565b6001546100bd906001600160a01b031681565b6000546001600160a01b031633146101845760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b0000000000000000000060448201526064015b60405180910390fd5b826101d15760405162461bcd60e51b815260206004820152601760248201527f4e6f206465706f7369746f727320737065636966696564000000000000000000604482015260640161017b565b60005b83811015610236576102248585838181106101f1576101f1610931565b90506020020160208101906102069190610947565b84848481811061021857610218610931565b905060200201356105d6565b8061022e81610969565b9150506101d4565b5050505050565b6000546001600160a01b031633146102975760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000604482015260640161017b565b6000546040516370a0823160e01b81526001600160a01b038481166004830152839216906370a082319060240160206040518083038186803b1580156102dc57600080fd5b505afa1580156102f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103149190610992565b101561036d5760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61037782826105d6565b600054604051631f1b6d2760e21b81526001600160a01b0384811660048301523060248301526044820184905290911690637c6db49c906064015b600060405180830381600087803b1580156103cc57600080fd5b505af11580156103e0573d6000803e3d6000fd5b505050505050565b6001546001600160a01b038481169116146104455760405162461bcd60e51b815260206004820152601160248201527f546f6b656e206973206e6f742054425443000000000000000000000000000000604482015260640161017b565b336001600160a01b0384161461049d5760405162461bcd60e51b815260206004820152601860248201527f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000604482015260640161017b565b610236858561066b565b6000546040516370a0823160e01b815233600482018190529183916001600160a01b03909116906370a082319060240160206040518083038186803b1580156104ef57600080fd5b505afa158015610503573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105279190610992565b10156105805760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61058a81836105d6565b600054604051631f1b6d2760e21b81526001600160a01b0383811660048301523060248301526044820185905290911690637c6db49c906064016103b2565b6105d3338261066b565b50565b816001600160a01b03167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161061191815260200190565b60405180910390a26001546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906340c10f19906044016103b2565b816001600160a01b03167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b9369826040516106a691815260200190565b60405180910390a26001546040517f79cc67900000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906379cc679090604401600060405180830381600087803b15801561071557600080fd5b505af1158015610729573d6000803e3d6000fd5b50506000546040517f56a6d9ef0000000000000000000000000000000000000000000000000000000081526001600160a01b0386811660048301526024820186905290911692506356a6d9ef91506044016103b2565b60008083601f84011261079157600080fd5b50813567ffffffffffffffff8111156107a957600080fd5b6020830191508360208260051b85010111156107c457600080fd5b9250929050565b600080600080604085870312156107e157600080fd5b843567ffffffffffffffff808211156107f957600080fd5b6108058883890161077f565b9096509450602087013591508082111561081e57600080fd5b5061082b8782880161077f565b95989497509550505050565b80356001600160a01b038116811461084e57600080fd5b919050565b6000806040838503121561086657600080fd5b61086f83610837565b946020939093013593505050565b60008060008060006080868803121561089557600080fd5b61089e86610837565b9450602086013593506108b360408701610837565b9250606086013567ffffffffffffffff808211156108d057600080fd5b818801915088601f8301126108e457600080fd5b8135818111156108f357600080fd5b89602082850101111561090557600080fd5b9699959850939650602001949392505050565b60006020828403121561092a57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561095957600080fd5b61096282610837565b9392505050565b600060001982141561098b57634e487b7160e01b600052601160045260246000fd5b5060010190565b6000602082840312156109a457600080fd5b505191905056fea264697066735822122034d347dae8b0cb7669cfc1db70694636766f5fdc5f5a1be8ba243f64fcb4915964736f6c63430008090033",
178
+ "deployedBytecode": "0x608060405234801561001057600080fd5b506004361061007d5760003560e01c80638f4ffcb11161005b5780638f4ffcb1146100d9578063a0712d68146100ec578063db006a75146100ff578063e5d3d7141461011257600080fd5b8063461c637314610082578063537941371461009757806376cdb03b146100aa575b600080fd5b6100956100903660046107cb565b610125565b005b6100956100a5366004610853565b61023d565b6000546100bd906001600160a01b031681565b6040516001600160a01b03909116815260200160405180910390f35b6100956100e736600461087d565b6103e8565b6100956100fa366004610918565b6104a7565b61009561010d366004610918565b6105c9565b6001546100bd906001600160a01b031681565b6000546001600160a01b031633146101845760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b0000000000000000000060448201526064015b60405180910390fd5b826101d15760405162461bcd60e51b815260206004820152601760248201527f4e6f206465706f7369746f727320737065636966696564000000000000000000604482015260640161017b565b60005b83811015610236576102248585838181106101f1576101f1610931565b90506020020160208101906102069190610947565b84848481811061021857610218610931565b905060200201356105d6565b8061022e81610969565b9150506101d4565b5050505050565b6000546001600160a01b031633146102975760405162461bcd60e51b815260206004820152601660248201527f43616c6c6572206973206e6f74207468652042616e6b00000000000000000000604482015260640161017b565b6000546040516370a0823160e01b81526001600160a01b038481166004830152839216906370a082319060240160206040518083038186803b1580156102dc57600080fd5b505afa1580156102f0573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906103149190610992565b101561036d5760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61037782826105d6565b600054604051631f1b6d2760e21b81526001600160a01b0384811660048301523060248301526044820184905290911690637c6db49c906064015b600060405180830381600087803b1580156103cc57600080fd5b505af11580156103e0573d6000803e3d6000fd5b505050505050565b6001546001600160a01b038481169116146104455760405162461bcd60e51b815260206004820152601160248201527f546f6b656e206973206e6f742054425443000000000000000000000000000000604482015260640161017b565b336001600160a01b0384161461049d5760405162461bcd60e51b815260206004820152601860248201527f4f6e6c7920544254432063616c6c657220616c6c6f7765640000000000000000604482015260640161017b565b610236858561066b565b6000546040516370a0823160e01b815233600482018190529183916001600160a01b03909116906370a082319060240160206040518083038186803b1580156104ef57600080fd5b505afa158015610503573d6000803e3d6000fd5b505050506040513d601f19601f820116820180604052508101906105279190610992565b10156105805760405162461bcd60e51b815260206004820152602260248201527f416d6f756e7420657863656564732062616c616e636520696e207468652062616044820152616e6b60f01b606482015260840161017b565b61058a81836105d6565b600054604051631f1b6d2760e21b81526001600160a01b0383811660048301523060248301526044820185905290911690637c6db49c906064016103b2565b6105d3338261066b565b50565b816001600160a01b03167f30385c845b448a36257a6a1716e6ad2e1bc2cbe333cde1e69fe849ad6511adfe8260405161061191815260200190565b60405180910390a26001546040517f40c10f190000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906340c10f19906044016103b2565b816001600160a01b03167f4896181ff8f4543cc00db9fe9b6fb7e6f032b7eb772c72ab1ec1b4d2e03b9369826040516106a691815260200190565b60405180910390a26001546040517f79cc67900000000000000000000000000000000000000000000000000000000081526001600160a01b03848116600483015260248201849052909116906379cc679090604401600060405180830381600087803b15801561071557600080fd5b505af1158015610729573d6000803e3d6000fd5b50506000546040517f56a6d9ef0000000000000000000000000000000000000000000000000000000081526001600160a01b0386811660048301526024820186905290911692506356a6d9ef91506044016103b2565b60008083601f84011261079157600080fd5b50813567ffffffffffffffff8111156107a957600080fd5b6020830191508360208260051b85010111156107c457600080fd5b9250929050565b600080600080604085870312156107e157600080fd5b843567ffffffffffffffff808211156107f957600080fd5b6108058883890161077f565b9096509450602087013591508082111561081e57600080fd5b5061082b8782880161077f565b95989497509550505050565b80356001600160a01b038116811461084e57600080fd5b919050565b6000806040838503121561086657600080fd5b61086f83610837565b946020939093013593505050565b60008060008060006080868803121561089557600080fd5b61089e86610837565b9450602086013593506108b360408701610837565b9250606086013567ffffffffffffffff808211156108d057600080fd5b818801915088601f8301126108e457600080fd5b8135818111156108f357600080fd5b89602082850101111561090557600080fd5b9699959850939650602001949392505050565b60006020828403121561092a57600080fd5b5035919050565b634e487b7160e01b600052603260045260246000fd5b60006020828403121561095957600080fd5b61096282610837565b9392505050565b600060001982141561098b57634e487b7160e01b600052601160045260246000fd5b5060010190565b6000602082840312156109a457600080fd5b505191905056fea264697066735822122034d347dae8b0cb7669cfc1db70694636766f5fdc5f5a1be8ba243f64fcb4915964736f6c63430008090033",
161
179
  "linkReferences": {},
162
180
  "deployedLinkReferences": {}
163
181
  }
@@ -1,6 +1,6 @@
1
1
  // SPDX-License-Identifier: MIT
2
2
 
3
- pragma solidity 0.8.4;
3
+ pragma solidity ^0.8.9;
4
4
 
5
5
  library GovernanceUtils {
6
6
  /// @notice Reverts if the governance delay has not passed since
@@ -13,7 +13,7 @@
13
13
  // ▐████▌ ▐████▌
14
14
  // ▐████▌ ▐████▌
15
15
 
16
- pragma solidity 0.8.4;
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
- keccak256(
212
- abi.encodePacked(
213
- "\x19\x01",
214
- DOMAIN_SEPARATOR(),
215
- keccak256(
216
- abi.encode(
217
- PERMIT_TYPEHASH,
218
- owner,
219
- spender,
220
- amount,
221
- nonce[owner]++,
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).onBalanceIncreased(depositors, depositedAmounts);
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 {balanceOf[spender] = spenderBalance - amount;}
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
+ }