Skip to content

Commit

Permalink
VERIDISE-005: define revert errcodes
Browse files Browse the repository at this point in the history
define separate errcodes for reverts.
  • Loading branch information
rdubois-crypto committed Aug 23, 2024
1 parent 6d03894 commit 02c0bf0
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 6 deletions.
11 changes: 8 additions & 3 deletions src/elliptic/SCL_mulmuladdX_fullgenW.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
pragma solidity >=0.8.19 <0.9.0;


import {_ModExpError} from "../include/SCL_errcodes.sol";

//Starting from mload(0x40) this is the mapping in allocated memory
//https://medium.com/@ac1d_eth/technical-exploration-of-inline-assembly-in-solidity-b7d2b0b2bda8
//mapping from 0x40 in memory
Expand All @@ -35,6 +37,9 @@ uint constant __a=0x60;
uint constant __gx=0x80;
uint constant __gy=0xa0;




//this function is for use only after validation of the Q input:
//Q shall belongs to the curve, and different from -P, -P128, -(P+P128), ...
//those 16 values are tested by the ValidateKey function
Expand Down Expand Up @@ -304,9 +309,9 @@ function ecGenMulmuladdB4W(
mstore(add(T, 0xa0), _p)

// Call the precompiled contract 0x05 = ModExp
if iszero(staticcall(not(0), 0x05, T, 0xc0, T, 0x20)) { revert(0, 0) }

Y := mulmod(Y, mload(T), _p)//Y/ZZZ
if iszero(staticcall(not(0), 0x05, T, 0xc0, T, 0x20)) {
revert(_ModExpError, 0x20) }
Y := mulmod(Y, mload(T), _p)//Y/ZZZ
ZZ :=mulmod(ZZ, mload(T),_p) //1/z
ZZ:= mulmod(ZZ,ZZ,_p) //1/zz
X := mulmod(X, ZZ, _p) //X/zz
Expand Down
5 changes: 3 additions & 2 deletions src/elliptic/SCL_mulmuladdX_fullgen_b4.sol
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
pragma solidity >=0.8.19 <0.9.0;


import {_ModExpError} from "../include/SCL_errcodes.sol";

//Starting from mload(0x40) this is the mapping in allocated memory
//https://medium.com/@ac1d_eth/technical-exploration-of-inline-assembly-in-solidity-b7d2b0b2bda8
//mapping from 0x40 in memory
Expand All @@ -41,7 +43,6 @@ uint constant _gpow2p128_y=0x120;




//this function is for use only after validation of the Q input:
//Q shall belongs to the curve, and different from -P, -P128, -(P+P128), ...
//those 16 values are tested by the ValidateKey function
Expand Down Expand Up @@ -274,7 +275,7 @@ function ecGenMulmuladdX_store(
mstore(add(T, 0xa0), _p)

// Call the precompiled contract 0x05 = ModExp
if iszero(staticcall(not(0), 0x05, T, 0xc0, T, 0x20)) { revert(0, 0) }
if iszero(staticcall(not(0), 0x05, T, 0xc0, T, 0x20)) { revert(_ModExpError, 0x20) }

//Y:=mulmod(Y,zzz,p)//Y/zzz
//zz :=mulmod(zz, mload(T),p) //1/z
Expand Down
18 changes: 18 additions & 0 deletions src/include/SCL_errcodes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/********************************************************************************************/
/*
/* ╔═╗╔╦╗╔═╗╔═╗╔╦╗╦ ╦ ╔═╗╦═╗╦ ╦╔═╗╔╦╗╔═╗╦ ╦╔╗
/* ╚═╗║║║║ ║║ ║ ║ ╠═╣ ║ ╠╦╝╚╦╝╠═╝ ║ ║ ║║ ║╠╩╗
/* ╚═╝╩ ╩╚═╝╚═╝o╩ ╩ ╩ ╚═╝╩╚═ ╩ ╩ ╩ ╚═╝╩═╝╩╚═╝
/*
/* Copyright (C) 2024 - Renaud Dubois - This file is part of SCL (Smoo.th CryptoLib) project
/* License: This software is licensed under MIT License (and allways will)
/* Description : testing the validity of an input point
/********************************************************************************************/


//error calling modExpPrecompile
uint256 constant _ModExpError=0x7FF;


//error due to calling square root computation on non residue number
uint256 constant _NotQuadraticResidueError=0x7FC;
5 changes: 4 additions & 1 deletion src/modular/SCL_sqrtMod_5mod8.sol
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
pragma solidity >=0.8.19 <0.9.0;

import {MODEXP_PRECOMPILE} from "../include/SCL_mask.h.sol";

import {_ModExpError} from "../include/SCL_errcodes.sol";

import { p, pp3div8, n, pMINUS_2, nMINUS_2, sqrtm1 } from "../fields/SCL_wei25519.sol";


Expand Down Expand Up @@ -54,7 +57,7 @@ function SqrtMod(uint256 self) returns (uint256 result){
_result, // retOffset (we override M to avoid paying for the memory expansion)
0x20 // retSize (32 bytes)
)
) { revert(0, 0) }
) { revert(_ModExpError, 0x20) }

result := mload(_result)
// result :=addmod(result,0,p)
Expand Down

0 comments on commit 02c0bf0

Please sign in to comment.