Course #1
Log10
SoliditySolidity's logo.Course
1
// SPDX-License-Identifier: MIT
2
pragma solidity ^0.8.21;
3
4
import { ICourse } from "src/interfaces/ICourse.sol";
5
import { FixedPointMathLib, LibPRNG } from "solady/Milady.sol";
6
7
uint8 constant INPUT_SIZE = 10;
8
9
interface Log10Like {
10
function perform(uint256[INPUT_SIZE] calldata) external pure returns (uint256[INPUT_SIZE] calldata);
11
}
12
13
contract Log10 is ICourse {
14
using LibPRNG for *;
15
16
// -------------------------------------------------------------------------
17
// Functions
18
// -------------------------------------------------------------------------
19
20
/// @inheritdoc ICourse
21
function name() external pure returns (string memory) {
22
return "Log10";
23
}
24
25
/// @inheritdoc ICourse
26
function run(address _target, uint256 _seed) external view returns (uint32) {
27
// Generate inputs
28
LibPRNG.PRNG memory prng;
29
prng.seed(_seed);
30
31
uint256[INPUT_SIZE] memory inputs;
32
for (uint8 i; i < INPUT_SIZE;) {
33
inputs[i] = prng.next();
34
35
unchecked{ i++; }
36
}
37
38
uint256 preGas = gasleft();
39
uint256[INPUT_SIZE] memory outputs = Log10Like(_target).perform(inputs);
40
uint256 usedGas;
41
unchecked {
42
usedGas = preGas - gasleft();
43
}
44
45
_verify(inputs, outputs);
46
47
return uint32(usedGas);
48
}
49
50
function _verify(uint256[INPUT_SIZE] memory _inputs, uint256[INPUT_SIZE] memory _outputs) internal pure {
51
for(uint8 i; i < INPUT_SIZE; i++) {
52
uint256 input = _inputs[i];
53
uint256 output = _outputs[i];
54
55
uint256 expected = FixedPointMathLib.log10(input);
56
if(output != expected) revert IncorrectSolution();
57
}
58
}
59
}
60
King of the Hill
0xd04dd74
2251
18
Waterfall