elliptic-curve-solidity – 椭圆曲线稠度区块链毕设代写

区块链毕设代写本文提供国外最新区块链项目源码下载,包括solidity,eth,fabric等blockchain区块链,elliptic-curve-solidity – 椭圆曲线稠度区块链毕设代写 是一篇很好的国外资料

elliptic-curve-solidity elliptic-curve-solidity - 椭圆曲线稠度 elliptic-curve-solidity - 椭圆曲线稠度 elliptic-curve-solidity - 椭圆曲线稠度

elliptic-curve-solidity is an open source implementation of Elliptic Curve arithmetic operations written in Solidity.

DISCLAIMER: This is experimental software. Use it at your own risk!

The solidity contracts have been generalized in order to support any elliptic curve based on prime numbers up to 256 bits.

elliptic-curve-solidity has been designed as a library with only pure functions aiming at decreasing gas consumption as much as possible. Additionally, gas consumption comparison can be found in the benchmark section. This library does not check whether the points passed as arguments to the library belong to the curve. However, the library exposes a method called isOnCurve that can be utilized before using the library functions.

It contains 2 solidity libraries:

  1. EllipticCurve.sol: provides main elliptic curve operations in affine and Jacobian coordinates.
  2. FastEcMul.sol: provides a fast elliptic curve multiplication by using scalar decomposition and wNAF scalar representation.

EllipticCurve library provides functions for:

  • Modular
    • inverse
    • exponentiation
  • Jacobian coordinates
    • addition
    • double
    • multiplication
  • Affine coordinates
    • inverse
    • addition
    • subtraction
    • multiplication
  • Auxiliary
    • conversion to affine coordinates
    • derive coordinate Y from compressed EC point
    • check if EC point is on curve

FastEcMul library provides support for:

  • Scalar decomposition
  • Simultaneous multiplication (computes 2 EC multiplications using wNAF scalar representation)

Supported curves

The elliptic-curve-solidity contract supports up to 256-bit curves. However, it has been extensively tested for the following curves:

  • secp256k1
  • secp224k1
  • secp192k1
  • secp256r1 (aka P256)
  • secp192r1 (aka P192)
  • secp224r1 (aka P224)

Known limitations:

  • deriveY function do not work with the curves secp224r1 and secp224k1 because of the selected derivation algorithm. The computations for this curve are done with a modulo prime p such that p mod 4 = 1, thus a more complex algorithm is required (e.g. Tonelli-Shanks algorithm). Note that deriveY is just an auxiliary function, and thus does not limit the functionality of curve arithmetic operations.
  • the library only supports elliptic curves with cofactor = 1 (all supported curves have a cofactor = 1).

Usage

EllipticCurve.sol library can be used directly by importing it.

The Secp256k1 example depicts how to use the library by providing a function to derive a public key from a secret key:

pragma solidity 0.6.12;  import "elliptic-curve-solidity/contracts/EllipticCurve.sol";   contract Secp256k1 {    uint256 public constant GX = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798;   uint256 public constant GY = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8;   uint256 public constant AA = 0;   uint256 public constant BB = 7;   uint256 public constant PP = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;    function derivePubKey(uint256 privKey) public pure returns(uint256 qx, uint256 qy) {     (qx, qy) = EllipticCurve.ecMul(       privKey,       GX,       GY,       AA,       PP     );   } }

The cost of a key derivation operation in Secp256k1 is around 550k gas.

·--------------------------------------------------|--------------------------· |                      Gas                         · Block limit: 6721975 gas │ ···················································|··························· |                 ·          100 gwei/gas           ·     592.30 usd/eth      │ ··················|··········|··········|··········|············|·············· |  Method         ·  Min     ·  Max     ·  Avg     ·  # calls   ·  usd (avg)  │ ··················|··········|··········|··········|············|·············· |  derivePubKey   ·  476146  ·  518863  ·  499884  ·        18  ·      29.61  │ ··················|··········|··········|··········|············|··············

The cost of a simultaneous multiplication (using wNAF) consumes around 35% of the gas required by 2 EC multiplications.

Benchmark

Gas consumption and USD price estimation with a gas price of 100 Gwei, derived from ETH Gas Station:

