Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished public and core API #1

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
5e5c79d
completed
BaldyAsh Jul 31, 2019
c943910
fix
BaldyAsh Jul 31, 2019
74963cc
renaming, api separation
BaldyAsh Jul 31, 2019
06e0e72
test fixes
BaldyAsh Jul 31, 2019
2e37c12
small test fix
BaldyAsh Jul 31, 2019
3613d93
input bytes array now have fixed size
BaldyAsh Jul 31, 2019
8b28c66
separated lengths verification
BaldyAsh Aug 1, 2019
a68604f
tested creating op_data
BaldyAsh Aug 1, 2019
c43a7ea
fixed a lot
BaldyAsh Aug 1, 2019
c177139
added g2 and pairing tests
BaldyAsh Aug 1, 2019
138de9b
fixed
BaldyAsh Aug 1, 2019
9a5a83d
added test for abi
BaldyAsh Aug 2, 2019
afaf533
added bn254 curve
BaldyAsh Aug 2, 2019
e9c0db8
replaced tests
BaldyAsh Aug 2, 2019
b36ba5a
fix
BaldyAsh Aug 2, 2019
04274c8
commented test for a while
BaldyAsh Aug 2, 2019
16dea36
fixed tests
BaldyAsh Aug 6, 2019
1fa6f8c
fix
BaldyAsh Aug 6, 2019
efc0704
fix
BaldyAsh Aug 7, 2019
f88d5dc
added tests for raw call precomp
BaldyAsh Aug 7, 2019
a21fcfc
fix
BaldyAsh Aug 7, 2019
cc8fbf8
some fixes
BaldyAsh Aug 7, 2019
3a0fb87
fix calling
shamatar Aug 7, 2019
41cea94
update for multiplication test example
shamatar Aug 7, 2019
792bcb2
more tests
BaldyAsh Aug 8, 2019
dffef91
raw tested mul g1&g2 and pairing for bls12-384
BaldyAsh Aug 8, 2019
90379db
tested g1 add raw
BaldyAsh Aug 8, 2019
1cdae9a
g2 add test passes
BaldyAsh Aug 8, 2019
b3c592c
added g1 multiexp raw test
BaldyAsh Aug 8, 2019
b49669d
completed raw tests
BaldyAsh Aug 8, 2019
83ced43
modified callEip1962
BaldyAsh Aug 8, 2019
0b2236c
added caller tests, pairing fails
BaldyAsh Aug 8, 2019
2d97124
separated a and b params for g1 and g2 operations due to different le…
BaldyAsh Aug 8, 2019
c2b7b5b
added check for bls12 type in pairings
BaldyAsh Aug 8, 2019
317a253
fixed pairing call
BaldyAsh Aug 11, 2019
11849f4
added g1add test for deployed bls curve
BaldyAsh Aug 11, 2019
6c7e152
added deploy and test with truffle on geth
BaldyAsh Aug 13, 2019
e65b337
added testing in readme
BaldyAsh Aug 13, 2019
6961cff
fixed readme
BaldyAsh Aug 13, 2019
8464058
Update README.md
BaldyAsh Aug 14, 2019
00a202b
Update README.md
BaldyAsh Aug 22, 2019
09b06fe
Update README.md
BaldyAsh Aug 22, 2019
c80e357
test contracts separation
BaldyAsh Oct 20, 2019
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
2 changes: 2 additions & 0 deletions .dev.env
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
JSON_RPC_URL=http://localhost:8545
WALLET_PK=0x4d5db4107d237df6a3d58ee5f70ae63d73d7658d4026f2eefd2f204c81682cb7
4 changes: 4 additions & 0 deletions .gitingore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.DS_Store

/build
/node_modules
175 changes: 175 additions & 0 deletions contracts/Bytes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,175 @@
pragma solidity ^0.5.1;

library Bytes {

// Compies uint 'self' into a new 'bytes memory'.
// Params:
// - self - input number
// - length - bytes array length
// Returns the newly created 'bytes memory'.
function toBytesFromUInt(uint self, uint length) internal pure returns (bytes memory bts) {
assembly {
bts := mload(0x10)
mstore(bts, 0x20)
mstore(add(bts, 0x20), self)
}
if (bts.length > length) {
bts = slice(bts, bts.length-length, length);
}
}

// Original source code: https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol#L228
function slice(
bytes memory _bytes,
uint _start,
uint _length
)
public
pure
returns (bytes memory)
{
require(_bytes.length >= (_start + _length));

bytes memory tempBytes;

assembly {
switch iszero(_length)
case 0 {
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
tempBytes := mload(0x40)

// The first word of the slice result is potentially a partial
// word read from the original array. To read it, we calculate
// the length of that partial word and start copying that many
// bytes into the array. The first word we copy will start with
// data we don't care about, but the last `lengthmod` bytes will
// land at the beginning of the contents of the new array. When
// we're done copying, we overwrite the full first word with
// the actual length of the slice.
let lengthmod := and(_length, 31)

// The multiplication in the next line is necessary
// because when slicing multiples of 32 bytes (lengthmod == 0)
// the following copy loop was copying the origin's length
// and then ending prematurely not copying everything it should.
let mc := add(add(tempBytes, lengthmod), mul(0x20, iszero(lengthmod)))
let end := add(mc, _length)

for {
// The multiplication in the next line has the same exact purpose
// as the one above.
let cc := add(add(add(_bytes, lengthmod), mul(0x20, iszero(lengthmod))), _start)
} lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
mstore(mc, mload(cc))
}

mstore(tempBytes, _length)

//update free-memory pointer
//allocating the array padded to 32 bytes like the compiler does now
mstore(0x40, and(add(mc, 31), not(31)))
}
//if we want a zero-length slice let's just return a zero-length array
default {
tempBytes := mload(0x40)

mstore(0x40, add(tempBytes, 0x20))
}
}

return tempBytes;
}

