# SAG

It's a challenge from the DEF CON CTF Qualifier 2018! Want to gamble?

// SPDX-License-Identifier: MIT
pragma solidity ^0.8.11;

interface SAG {
    function gamble(uint256 guess, uint256 seed) external;
    function isWinner(address addr) external returns (bool);
}

contract SAGProxy {
    SAG private sag;
    address private owner;
    bool public completed;

    modifier onlyOwner {
        require(msg.sender == owner);
        _;
    }

    constructor() public {
        owner = msg.sender;
    	bytes memory data_sag = hex"...";
    	sag = SAG(deploy(data_sag));
        completed = false;
    }

    function gamble(uint256 guess, uint256 seed) public {
        sag.gamble(guess, seed);
    }

    function requestPrize(bytes32 msgHash, uint8 v, bytes32 r, bytes32 s) public returns (bool) {
        completed = ecrecover(msgHash, v, r, s) == msg.sender && sag.isWinner(msg.sender);
        return completed;
    }

    function deploy(bytes memory data) private returns (address) {
    	uint size = data.length;
    	address addr;
    	assembly {
            addr := create(0, add(data, 0x20), size)
        }
    	return addr;
    }
}