·----------------------------------------|---------------------------|-------------|----------------------------· |  Solc version: 0.6.12+commit.27d51765  ·  Optimizer enabled: true  ·  Runs: 200  ·  Block limit: 6718946 gas  │ ·········································|···························|·············|····························· |  Methods                               ·              100 gwei/gas               ·       613.52 usd/eth       │ ··················|······················|·············|·············|·············|··············|·············· |  Contract       ·  Method              ·  Min        ·  Max        ·  Avg        ·  # calls     ·  usd (avg)  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  decomposeScalar     ·      55811  ·      65399  ·      61939  ·         134  ·       3.80  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  deriveY             ·      45275  ·      55545  ·      50410  ·           4  ·       3.09  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecAdd               ·      24305  ·      56323  ·      49119  ·         472  ·       3.01  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecInv               ·      22906  ·      23074  ·      22990  ·           2  ·       1.41  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecMul               ·      24911  ·     623087  ·     350939  ·         561  ·      21.53  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecSimMul            ·      76465  ·     488165  ·     243763  ·         125  ·      14.96  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecSub               ·      42634  ·      56236  ·      49717  ·         228  ·       3.05  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  invMod              ·      22153  ·      49255  ·      39627  ·          12  ·       2.43  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  isOnCurve           ·      23400  ·      24071  ·      23623  ·          16  ·       1.45  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  toAffine            ·      50145  ·      50850  ·      50498  ·           4  ·       3.10  │ ·----------------------------------------|-------------|-------------|-------------|--------------|-------------·

Acknowledgements

Some functions of the contract are based on:

  • Comparatively Study of ECC and Jacobian Elliptic Curve Cryptography by Anagha P. Zele and Avinash P. Wadhe
  • Numerology by NuCypher
  • solidity-arithmetic by Gnosis
  • ecsol written by Jordi Baylina
  • standard contracts written by Andreas Olofsson

License

elliptic-curve-solidity is published under the MIT license.

We use optional third-party analytics cookies to understand how you use GitHub.com so we can build better products. Learn more.


