-
Notifications
You must be signed in to change notification settings - Fork 1
/
Level_5_Solution.sol
36 lines (27 loc) · 1.17 KB
/
Level_5_Solution.sol
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
// SPDX-License-Identifier: UNLICENSED
pragma solidity 0.8.17;
//interface Isolution5 {
// function solution(bytes32 b, bytes32 ex, bytes32 modulus) external returns (bytes32 result);
//}
contract Level_5_Solution {
function solution(bytes32 b, bytes32 ex, bytes32 modulus) external returns (bytes32 result) {
assembly {
// Prepare the input and output buffers
let input := mload(0x40)
mstore(input, 0x60) // Length of input buffer
mstore(add(input, 0x20), 0x20) // Offset of base
mstore(add(input, 0x40), 0x20) // Offset of exponent
mstore(add(input, 0x60), 0x20) // Offset of modulus
mstore(add(input, 0x80), b) // Base
mstore(add(input, 0xA0), ex) // Exponent
mstore(add(input, 0xC0), modulus) // Modulus
let output := mload(0x80)
// Call the modular exponentiation precompiled contract at address 0x05
if iszero(call(not(0), 0x05, 0, input, 0xE0, output, 0x20)) {
revert(0, 0)
}
// Retrieve the result from the output buffer
result := mload(output)
}
}
}