-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path0.problem.sol
More file actions
38 lines (35 loc) · 970 Bytes
/
0.problem.sol
File metadata and controls
38 lines (35 loc) · 970 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.5;
contract SqrtProblem {
bytes4 constant digest = bytes4(keccak256("sqrt(uint256)"));
function check(
bool ok,
bytes calldata i,
bytes calldata o
) external view {
require(bytes4(i[:4]) == digest);
uint256 x = abi.decode(i[4:], (uint256));
if (!ok) {
return;
}
try this.decode(o) returns (uint256 y) {
if (y > 0xffffffffffffffffffffffffffffffff) {
return;
}
if (y * y > x) {
return;
}
if (y < 0xffffffffffffffffffffffffffffffff) {
if ((y + 1)**2 <= x) {
return;
}
}
revert();
} catch {
return;
}
}
function decode(bytes calldata data) external pure returns (uint256) {
return abi.decode(data, (uint256));
}
}