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

EcMul precompile implementation #46

Open
wants to merge 8 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
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
4 changes: 2 additions & 2 deletions SystemContractsHashes.json
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,8 @@
"contractName": "EcMul",
"bytecodePath": "contracts/precompiles/artifacts/EcMul.yul/EcMul.yul.zbin",
"sourceCodePath": "contracts/precompiles/EcMul.yul",
"bytecodeHash": "0x0100013759b40792c2c3d033990e992e5508263c15252eb2d9bfbba571350675",
"sourceCodeHash": "0xdad8be6e926155a362ea05b132ba8b6c634e978a41f79bb6390b870e18049e45"
"bytecodeHash": "0x01000139c33958289a14f9e84c8d6843d1cd998f30faab12671c25b221a3d96b",
"sourceCodeHash": "0x8f4c35e0019c423f27397f8ac8162a664a3aed654726563a8e51e17f6cb1f09b"
},
{
"contractName": "Ecrecover",
Expand Down
16 changes: 7 additions & 9 deletions contracts/precompiles/EcMul.yul
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,7 @@ object "EcMul" {
}
object "EcMul_deployed" {
code {
////////////////////////////////////////////////////////////////
// CONSTANTS
////////////////////////////////////////////////////////////////
// CONSTANTS

/// @notice Constant function for value one in Montgomery form.
/// @dev This value was precomputed using Python.
Expand Down Expand Up @@ -54,9 +52,7 @@ object "EcMul" {
ret := 111032442853175714102588374283752698368366046808579839647964533820976443843465
}

// ////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS
// ////////////////////////////////////////////////////////////////
// HELPER FUNCTIONS

/// @dev Executes the `precompileCall` opcode.
function precompileCall(precompileParams, gasToBurn) -> ret {
Expand Down Expand Up @@ -375,9 +371,7 @@ object "EcMul" {
xr := montgomeryAdd(xr, xr)
}

////////////////////////////////////////////////////////////////
// FALLBACK
////////////////////////////////////////////////////////////////
// FALLBACK

// Retrieve the coordinates from the calldata
let x := calldataload(0)
Expand All @@ -389,6 +383,8 @@ object "EcMul" {

if affinePointIsInfinity(x, y) {
// Infinity * scalar = Infinity
mstore(0x00, 0x00)
mstore(0x20, 0x00)
return(0x00, 0x40)
}

Expand All @@ -402,6 +398,8 @@ object "EcMul" {

if eq(scalar, 0) {
// P * 0 = Infinity
mstore(0x00, 0x00)
mstore(0x20, 0x00)
return(0x00, 0x40)
}
if eq(scalar, 1) {
Expand Down
Loading