// Compies uint8 'self' into a new 'bytes memory'.
// Returns the newly created 'bytes memory'.
function toBytesFromUInt8(uint8 self) internal pure returns (bytes memory bts) {
bts = new bytes(1);
bts[0] = byte(self);
}

// Original source code: https://github.com/GNSPS/solidity-bytes-utils/blob/master/contracts/BytesLib.sol#L13
// Concatenate bytes arrays in memory
// Returns the newly created 'bytes memory'.
function concat(
bytes memory _preBytes,
bytes memory _postBytes
)
public
pure
returns (bytes memory)
{
bytes memory tempBytes;

assembly {
// Get a location of some free memory and store it in tempBytes as
// Solidity does for memory variables.
tempBytes := mload(0x40)

// Store the length of the first bytes array at the beginning of
// the memory for tempBytes.
let length := mload(_preBytes)
mstore(tempBytes, length)

// Maintain a memory counter for the current write location in the
// temp bytes array by adding the 32 bytes for the array length to
// the starting location.
let mc := add(tempBytes, 0x20)
// Stop copying when the memory counter reaches the length of the
// first bytes array.
let end := add(mc, length)

for {
// Initialize a copy counter to the start of the _preBytes data,
// 32 bytes into its memory.
let cc := add(_preBytes, 0x20)
} lt(mc, end) {
// Increase both counters by 32 bytes each iteration.
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
// Write the _preBytes data into the tempBytes memory 32 bytes
// at a time.
mstore(mc, mload(cc))
}

// Add the length of _postBytes to the current length of tempBytes
// and store it as the new length in the first 32 bytes of the
// tempBytes memory.
length := mload(_postBytes)
mstore(tempBytes, add(length, mload(tempBytes)))

// Move the memory counter back from a multiple of 0x20 to the
// actual end of the _preBytes data.
mc := end
// Stop copying when the memory counter reaches the new combined
// length of the arrays.
end := add(mc, length)

for {
let cc := add(_postBytes, 0x20)
} lt(mc, end) {
mc := add(mc, 0x20)
cc := add(cc, 0x20)
} {
mstore(mc, mload(cc))
}

// Update the free-memory pointer by padding our last write location
// to 32 bytes: add 31 bytes to the end of tempBytes to move to the
// next 32 byte block, then round down to the nearest multiple of
// 32. If the sum of the length of the two arrays is zero then add
// one before rounding down to leave a blank 32 bytes (the length block with 0).
mstore(0x40, and(
add(add(end, iszero(add(length, mload(_preBytes)))), 31),
not(31) // Round down to the nearest 32 bytes.
))
}

return tempBytes;
}

}
52 changes: 52 additions & 0 deletions contracts/CommonTypes.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
pragma solidity ^0.5.1;
pragma experimental ABIEncoderV2;

import {Bytes} from "../contracts/Bytes.sol";

library CommonTypes {
// Curve parameters struct
struct CurveParams {
uint8 curveType;
uint8 fieldLength;
bytes baseFieldModulus;
uint8 extensionDegree;
bytes a;
bytes b;
uint8 groupOrderLength;
bytes groupOrder;
bytes fpNonResidue;
bytes mainSubgroupOrder;
bytes fp2NonResidue;
bytes fp6NonResidue;
uint8 twistType;
uint8 xLength;
bytes x;
uint8 sign;
}

// G1 Point
struct G1Point {
uint X;
uint Y;
}

// G2 Point
struct G2Point {
uint[2] X;
uint[2] Y;
}

// Points pair
struct Pair {
G1Point g1p;
G2Point g2p;
BaldyAsh marked this conversation as resolved.
Show resolved Hide resolved
}

// Enum describes possible curves.
// 'Custom' is user defined curve.
// 'Undefined' curve is undefined;
enum PrebuildCurveTypes {
Bn256,
Bls12_381
}
}
Loading