Verified contractExactUNLICENSED
BurnBankVault
Address0x1e99b8b12da985bd7c2eabe241efab19d5b1459e
- Balance
0.00074 ETH
- Transactions
7
- Compiler
solc 0.8.16
- Same code
Only this contract
Details
- Compiler
- solc 0.8.16+commit.07a7930e
- Language
- solidity
- Optimization
- Yes, 200 runs
- License
- UNLICENSED
- Match
- Exactcreation code: yes, runtime code: yes
- Verified on Sourcify
- Created in block
- 26,093,695
- Creation transaction
- 0xf5d50b5460…c8c1f67ead
contracts/BurnBankVault.sol
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.16;
import "@openzeppelin/[email protected]/access/Ownable.sol";
/// @notice The give() entry point every Burn Bank (Ktv2) exposes.
interface IBurnBank {
function give() external payable;
}
/**
* @title BurnBankVault
* @notice Escrow for Burn Bank Battles challenges.
*
* A donor funds a vault under the keccak256 hash of a secret 32-byte key.
* Nobody, the owner included, can withdraw that ETH. The only way out is
* unlock(key, bank): anyone who knows the key may direct the whole deposit
* into the give() function of a whitelisted Burn Bank, once.
*
* Design decisions, deliberately:
* - One deposit per key hash. fund() reverts if the hash is already used, so
* the challenge amount a site posts is exactly what the key unlocks. Top-ups
* need a fresh key and a fresh challenge.
* - No withdraw, no rescue, no expiry. A lost key means the ETH is stuck for
* good. That is the escrow guarantee the challenge relies on.
* - The unlock is a race by design. Once a key is public anyone can spend it,
* and a mempool watcher can front-run the unlocker with a different bank.
* The Battle rules treat "snatching" as fair play; a site that needs the
* matcher to choose the bank must reveal the key privately.
* - Attribution comes from this contract's VaultUnlocked event. The bank's
* own Gave event names this vault as the giver, not the donor.
* - The whitelist is checked at unlock time. Removing a bank strands nothing:
* the unlocker simply picks another.
* - Plain ETH transfers revert. With no withdraw path, ETH sent without a key
* hash would be lost, so receive() refuses it.
*/
contract BurnBankVault is Ownable {
struct Vault {
address funder;
uint amount;
uint fundedBlock;
bool spent;
}
mapping(bytes32 => Vault) public vaults;
mapping(address => bool) public banks;
uint public totalLocked;
event BankAdded(address indexed bank);
event BankRemoved(address indexed bank);
event VaultFunded(bytes32 indexed keyHash, address indexed funder, uint amount);
event VaultUnlocked(bytes32 indexed keyHash, address indexed bank, uint amount, address indexed unlocker);
constructor(address[] memory initialBanks) Ownable() {
for (uint i = 0; i < initialBanks.length; i++) {
_addBank(initialBanks[i]);
}
}
// ------------------------------------------------------------------ owner
function addBank(address bank) external onlyOwner {
_addBank(bank);
}
function removeBank(address bank) external onlyOwner {
require(banks[bank], "Not a bank");
banks[bank] = false;
emit BankRemoved(bank);
}
function _addBank(address bank) private {
require(bank != address(0), "Zero bank");
require(!banks[bank], "Already a bank");
banks[bank] = true;
emit BankAdded(bank);
}
// ----------------------------------------------------------------- public
/// @notice Lock msg.value under keyHash = keccak256(abi.encodePacked(key)).
function fund(bytes32 keyHash) external payable {
require(msg.value > 0, "No ETH");
require(vaults[keyHash].amount == 0, "Hash already funded");
vaults[keyHash] = Vault({funder: msg.sender, amount: msg.value, fundedBlock: block.number, spent: false});
totalLocked += msg.value;
emit VaultFunded(keyHash, msg.sender, msg.value);
}
/// @notice Spend the vault for `key` by calling give() on a whitelisted bank.
function unlock(bytes32 key, address bank) external {
bytes32 keyHash = hashKey(key);
Vault storage v = vaults[keyHash];
require(v.amount > 0, "Unknown key");
require(!v.spent, "Already unlocked");
require(banks[bank], "Not a bank");
// Effects before the external call: give() forwards ETH onward with a
// low-level call, so the vault must already be marked spent.
v.spent = true;
uint amount = v.amount;
totalLocked -= amount;
IBurnBank(bank).give{value: amount}();
emit VaultUnlocked(keyHash, bank, amount, msg.sender);
}
/// @notice The hash a key must be funded under.
function hashKey(bytes32 key) public pure returns (bytes32) {
return keccak256(abi.encodePacked(key));
}
/// @notice Convenience view for sites: whether a hash is funded and unspent.
function isUnlockable(bytes32 keyHash) external view returns (bool) {
Vault storage v = vaults[keyHash];
return v.amount > 0 && !v.spent;
}
receive() external payable {
revert("Use fund(keyHash)");
}
}@openzeppelin/[email protected]/access/Ownable.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.0) (access/Ownable.sol)
pragma solidity ^0.8.0;
import "../utils/Context.sol";
/**
* @dev Contract module which provides a basic access control mechanism, where
* there is an account (an owner) that can be granted exclusive access to
* specific functions.
*
* By default, the owner account will be the one that deploys the contract. This
* can later be changed with {transferOwnership}.
*
* This module is used through inheritance. It will make available the modifier
* `onlyOwner`, which can be applied to your functions to restrict their use to
* the owner.
*/
abstract contract Ownable is Context {
address private _owner;
event OwnershipTransferred(address indexed previousOwner, address indexed newOwner);
/**
* @dev Initializes the contract setting the deployer as the initial owner.
*/
constructor() {
_transferOwnership(_msgSender());
}
/**
* @dev Throws if called by any account other than the owner.
*/
modifier onlyOwner() {
_checkOwner();
_;
}
/**
* @dev Returns the address of the current owner.
*/
function owner() public view virtual returns (address) {
return _owner;
}
/**
* @dev Throws if the sender is not the owner.
*/
function _checkOwner() internal view virtual {
require(owner() == _msgSender(), "Ownable: caller is not the owner");
}
/**
* @dev Leaves the contract without owner. It will not be possible to call
* `onlyOwner` functions. Can only be called by the current owner.
*
* NOTE: Renouncing ownership will leave the contract without an owner,
* thereby disabling any functionality that is only available to the owner.
*/
function renounceOwnership() public virtual onlyOwner {
_transferOwnership(address(0));
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Can only be called by the current owner.
*/
function transferOwnership(address newOwner) public virtual onlyOwner {
require(newOwner != address(0), "Ownable: new owner is the zero address");
_transferOwnership(newOwner);
}
/**
* @dev Transfers ownership of the contract to a new account (`newOwner`).
* Internal function without access restriction.
*/
function _transferOwnership(address newOwner) internal virtual {
address oldOwner = _owner;
_owner = newOwner;
emit OwnershipTransferred(oldOwner, newOwner);
}
}
@openzeppelin/[email protected]/utils/Context.sol
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v4.9.4) (utils/Context.sol)
pragma solidity ^0.8.0;
/**
* @dev Provides information about the current execution context, including the
* sender of the transaction and its data. While these are generally available
* via msg.sender and msg.data, they should not be accessed in such a direct
* manner, since when dealing with meta-transactions the account sending and
* paying for execution may not be the actual sender (as far as an application
* is concerned).
*
* This contract is only required for intermediate, library-like contracts.
*/
abstract contract Context {
function _msgSender() internal view virtual returns (address) {
return msg.sender;
}
function _msgData() internal view virtual returns (bytes calldata) {
return msg.data;
}
function _contextSuffixLength() internal view virtual returns (uint256) {
return 0;
}
}
Compiler settingsShow
{
"optimizer": {
"runs": 200,
"enabled": true
},
"remappings": []
}Source code and metadata: Sourcify.
The source code belongs to the authors of the contract.