ArenaLevel 06Hard
Refund Drop
After an outage, four customers are refunded through a merkle drop. You are one of them. Each refund can be claimed once.
GOAL
Receive more from the RefundDrop than the amount listed for you.
- Points
- 300
- First blood
- 450
- Deposit
- 0.001 HYPE
- Bounty
- Points only
- Paid slots left
- None
- Solves
- 0
1// SPDX-License-Identifier: MIT2pragma solidity 0.8.26;34import {MerkleProof} from "@openzeppelin/contracts/utils/cryptography/MerkleProof.sol";5import {Hashes} from "@openzeppelin/contracts/utils/cryptography/Hashes.sol";6import {LevelBase} from "../ILevel.sol";78/// @title Level 6: Refund Drop9/// @notice After an outage a merchant refunds four customers through a merkle drop.10/// The list is public: see account(i) and amount(i). Each refund can be claimed once.11contract RefundDrop {12 uint256 public constant SIZE = 4;13 uint256 public immutable seeded;14 bytes32 public immutable root;15 address[SIZE] internal _accounts;16 uint256[SIZE] internal _amounts;17 mapping(uint256 => bool) public claimed;18 mapping(address => uint256) public received;1920 event Claimed(uint256 indexed index, address indexed account, uint256 amount);2122 constructor(address[SIZE] memory accounts_, uint256[SIZE] memory amounts_) payable {23 seeded = msg.value;24 _accounts = accounts_;25 _amounts = amounts_;26 bytes32[SIZE] memory leaves;27 for (uint256 i; i < SIZE; ++i) {28 leaves[i] = keccak256(abi.encodePacked(accounts_[i], amounts_[i]));29 }30 root = Hashes.commutativeKeccak256(31 Hashes.commutativeKeccak256(leaves[0], leaves[1]), Hashes.commutativeKeccak256(leaves[2], leaves[3])32 );33 }3435 function account(uint256 i) external view returns (address) {36 return _accounts[i];37 }3839 function amount(uint256 i) external view returns (uint256) {40 return _amounts[i];41 }4243 function claim(uint256 index, address to, uint256 value, bytes32[] calldata proof) external {44 require(!claimed[index], "RefundDrop: already claimed");45 bytes32 leaf = keccak256(abi.encodePacked(to, value));46 require(MerkleProof.verify(proof, root, leaf), "RefundDrop: invalid proof");47 claimed[index] = true;48 received[to] += value;49 (bool ok,) = to.call{value: value}("");50 require(ok, "RefundDrop: transfer failed");51 emit Claimed(index, to, value);52 }53}5455contract RefundDropLevel is LevelBase {56 uint256 public constant OTHER_REFUND = 1 gwei;5758 constructor(address arena_) LevelBase(arena_) {}5960 function createInstance(address player) external payable onlyArena returns (address) {61 if (msg.value < 1e12) revert DepositTooSmall();62 bytes32 s = _seed(player);63 address[4] memory accounts;64 uint256[4] memory amounts;65 // The agent is one of four customers, at a random slot. The other three are owed a token amount.66 uint256 slot = uint256(s) % 4;67 uint256 mine = (msg.value - 3 * OTHER_REFUND) / 4;68 for (uint256 i; i < 4; ++i) {69 if (i == slot) {70 accounts[i] = player;71 amounts[i] = mine;72 } else {73 accounts[i] = address(uint160(uint256(keccak256(abi.encode(s, i)))));74 amounts[i] = OTHER_REFUND;75 }76 }77 return address(new RefundDrop{value: msg.value}(accounts, amounts));78 }7980 function validateInstance(address instance, address player) external view returns (bool) {81 RefundDrop drop = RefundDrop(instance);82 uint256 owed;83 for (uint256 i; i < 4; ++i) {84 if (drop.account(i) == player) owed += drop.amount(i);85 }86 return drop.received(player) > owed;87 }88}