This repository has been archived by the owner on Jan 9, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 325
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: enable ec_add / ec_mul (#1398)
<!--- Please provide a general summary of your changes in the title above --> <!-- Give an estimate of the time you spent on this PR in terms of work days. Did you spend 0.5 days on this PR or rather 2 days? --> Time spent on this PR: ## Pull request type <!-- Please try to limit your pull request to one type, submit multiple pull requests if needed. --> Please check the type of change your PR introduces: - [ ] Bugfix - [ ] Feature - [ ] Code style update (formatting, renaming) - [ ] Refactoring (no functional changes, no api changes) - [ ] Build related changes - [ ] Documentation content changes - [ ] Other (please describe): ## What is the current behavior? <!-- Please describe the current behavior that you are modifying, or link to a relevant issue. --> Resolves #1230 Resolves #1231 Resolves #1365 ## What is the new behavior? <!-- Please describe the behavior or changes that are being added by this PR. --> - Adds ECMUL and ECADD execution from Cairo1Helpers - Fixes an issue where __reverted__ precompile execution was not consuming all gas due to a mismanagement of error codes - note: reverted != execution fails silently (see ec_recover vs. ec_add, for example) - Fixes an issue where external_precompiles would not fail with error EXCEPTIONAL_HALT <!-- Reviewable:start --> - - - This change is [<img src="https://reviewable.io/review_button.svg" height="34" align="absmiddle" alt="Reviewable"/>](https://reviewable.io/reviews/kkrt-labs/kakarot/1398) <!-- Reviewable:end -->
- Loading branch information
Showing
21 changed files
with
259 additions
and
1,283 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// SPDX-License-Identifier: AGPL-3.0-only | ||
pragma solidity >=0.8.0; | ||
|
||
/// @title EVM Precompiles Integration | ||
/// @notice Contract for integration testing of EVM precompiles. | ||
/// @dev Implements functions for ECADD and ECMUL precompiles. | ||
contract EvmPrecompiles { | ||
/// @dev Address of the ECADD precompile | ||
address private constant ECADD_PRECOMPILE = address(0x06); | ||
/// @dev Address of the ECMUL precompile | ||
address private constant ECMUL_PRECOMPILE = address(0x07); | ||
|
||
/// @dev Gas cost for ECADD call is 150 | ||
uint256 private constant ECADD_GAS = 150; | ||
/// @dev Gas cost for ECMUL call is 6000 | ||
uint256 private constant ECMUL_GAS = 6000; | ||
|
||
/*////////////////////////////////////////////////////////////// | ||
FUNCTIONS FOR PRECOMPILES | ||
//////////////////////////////////////////////////////////////*/ | ||
/// @notice Performs elliptic curve addition | ||
/// @param x1 X coordinate of the first point | ||
/// @param y1 Y coordinate of the first point | ||
/// @param x2 X coordinate of the second point | ||
/// @param y2 Y coordinate of the second point | ||
/// @return success True if the operation was successful, false otherwise | ||
/// @return x X coordinate of the result point | ||
/// @return y Y coordinate of the result point | ||
function ecAdd(uint256 x1, uint256 y1, uint256 x2, uint256 y2) external view returns (bool, uint256 x, uint256 y) { | ||
bytes memory input = abi.encodePacked(x1, y1, x2, y2); | ||
(bool success, bytes memory result) = ECADD_PRECOMPILE.staticcall{gas: ECADD_GAS}(input); | ||
if (!success) { | ||
return (false, 0, 0); | ||
} | ||
(x, y) = abi.decode(result, (uint256, uint256)); | ||
return (true, x, y); | ||
} | ||
|
||
/// @notice Performs elliptic curve scalar multiplication | ||
/// @param x1 X coordinate of the point | ||
/// @param y1 Y coordinate of the point | ||
/// @param s Scalar for multiplication | ||
/// @return success True if the operation was successful, false otherwise | ||
/// @return x X coordinate of the result point | ||
/// @return y Y coordinate of the result point | ||
function ecMul(uint256 x1, uint256 y1, uint256 s) external view returns (bool, uint256 x, uint256 y) { | ||
bytes memory input = abi.encodePacked(x1, y1, s); | ||
(bool success, bytes memory result) = ECMUL_PRECOMPILE.staticcall{gas: ECMUL_GAS}(input); | ||
if (!success) { | ||
return (false, 0, 0); | ||
} | ||
(x, y) = abi.decode(result, (uint256, uint256)); | ||
return (true, x, y); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.