comments and stuff

comments
jazzysnake 2022-12-06 18:56:40 +01:00
parent 7b871ff9d6
commit 22afd9e197
1 changed files with 15 additions and 11 deletions

View File

@ -11,7 +11,6 @@ import "./verifier.sol";
contract CCTF9 is Verifier{
address public admin;
uint256 public volStart;
uint256 public volMaxPoints;
bool public started;
@ -61,34 +60,35 @@ contract CCTF9 is Verifier{
started = false;
}
/// transfers the admin privilege to _admin address
function setAdmin(address _admin) external onlyAdmin {
require(_admin != address(0));
admin = _admin;
}
/// can be used to set the status of the cctf to started or finished
function setCCTFStatus(bool _started) external onlyAdmin {
started = _started;
}
/// creates a new capturable flag according to the arguments
function setFlag(uint256 _flagId,Hash memory _flagHash, bool _onlyFirstSolver, uint256 _points, string memory _skill) external onlyAdmin{
flags[_flagId] = Flag(_flagHash, _onlyFirstSolver, _points, _skill);
emit FlagAdded(_flagId, _flagHash);
}
function register(string memory _RTFM) external {
/// registers the caller as a player
function register() external {
require(players[msg.sender].status == PlayerStatus.Unverified, 'Already registered or banned');
require(keccak256(abi.encodePacked('I_read_it')) == keccak256(abi.encodePacked(_RTFM))); // PoW can be used for harder challenges, this is Entry!
players[msg.sender].status = PlayerStatus.Verified;
}
/// sets the player's status either to Unverified, Verified or Banned
function setPlayerStatus(address player, PlayerStatus status) external onlyAdmin {
players[player].status = status;
}
////////// Submit flags
mapping(bytes32 => bool) usedNs; // Against replay attack (we only check message signer)
mapping (address => mapping (uint256 => bool)) Solves; // address -> challenge ID -> solved/not
uint256 public submission_success_count = 0; // For statistics
@ -104,9 +104,9 @@ contract CCTF9 is Verifier{
inputs[8+i] = addr[i];
}
bool valid = verifyTx(p,inputs);
require(valid, "Your proof is invalid");
assert(valid);
require(!Solves[msg.sender][_submitFor]); // can't submit the same flag multiple times
Solves[msg.sender][_submitFor] = true;
players[msg.sender].points += flags[_submitFor].points;
players[msg.sender].points = players[msg.sender].points < volMaxPoints ? players[msg.sender].points : volMaxPoints;
@ -119,11 +119,15 @@ contract CCTF9 is Verifier{
emit FlagSolved(_submitFor, msg.sender);
}
/// maps an address to unsigned int
function addressToUint32 (address _addr) public pure returns (uint32[5] memory)
{
uint256 targetUint = uint256(uint160(_addr));
uint32[5] memory addr = [uint32(targetUint/4294967296**4),uint32(targetUint/4294967296**3),uint32(targetUint/4294967296**2),uint32(targetUint/4294967296),uint32(targetUint)];
uint32[5] memory addr = [uint32(targetUint/4294967296**4),
uint32(targetUint/4294967296**3),
uint32(targetUint/4294967296**2),
uint32(targetUint/4294967296),
uint32(targetUint)];
return addr;
}
@ -143,4 +147,4 @@ contract CCTF9 is Verifier{
function getFlag(uint256 id) external view returns (Flag memory) {
return flags[id];
}
}
}