椭圆曲线坚固性椭圆曲线.sol:提供仿射和雅可比坐标下的主要椭圆曲线操作。
  • 快速多功能.sol:使用标量分解和wNAF标量表示提供快速椭圆曲线乘法。模逆幂运算
  • 减法
  • 乘法
  • 辅助转换到仿射坐标从压缩的EC点导出坐标Y检查EC点是否在曲线上
  • 转换为仿射坐标
  • 从压缩的EC点导出坐标Y
  • 检查EC点是否在曲线上
  • 标量分解
  • 同时乘法(使用wNAF标量表示计算2个EC乘法)
  • secp256k1
  • secp224k1
  • secp192k1
  • secp256r1(aka P256)
  • secp192r1(aka P192)
  • secp224r1(aka P224)
  • deriveY函数不适用于曲线secp224r1和secp224k1因为选择了派生算法。这条曲线的计算是用模素数p来完成的,因此p mod 4=1,因此需要一个更复杂的算法(例如,Tonelli-Shanks算法)。注意,deriveY只是一个辅助函数,因此不限制曲线算术运算的功能。
  • 该库仅支持余因子为1的椭圆曲线(所有支持的曲线都具有余因子=1)。Anagha P.Zele和Avinash P.Wadhe对椭圆曲线密码体制和雅可比椭圆曲线密码体制的比较研究
  • 椭圆曲线solidity是用solidity编写的椭圆曲线算术操作的开源实现。

    免责声明:这是实验性软件。使用它的风险自负!

    为了支持基于256位以下素数的椭圆曲线,对实性契约进行了推广。椭圆曲线稠度被设计成一个纯函数库,以尽可能降低气体消耗为目标。此外,气耗对比可在基准部分找到。此库不检查作为参数传递给库的点是否属于曲线。但是,该库公开了一个名为isOnCurve的方法,可以在使用库函数之前使用该方法。

    它包含2个可靠度库:

    EllipticCurve库提供以下功能:

    1. 快速多功能.sol:使用标量分解和wNAF标量表示提供快速椭圆曲线乘法。模逆幂运算
    2. 减法

    FastEcMul库提供支持:

    • 乘法
    • 从压缩的EC点导出坐标Y
    • secp256k1
    • secp224r1(aka P224)

    椭圆曲线索利多度契约最多支持256位曲线。但是,它已经针对以下曲线进行了广泛测试:

    • Scalar decomposition
    • Simultaneous multiplication (computes 2 EC multiplications using wNAF scalar representation)

    Supported curves

    已知限制:

    • secp256k1
    • secp224k1
    • secp192k1
    • secp256r1 (aka P256)
    • secp192r1 (aka P192)
    • secp224r1 (aka P224)

    椭圆曲线.sol库可以通过导入直接使用。

    • deriveY function do not work with the curves secp224r1 and secp224k1 because of the selected derivation algorithm. The computations for this curve are done with a modulo prime p such that p mod 4 = 1, thus a more complex algorithm is required (e.g. Tonelli-Shanks algorithm). Note that deriveY is just an auxiliary function, and thus does not limit the functionality of curve arithmetic operations.
    • the library only supports elliptic curves with cofactor = 1 (all supported curves have a cofactor = 1).

    Usage

    Secp256k1示例描述了如何通过提供一个从密钥派生公钥的函数来使用库:

    Secp256k1中的密钥派生操作的成本约为550k gas。

    pragma solidity 0.6.12;  import "elliptic-curve-solidity/contracts/EllipticCurve.sol";   contract Secp256k1 {    uint256 public constant GX = 0x79BE667EF9DCBBAC55A06295CE870B07029BFCDB2DCE28D959F2815B16F81798;   uint256 public constant GY = 0x483ADA7726A3C4655DA4FBFC0E1108A8FD17B448A68554199C47D08FFB10D4B8;   uint256 public constant AA = 0;   uint256 public constant BB = 7;   uint256 public constant PP = 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFEFFFFFC2F;    function derivePubKey(uint256 privKey) public pure returns(uint256 qx, uint256 qy) {     (qx, qy) = EllipticCurve.ecMul(       privKey,       GX,       GY,       AA,       PP     );   } }

    同时乘法(使用wNAF)的成本大约消耗2次EC乘法所需气体的35%。

    ·--------------------------------------------------|--------------------------· |                      Gas                         · Block limit: 6721975 gas │ ···················································|··························· |                 ·          100 gwei/gas           ·     592.30 usd/eth      │ ··················|··········|··········|··········|············|·············· |  Method         ·  Min     ·  Max     ·  Avg     ·  # calls   ·  usd (avg)  │ ··················|··········|··········|··········|············|·············· |  derivePubKey   ·  476146  ·  518863  ·  499884  ·        18  ·      29.61  │ ··················|··········|··········|··········|············|··············

    天然气消耗量和美元价格估算,天然气价格为100 Gwei,来源于ETH加油站:

    Benchmark

    合同的某些功能基于:

    ·----------------------------------------|---------------------------|-------------|----------------------------· |  Solc version: 0.6.12+commit.27d51765  ·  Optimizer enabled: true  ·  Runs: 200  ·  Block limit: 6718946 gas  │ ·········································|···························|·············|····························· |  Methods                               ·              100 gwei/gas               ·       613.52 usd/eth       │ ··················|······················|·············|·············|·············|··············|·············· |  Contract       ·  Method              ·  Min        ·  Max        ·  Avg        ·  # calls     ·  usd (avg)  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  decomposeScalar     ·      55811  ·      65399  ·      61939  ·         134  ·       3.80  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  deriveY             ·      45275  ·      55545  ·      50410  ·           4  ·       3.09  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecAdd               ·      24305  ·      56323  ·      49119  ·         472  ·       3.01  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecInv               ·      22906  ·      23074  ·      22990  ·           2  ·       1.41  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecMul               ·      24911  ·     623087  ·     350939  ·         561  ·      21.53  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecSimMul            ·      76465  ·     488165  ·     243763  ·         125  ·      14.96  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  ecSub               ·      42634  ·      56236  ·      49717  ·         228  ·       3.05  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  invMod              ·      22153  ·      49255  ·      39627  ·          12  ·       2.43  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  isOnCurve           ·      23400  ·      24071  ·      23623  ·          16  ·       1.45  │ ··················|······················|·············|·············|·············|··············|·············· |  EllipticCurve  ·  toAffine            ·      50145  ·      50850  ·      50498  ·           4  ·       3.10  │ ·----------------------------------------|-------------|-------------|-------------|--------------|-------------·

    Acknowledgements

    椭圆曲线稠度根据MIT许可证发布。

    • Comparatively Study of ECC and Jacobian Elliptic Curve Cryptography by Anagha P. Zele and Avinash P. Wadhe
    • Numerology by NuCypher
    • solidity-arithmetic by Gnosis
    • ecsol written by Jordi Baylina
    • standard contracts written by Andreas Olofsson

    License

    我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。了解更多。

    我们使用可选的第三方分析cookies来了解您如何使用GitHub.com网站所以我们可以制造更好的产品。
    您可以随时通过单击页面底部的Cookie首选项来更新您的选择。有关更多信息,请参阅我们的隐私声明。

    部分转自网络,侵权联系删除区块链源码网

    www.interchains.cc

    https://www.interchains.cc/19010.html

    区块链毕设网(www.interchains.cc)全网最靠谱的原创区块链毕设代做网站 部分资料来自网络,侵权联系删除! 最全最大的区块链源码站 ! QQ3039046426
    区块链知识分享网, 以太坊dapp资源网, 区块链教程, fabric教程下载, 区块链书籍下载, 区块链资料下载, 区块链视频教程下载, 区块链基础教程, 区块链入门教程, 区块链资源 » elliptic-curve-solidity – 椭圆曲线稠度区块链毕设代写

    提供最优质的资源集合

    立即查看 了解详情