Puzzle #8
Groovy Fruit (Punch) Fiesta
Author
1// SPDX-License-Identifier: MIT2
3pragma solidity ^0.8.17;4
5import "./IPuzzle.sol";6
7// Hello, it's me your Doordash shopper. I'm at the grocery store.8// I'm having trouble finding the ingredients you requested for your fruit punch.9// Can you help me find them?10// There's only 906459278810089239264754550292645448950 places to check...shouldn't be so bad.11//12// Enjoy this kind of challenge? Consider working at Zellic: [email protected]13//14contract Chal is IPuzzle {15 uint256 constant punch = 906_459_278_810_089_239_293_436_146_013_992_401_709;16
17 function name() external pure returns (string memory) {18 return "Groovy Fruit (Punch) Fiesta";19 }20
21 function generate(address _seed) external pure returns (uint256) {22 uint256 fiesta = uint256(keccak256(abi.encodePacked(_seed))) % punch;23 fiesta = (fiesta % 10_000_000_000_000_000_000_000) + 10_000_000_000_000_000_000_000;24 return fiesta;25 }26
27 function verify(uint256 _start, uint256 _solution) external pure returns (bool) {28 uint256 apple = _solution & 0x7fffffffffffffffffffffffffffffff;29 uint256 banana = (_solution >> 128) & 0x7fffffffffffffffffffffffffffffff;30 uint256 cherry = 1;31
32 if (apple < 100 || banana < 100) {33 return false;34 }35 if (smoothie(apple, banana) != 1) {36 return false;37 }38 return _start39 == (40 (apple * milkshake(banana + cherry)) % punch41 + (banana * milkshake(apple + cherry)) % punch42 + (cherry * milkshake(apple + banana)) % punch43 ) % punch;44 }45
46 function milkshake(uint256 apple) private pure returns (uint256) {47 int256 appleJuice_;48 (, appleJuice_,) = blender(apple, punch);49 require(appleJuice_ > 0);50 uint256 appleJuice = uint256(appleJuice_);51 require((apple * appleJuice) % punch == 1);52 return (appleJuice % punch + punch) % punch;53 }54
55 function blender(uint256 apple, uint256 banana)56 private57 pure58 returns (uint256 yummy, int256 appleJuice, int256 bananaJuice)59 {60 if (banana == 0) {61 return (apple, 1, 0);62 }63 (uint256 _yummy, int256 _appleJuice, int256 _bananaJuice) = blender(64 banana,65 apple % banana66 );67 (yummy, appleJuice, bananaJuice) =68 (_yummy, _bananaJuice, _appleJuice - int256(apple / banana) * _bananaJuice);69 }70
71 function smoothie(uint256 apple, uint256 banana) private pure returns (uint256 yummy) {72 (yummy,,) = blender(apple, banana);73 }74}75
Time Left
Solve locally (WIP)
- Clone GitHub repo + install deps
git clone https://github.com/waterfall-mkt/curta-puzzles.git && cd curta-puzzles && forge install
- Set
RPC_URL_MAINNET
in.env
.env
RPC_URL_MAINNET=""
- Write solution + run script
forge script <PATH_TO_PUZZLE> -f mainnet -vvv
This is still WIP.