bitpro가 원문에서 글자만 모은 내용이에요. 표·그림·수식은 빠지거나 깨질 수 있어요. 전체 36쪽 중 23쪽
fset, uint256 resetMovingFundsTimeoutGasOffset, uint256 submitMovingFundsProofGasOffset, uint256 notifyMovingFundsBelowDustGasOffset, uint256 submitMovedFundsSweepProofGasOffset, uint256 requestNewWalletGasOffset, uint256 notifyWalletCloseableGasOffset, uint256 notifyWalletClosingPeriodElapsedGasOffset, uint256 defeatFraudChallengeGasOffset, uint256 defeatFraudChallengeWithHeartbeatGasOffset)
```
### onlyWalletMaintainer
```solidity
modifier onlyWalletMaintainer()
```
### onlySpvMaintainer
```solidity
modifier onlySpvMaintainer()
```
### onlyReimbursableAdmin
```solidity
modifier onlyReimbursableAdmin()
```
### constructor
```solidity
constructor(contract Bridge _bridge, contract ReimbursementPool _reimbursementPool) public
```
### submitDepositSweepProof
```solidity
function submitDepositSweepProof(struct BitcoinTx.Info sweepTx, struct BitcoinTx.Proof sweepProof, struct BitcoinTx.UTXO mainUtxo, address vault) external
```
Wraps `Bridge.submitDepositSweepProof` call and reimburses the caller's transaction cost.
See `Bridge.submitDepositSweepProof` function documentation.
### submitRedemptionProof
```solidity
function submitRedemptionProof(struct BitcoinTx.Info redemptionTx, struct BitcoinTx.Proof redemptionProof, struct BitcoinTx.UTXO mainUtxo, bytes20 walletPubKeyHash) external
```
Wraps `Bridge.submitRedemptionProof` call and reimburses the caller's transaction cost.
See `Bridge.submitRedemptionProof` function documentation.
### resetMovingFundsTimeout
```solidity
function resetMovingFundsTimeout(bytes20 walletPubKeyHash) external
```
Wraps `Bridge.resetMovingFundsTimeout` call and reimburses the caller's transaction cost.
See `Bridge.resetMovingFundsTimeout` function documentation.
### submitMovingFundsProof
```solidity
function submitMovingFundsProof(struct BitcoinTx.Info movingFundsTx, struct BitcoinTx.Proof movingFundsProof, struct BitcoinTx.UTXO mainUtxo, bytes20 walletPubKeyHash) external
```
Wraps `Bridge.submitMovingFundsProof` call and reimburses the caller's transaction cost.
See `Bridge.submitMovingFundsProof` function documentation.
### notifyMovingFundsBelowDust
```solidity
function notifyMovingFundsBelowDust(bytes20 walletPubKeyHash, struct BitcoinTx.UTXO mainUtxo) external
```
Wraps `Bridge.notifyMovingFundsBelowDust` call and reimburses the caller's transaction cost.
See `Bridge.notifyMovingFundsBelowDust` function documentation.
### submitMovedFundsSweepProof
```solidity
function submitMovedFundsSweepProof(struct BitcoinTx.Info sweepTx, struct BitcoinTx.Proof sweepProof, struct BitcoinTx.UTXO mainUtxo) external
```
Wraps `Bridge.submitMovedFundsSweepProof` call and reimburses the caller's transaction cost.
See `Bridge.submitMovedFundsSweepProof` function documentation.
### requestNewWallet
```solidity
function requestNewWallet(struct BitcoinTx.UTXO activeWalletMainUtxo) external
```
Wraps `Bridge.requestNewWallet` call and reimburses the caller's transaction cost.
See `Bridge.requestNewWallet` function documentation.
### notifyWalletCloseable
```solidity
function notifyWalletCloseable(bytes20 walletPubKeyHash, struct BitcoinTx.UTXO walletMainUtxo) external
```
Wraps `Bridge.notifyWalletCloseable` call and reimburses the caller's transaction cost.
See `Bridge.notifyWalletCloseable` function documentation.
### notifyWalletClosingPeriodElapsed
```solidity
function notifyWalletClosingPeriodElapsed(bytes20 walletPubKeyHash) external
```
Wraps `Bridge.notifyWalletClosingPeriodElapsed` call and reimburses the caller's transaction cost.
See `Bridge.notifyWalletClosingPeriodElapsed` function documentation.
### defeatFraudChallenge
```solidity
function defeatFraudChallenge(bytes walletPublicKey, bytes preimage, bool witness) external
```
Wraps `Bridge.defeatFraudChallenge` call and reimburses the caller's transaction cost.
See `Bridge.defeatFraudChallenge` function documentation.
### defeatFraudChallengeWithHeartbeat
```solidity
function defeatFraudChallengeWithHeartbeat(bytes walletPublicKey, bytes heartbeatMessage) external
```
Wraps `Bridge.defeatFraudChallengeWithHeartbeat` call and reimburses the caller's transaction cost.
See `Bridge.defeatFraudChallengeWithHeartbeat` function documentation.
### authorizeWalletMaintainer
```solidity
function authorizeWalletMaintainer(address maintainer) external
```
Authorize a wallet maintainer that can interact with this reimbursement pool. Can be authorized by the owner only.
#### Parameters
| Name | Type | Description |
| ---------- | ------- | ------------------------------- |
| maintainer | address | Wallet maintainer to authorize. |
### authorizeSpvMaintainer
```solidity
function authorizeSpvMaintainer(address maintainer) external
```
Authorize an SPV maintainer that can interact with this reimbursement pool. Can be authorized by the owner only.
#### Parameters
| Name | Type | Description |
| ---------- | ------- | ---------------------------- |
| maintainer | address | SPV maintainer to authorize. |
### unauthorizeWalletMaintainer
```solidity
function unauthorizeWalletMaintainer(address maintainerToUnauthorize) external
```
Unauthorize a wallet maintainer that was previously authorized to interact with the Maintainer Proxy contract. Can be unauthorized by the owner only.
The last maintainer is swapped with the one to be unauthorized. The unauthorized maintainer is then removed from the list. An index of the last maintainer is changed with the removed maintainer. Ex. 'walletMaintainers' list: \[0x1, 0x2, 0x3, 0x4, 0x5] 'isWalletMaintainer' map: \[0x1 -> 1, 0x2 -> 2, 0x3 -> 3, 0x4 -> 4, 0x5 -> 5] unauthorize: 0x3 new 'walletMaintainers' list: \[0x1, 0x2, 0x5, 0x4] new 'isWalletMaintainer' map: \[0x1 -> 1, 0x2 -> 2, 0x4 -> 4, 0x5 -> 3]
#### Parameters
| Name | Type | Description |
| ----------------------- | ------- | -------------------------- |
| maintainerToUnauthorize | address | Maintainer to unauthorize. |
### unauthorizeSpvMaintainer
```solidity
function unauthorizeSpvMaintainer(address maintainerToUnauthorize) external
```
Unauthorize an SPV maintainer that was previously authorized to interact with the Maintainer Proxy contract. Can be unauthorized by the owner only.
The last maintainer is swapped with the one to be unauthorized. The unauthorized maintainer is then removed from the list. An index of the last maintainer is changed with the removed maintainer. Ex. 'spvMaintainers' list: \[0x1, 0x2, 0x3, 0x4, 0x5] 'isSpvMaintainer' map: \[0x1 -> 1, 0x2 -> 2, 0x3 -> 3, 0x4 -> 4, 0x5 -> 5] unauthorize: 0x3 new 'spvMaintainers' list: \[0x1, 0x2, 0x5, 0x4] new 'isSpvMaintainer' map: \[0x1 -> 1, 0x2 -> 2, 0x4 -> 4, 0x5 -> 3]
#### Parameters
| Name | Type | Description |
| ----------------------- | ------- | -------------------------- |
| maintainerToUnauthorize | address | Maintainer to unauthorize. |
### updateBridge
```solidity
function updateBridge(contract Bridge _bridge) external
```
Allows the Governance to upgrade the Bridge address.
The function does not implement any governance delay and does not check the status of the Bridge. The Governance implementation needs to ensure all requirements for the upgrade are satisfied before executing this function.
### updateGasOffsetParameters
```solidity
function updateGasOffsetParameters(uint256 newSubmitDepositSweepProofGasOffset, uint256 newSubmitRedemptionProofGasOffset, uint256 newResetMovingFundsTimeoutGasOffset, uint256 newSubmitMovingFundsProofGasOffset, uint256 newNotifyMovingFundsBelowDustGasOffset, uint256 newSubmitMovedFundsSweepProofGasOffset, uint256 newRequestNewWalletGasOffset, uint256 newNotifyWalletCloseableGasOffset, uint256 newNotifyWalletClosingPeriodElapsedGasOffset, uint256 newDefeatFraudChallengeGasOffset, uint256 newDefeatFraudChallengeWithHeartbeatGasOffset) external
```
Updates the values of gas offset parameters.
Can be called only by the contract owner. The caller is responsible for validating parameters.
#### Parameters
| Name | Type | Description |
| --------------------------------------------- | ------- | ----------------------------------------------------- |
| newSubmitDepositSweepProofGasOffset | uint256 | New submit deposit sweep proof gas offset. |
| newSubmitRedemptionProofGasOffset | uint256 | New submit redemption proof gas offset. |
| newResetMovingFundsTimeoutGasOffset | uint256 | New reset moving funds timeout gas offset. |
| newSubmitMovingFundsProofGasOffset | uint256 | New submit moving funds proof gas offset. |
| newNotifyMovingFundsBelowDustGasOffset | uint256 | New notify moving funds below dust gas offset. |
| newSubmitMovedFundsSweepProofGasOffset | uint256 | New submit moved funds sweep proof gas offset. |
| newRequestNewWalletGasOffset | uint256 | New request new wallet gas offset. |
| newNotifyWalletCloseableGasOffset | uint256 | New notify closeable wallet gas offset. |
| newNotifyWalletClosingPeriodElapsedGasOffset | uint256 | New notify wallet closing period elapsed gas offset. |
| newDefeatFraudChallengeGasOffset | uint256 | New defeat fraud challenge gas offset. |
| newDefeatFraudChallengeWithHeartbeatGasOffset | uint256 | New defeat fraud challenge with heartbeat gas offset. |
### allWalletMaintainers
```solidity
function allWalletMaintainers() external view returns (address[])
```
Gets an entire array of wallet maintainer addresses.
### allSpvMaintainers
```solidity
function allSpvMaintainers() external view returns (address[])
```
Gets an entire array of SPV maintainer addresses.
# MovingFunds
## MovingFunds
The library handles the logic for moving Bitcoin between Bridge wallets.
A wallet that failed a heartbeat, did not process requested redemption on time, or qualifies to be closed, begins the procedure of moving funds to other wallets in the Bridge. The wallet needs to commit to which other Live wallets it is moving the funds to and then, provide an SPV proof of moving funds to the previously committed wallets. Once the proof is submitted, all target wallets are supposed to sweep the received UTXOs with their own main UTXOs in order to update their BTC balances.
### MovingFundsTxOutputsProcessingInfo
```solidity
struct MovingFundsTxOutputsProcessingInfo {
bytes32 movingFundsTxHash;
bytes movingFundsTxOutputVector;
}
```
### MovedFundsSweepRequestState
```solidity
enum MovedFundsSweepRequestState {
Unknown,
Pending,
Processed,
TimedOut
}
```
### MovedFundsSweepRequest
```solidity
struct MovedFundsSweepRequest {
bytes20 walletPubKeyHash;
uint64 value;
uint32 createdAt;
enum MovingFunds.MovedFundsSweepRequestState state;
}
```
### MovingFundsCommitmentSubmitted
```solidity
event MovingFundsCommitmentSubmitted(bytes20 walletPubKeyHash, bytes20[] targetWallets, address submitter)
```
### MovingFundsTimeoutReset
```solidity
event MovingFundsTimeoutReset(bytes20 walletPubKeyHash)
```
### MovingFundsCompleted
```solidity
event MovingFundsCompleted(bytes20 walletPubKeyHash, bytes32 movingFundsTxHash)
```
### MovingFundsTimedOut
```solidity
event MovingFundsTimedOut(bytes20 walletPubKeyHash)
```
### MovingFundsBelowDustReported
```solidity
event MovingFundsBelowDustReported(bytes20 walletPubKeyHash)
```
### MovedFundsSwept
```solidity
event MovedFundsSwept(bytes20 walletPubKeyHash, bytes32 sweepTxHash)
```
### MovedFundsSweepTimedOut
```solidity
event MovedFundsSweepTimedOut(bytes20 walletPubKeyHash, bytes32 movingFundsTxHash, uint32 movingFundsTxOutputIndex)
```
### submitMovingFundsCommitment
```solidity
function submitMovingFundsCommitment(struct BridgeState.Storage self, bytes20 walletPubKeyHash, struct BitcoinTx.UTXO walletMainUtxo, uint32[] walletMembersIDs, uint256 walletMemberIndex, bytes20[] targetWallets) external
```
Submits the moving funds target wallets commitment. Once all requirements are met, that function registers the target wallets commitment and opens the way for moving funds proof submission.
Requirements:
* The source wallet must be in the MovingFunds state,
* The source wallet must not have pending redemption requests,
* The source wallet must not have pending moved funds sweep requests,
* The source wallet must not have submitted its commitment already,
* The expression `keccak256(abi.encode(walletMembersIDs))` must be exactly the same as the hash stored under `membersIdsHash` for the given source wallet in the ECDSA registry. Those IDs are not directly stored in the contract for gas efficiency purposes but they can be read from appropriate `DkgResultSubmitted` and `DkgResultApproved` events,
* The `walletMemberIndex` must be in range \[1, walletMembersIDs.length],
* The caller must be the member of the source wallet signing group at the position indicated by `walletMemberIndex` parameter,
* The `walletMainUtxo` components must point to the recent main UTXO of the source wallet, as currently known on the Ethereum chain,
* Source wallet BTC balance must be greater than zero,
* At least one Live wallet must exist in the system,
* Submitted target wallets count must match the expected count `N = min(liveWalletsCount, ceil(walletBtcBalance / walletMaxBtcTransfer))` where `N > 0`,
* Each target wallet must be not equal to the source wallet,
* Each target wallet must follow the expected order i.e. all target wallets 20-byte public key hashes represented as numbers must form a strictly increasing sequence without duplicates,
* Each target wallet must be in Live state.
#### Parameters
| Name | Type | Description |
| ----------------- | -------------------------- | ------------------------------------------------------------------------------------------------------------ |
| self | struct BridgeState.Storage | |
| walletPubKeyHash | bytes20 | 20-byte public key hash of the source wallet. |
| walletMainUtxo | struct BitcoinTx.UTXO | Data of the source wallet's main UTXO, as currently known on the Ethereum chain. |
| walletMembersIDs | uint32\[] | Identifiers of the source wallet signing group members. |
| walletMemberIndex | uint256 | Position of the caller in the source wallet signing group members list. |
| targetWallets | bytes20\[] | List of 20-byte public key hashes of the target wallets that the source wallet commits to move the funds to. |
### resetMovingFundsTimeout
```solidity
function resetMovingFundsTimeout(struct BridgeState.Storage self, bytes20 walletPubKeyHash) external
```
Resets the moving funds timeout for the given wallet if the target wallet commitment cannot be submitted due to a lack of live wallets in the system.
Requirements:
* The wallet must be in the MovingFunds state,
* The target wallets commitment must not be already submitted for the given moving funds wallet,
* Live wallets count must be zero,
* The moving funds timeout reset delay must be elapsed.
#### Parameters
| Name | Type | Description |
| ---------------- | -------------------------- | -------------------------------------------------- |
| self | struct BridgeState.Storage | |
| walletPubKeyHash | bytes20 | 20-byte public key hash of the moving funds wallet |
### submitMovingFundsProof
```solidity
function submitMovingFundsProof(struct BridgeState.Storage self, struct BitcoinTx.Info movingFundsTx, struct BitcoinTx.Proof movingFundsProof, struct BitcoinTx.UTXO mainUtxo, bytes20 walletPubKeyHash) external
```
Used by the wallet to prove the BTC moving funds transaction and to make the necessary state changes. Moving funds is only accepted if it satisfies SPV proof.
The function validates the moving funds transaction structure by checking if it actually spends the main UTXO of the declared wallet and locks the value on the pre-committed target wallets using a reasonable transaction fee. If all preconditions are met, this functions closes the source wallet.
It is possible to prove the given moving funds transaction only one time.
Requirements:
* `movingFundsTx` components must match the expected structure. See `BitcoinTx.Info` docs for reference. Their values must exactly correspond to appropriate Bitcoin transaction fields to produce a provable transaction hash,
* The `movingFundsTx` should represent a Bitcoin transaction with exactly 1 input that refers to the wallet's main UTXO. That transaction should have 1..n outputs corresponding to the pre-committed target wallets. Outputs must be ordered in the same way as their corresponding target wallets are ordered within the target wallets commitment,
* `movingFundsProof` components must match the expected structure. See `BitcoinTx.Proof` docs for reference. The `bitcoinHeaders` field must contain a valid number of block headers, not less than the `txProofDifficultyFactor` contract constant,
* `mainUtxo` components must point to the recent main UTXO of the given wallet, as currently known on the Ethereum chain. Additionally, the recent main UTXO on Ethereum must be set,
* `walletPubKeyHash` must be connected with the main UTXO used as transaction single input,
* The wallet that `walletPubKeyHash` points to must be in the MovingFunds state,
* The target wallets commitment must be submitted by the wallet that `walletPubKeyHash` points to,
* The total Bitcoin transaction fee must be lesser or equal to `movingFundsTxMaxTotalFee` governable parameter.
#### Parameters
| Name | Type | Description |
| ---------------- | -------------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------- |
| self | struct BridgeState.Storage | |
| movingFundsTx | struct BitcoinTx.Info | Bitcoin moving funds transaction data. |
| movingFundsProof | struct BitcoinTx.Proof | Bitcoin moving funds proof data. |
| mainUtxo | struct BitcoinTx.UTXO | Data of the wallet's main UTXO, as currently known on the Ethereum chain. |
| walletPubKeyHash | bytes20 | 20-byte public key hash (computed using Bitcoin HASH160 over the compressed ECDSA public key) of the wallet which performed the moving funds transaction. |
### processMovingFundsTxOutputs
```solidity
function processMovingFundsTxOutputs(struct BridgeState.Storage self, struct MovingFunds.MovingFundsTxOutputsProcessingInfo processInfo) internal returns (bytes32 targetWalletsHash, uint256 outputsTotalValue)
```
Processes the moving funds Bitcoin transaction output vector and extracts information required for further processing.
Requirements:
* The `movingFundsTxOutputVector` must be parseable, i.e. must be validated by the caller as stated in their parameter doc,
* Each output must refer to a 20-byte public key hash,
* The total outputs value must be evenly divided over all outputs.
#### Parameters
| Name | Type | Description |
| ----------- | ----------------------------------------------------- | ---------------------------------------------------------------------- |
| self | struct BridgeState.Storage | |
| processInfo | struct MovingFunds.MovingFundsTxOutputsProcessingInfo | Processing info containing the moving funds tx hash and output vector. |
#### Return Values
| Name | Type | Description |
| ----------------- | ------- | ------------------------------------------------------------------------------ |
| targetWalletsHash | bytes32 | keccak256 hash over the list of actual target wallets used in the transaction. |
| outputsTotalValue | uint256 | Sum of all outputs values. |
### notifyMovingFundsTimeout
```solidity
function notifyMovingFundsTimeout(struct BridgeState.Storage self, bytes20 walletPubKeyHash, uint32[] walletMembersIDs) external
```
Notifies about a timed out moving funds process. Terminates the wallet and slashes signing group members as a result.
Requirements:
* The wallet must be in the MovingFunds state,
* The moving funds timeout must be actually exceeded,
* The expression `keccak256(abi.encode(walletMembersIDs))` must be exactly the same as the hash stored under `membersIdsHash` for the given `walletID`. Those IDs are not directly stored in the contract for gas efficiency purposes but they can be rea프로젝트로 돌아가기