Skip to content
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
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
- `$ npm install`
- `$ npm -g install truffle`
- `$ npm install -g ganache-cli` or installing its [graphic interface](https://truffleframework.com/ganache)
- Required truffle/solcjs version: >= 0.5

### Compile:
- `$ truffle compile`
Expand Down
1 change: 1 addition & 0 deletions _config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
theme: jekyll-theme-minimal
2 changes: 1 addition & 1 deletion contracts/DOSProxy.sol
Original file line number Diff line number Diff line change
Expand Up @@ -358,4 +358,4 @@ contract DOSProxy {
nodeId.length = 0;
groupPubKeys.length = 0;
}
}
}
16 changes: 11 additions & 5 deletions contracts/lib/utils.sol
Original file line number Diff line number Diff line change
Expand Up @@ -140,13 +140,19 @@ library utils {
return string(b);
}

// Example: address(0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263) => '0e7ad63d2a305a7b9f46541c386aafbd2af6b263'
function addr2Str(address x) internal pure returns(string memory) {
bytes memory b = new bytes(20);
// Example: address(0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263) => '0x0e7ad63d2a305a7b9f46541c386aafbd2af6b263'
function addr2Str(address _addr) internal pure returns(string memory) {
bytes32 value = bytes32(uint256(_addr));
bytes memory charset = "0123456789abcdef";

bytes memory str = new bytes(42);
str[0] = '0';
str[1] = 'x';
for (uint i = 0; i < 20; i++) {
b[i] = byte(uint8(uint(x) / (2**(8*(19 - i)))));
str[2+i*2] = charset[uint8(value[i + 12] >> 4)];
str[3+i*2] = charset[uint8(value[i + 12] & 0x0f)];
}
return string(b);
return string(str);
}

/// bytes/string helpers.
Expand Down
12 changes: 6 additions & 6 deletions contracts/mocks/BN256Mock.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ contract BN256Mock {
return [ BN256.P1().x, BN256.P1().y ];
}

function P2() public pure returns (uint[2][2] memory) {
function P2() public pure returns (uint[4] memory) {
return [
[BN256.P2().x[0], BN256.P2().x[1]],
[BN256.P2().y[0], BN256.P2().y[1]]
BN256.P2().x[0], BN256.P2().x[1],
BN256.P2().y[0], BN256.P2().y[1]
];
}

Expand Down Expand Up @@ -43,7 +43,7 @@ contract BN256Mock {
return [p1.x, p1.y];
}

function pairingCheck(uint[2][] memory p1, uint[2][2][] memory p2)
function pairingCheck(uint[2][] memory p1, uint[4][] memory p2)
public
returns (bool)
{
Expand All @@ -53,8 +53,8 @@ contract BN256Mock {
BN256.G2Point[] memory b_p2 = new BN256.G2Point[](p1.length);
for (uint i = 0; i < p1.length; i++) {
b_p1[i] = BN256.G1Point(p1[i][0], p1[i][1]);
b_p2[i] = BN256.G2Point([p2[i][0][0], p2[i][0][1]],
[p2[i][1][0], p2[i][1][1]]);
b_p2[i] = BN256.G2Point([p2[i][0], p2[i][1]],
[p2[i][2], p2[i][3]]);
}
return BN256.pairingCheck(b_p1, b_p2);
}
Expand Down
73 changes: 73 additions & 0 deletions contracts/mocks/UtilsMock.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
pragma solidity >= 0.4.24;
import "../lib/utils.sol";

contract UtilsMock {
function returnUINT256MAX() public pure returns(uint) {
return ~uint(0);
}

function createByte() public pure returns(byte) {
return '6';
}

function byte2Uint(byte b) public pure returns(uint8) {
return utils.byte2Uint(b);
}

function hexByte2Uint(byte b) public pure returns(uint8) {
return utils.hexByte2Uint(b);
}

function str2Uint(string memory a) public pure returns(uint) {
return utils.str2Uint(a);
}

function hexStr2Uint(string memory a) public pure returns(uint) {
return utils.hexStr2Uint(a);
}

function str2Addr(string memory a) public pure returns(address) {
return utils.str2Addr(a);
}

function uint2HexStr(uint x) public pure returns(string memory) {
return utils.uint2HexStr(x);
}

function uint2Str(uint x) public pure returns(string memory) {
return utils.uint2Str(x);
}

function addr2Str(string memory a) public pure returns(string memory) {
address x = utils.str2Addr(a);
return utils.addr2Str(x);
}

function bytesConcat(bytes memory a, bytes memory b) public pure returns(bytes memory) {
return utils.bytesConcat(a,b);
}

function strConcat(string memory a, string memory b) public pure returns(string memory) {
return utils.strConcat(a,b);
}

function strCompare(string memory a, string memory b) public pure returns(int) {
return utils.strCompare(a, b);
}

function strEqual(string memory a, string memory b) public pure returns(bool) {
return utils.strEqual(a, b);
}

function indexOf(string memory haystack, string memory needle) public pure returns(int) {
return utils.indexOf(haystack, needle);
}

function subStr(string memory a, uint start, uint len) public pure returns(string memory) {
return utils.subStr(a, start, len);
}

function subStr1(string memory a, uint start) public pure returns(string memory) {
return utils.subStr(a, start);
}
}
Loading