Coder Social home page Coder Social logo

seitozhen / fcl-ecdsa-verify-audit Goto Github PK

View Code? Open in Web Editor NEW

This project forked from base-org/fcl-ecdsa-verify-audit

0.0 0.0 0.0 23.75 MB

We audited the sepc256r1 ecdsa verify in FreshCryptoLib. This repo contains the test files we used to conduct it.

Go 7.61% Rust 3.49% Solidity 88.90%

fcl-ecdsa-verify-audit's Introduction

Important

This audit's scope is extremely narrow. Ensure use of this audit as a reference is appropriately scoped.

FreshCryptoLib ecdsa_verify Audit

This repo contains the set of tests used to audit the FCL ecdsa sepc256r1 verify method implemented by FreshCryptoLib here.

Scope

The scope of the audit is restricted only to methods used in the context of ecdsa_verify:

    function ecdsa_verify(bytes32 message, uint256 r, uint256 s, uint256 Qx, uint256 Qy)  internal view returns (bool){

        if (r == 0 || r >= FCL_Elliptic_ZZ.n || s == 0 || s >= FCL_Elliptic_ZZ.n) {
            return false;
        }
        
        if (!FCL_Elliptic_ZZ.ecAff_isOnCurve(Qx, Qy)) {
            return false;
        }

        uint256 sInv = FCL_Elliptic_ZZ.FCL_nModInv(s);

        uint256 scalar_u = mulmod(uint256(message), sInv, FCL_Elliptic_ZZ.n);
        uint256 scalar_v = mulmod(r, sInv, FCL_Elliptic_ZZ.n);
        uint256 x1;

        x1 = FCL_Elliptic_ZZ.ecZZ_mulmuladd_S_asm(Qx, Qy, scalar_u, scalar_v);

        x1= addmod(x1, n-r,n );
    
        return x1 == 0;
    }

As such, only the following files were in-scope for this exercise:

Methodology

The test suite was conducted in three major parts:

  1. Unit tests were written for each of the helper methods employed in the ecdsa_verify flow. By leveraging calls against the go/elliptic library, each solidity implementation was fuzz-tested for accuracy across a range of inputs.
  2. Targeted tests were written against inline assembly exceperts taken from the extensive ecZZ_mulmuladd_S_asm method found here.
  3. Our in-house cryptography team reviewed the methodology and implementation then conducted targeted edge case testing against relevant methods in the library.

Results

Official reports can be found in the docs.

Through our testing, we determined there were two issues with the implementation. Both were addressed and fixed in the subject libraries. The PRs for these changes can be found here and here.

Usage

Build

$ forge build

Test

$ forge test --ffi

Help

$ forge --help
$ anvil --help
$ cast --help

fcl-ecdsa-verify-audit's People

Contributors

stevieraykatz avatar wilsoncusack avatar arash-afshar avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.