Skip to content
This repository has been archived by the owner on Nov 26, 2024. It is now read-only.

Math Host I/Os #38

Merged
merged 1 commit into from
Apr 12, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions src/mocks/Program.sol
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ contract ProgramTest {
bytes calldata data
) external view returns (bytes memory) {
(bool success, bytes memory result) = address(program).staticcall{gas: gas}(data);
require(success, "call failed");

address arbPrecompile = address(0x69);
address ethPrecompile = address(0x01);
Expand Down Expand Up @@ -99,4 +100,27 @@ contract ProgramTest {
}
return result;
}

function mathTest(address program) external {
uint256 value = 0xeddecf107b5740cef7f5a01e3ea7e287665c4e75a8eb6afae2fda2e3d4367786;
value = mulmod(
value,
0xc6178c2de1078cd36c3bd302cde755340d7f17fcb3fcc0b9c333ba03b217029f,
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f
);
value = addmod(
value,
0xfffffffffffffffffffffffffffffffffffffffffffffffffffffffefffffc2f,
0xc6178c2de1078cd36c3bd302cde755340d7f17fcb3fcc0b9c333ba03b217029f
);
unchecked {
value /= 0xeddecf107b5740ce;
value = value**0xfffffffefffffc2f;
value = value % 0xc6178c2de1078cd3;
}

(bool success, bytes memory result) = address(program).call("");
require(success, "call failed");
require(keccak256(result) == keccak256(abi.encodePacked(value)));
}
}
Loading