Skip to content
This repository has been archived by the owner on Oct 20, 2020. It is now read-only.

Commit

Permalink
Bump version, change the state machine used for processing new blocks…
Browse files Browse the repository at this point in the history
…. Now a newly added block that is not yet trusted is stored in untrustedHead. After the challenge period is over, it can be moved to head. Fixes #13, #15.
  • Loading branch information
abacabadabacaba committed Sep 21, 2020
1 parent 22f8845 commit f4ad769
Show file tree
Hide file tree
Showing 52 changed files with 3,381 additions and 6,505 deletions.
1 change: 1 addition & 0 deletions dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ do
# Get contract name without extension and without directories.
contract_name="${filename%.*}"
node_modules/.bin/truffle-flattener "./contracts/${contract_name}.sol" > "dist/${contract_name}.full.sol"
sed -i '/^\/\/ SPDX-License-Identifier:/d' "dist/${contract_name}.full.sol"
yarn run solcjs --bin --abi --optimize "dist/${contract_name}.full.sol" -o "dist"
mv "dist/dist_${contract_name}_full_sol_${contract_name}.abi" "dist/${contract_name}.full.abi"
mv "dist/dist_${contract_name}_full_sol_${contract_name}.bin" "dist/${contract_name}.full.bin"
Expand Down
4 changes: 2 additions & 2 deletions nearbridge/contracts/Borsh.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6;

import "@openzeppelin/contracts/math/SafeMath.sol";

Expand Down Expand Up @@ -48,7 +48,7 @@ library Borsh {
bytes32[1] memory result;
// solium-disable-next-line security/no-inline-assembly
assembly {
pop(staticcall(gas, 0x02, add(add(ptr, 32), offset), length, result, 32))
pop(staticcall(gas(), 0x02, add(add(ptr, 32), offset), length, result, 32))
}
return result[0];
}
Expand Down
2 changes: 1 addition & 1 deletion nearbridge/contracts/Ed25519.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6;


// https://gist.github.com/abacabadabacaba/cb927b5ebe6db63f00b98902503ffc76
Expand Down
4 changes: 2 additions & 2 deletions nearbridge/contracts/INearBridge.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6;


interface INearBridge {
Expand All @@ -21,7 +21,7 @@ interface INearBridge {

function initWithValidators(bytes calldata initialValidators) external;
function initWithBlock(bytes calldata data) external;
function addLightClientBlock(bytes calldata data) external payable;
function addLightClientBlock(bytes calldata data) external;
function challenge(address payable receiver, uint256 signatureIndex) external;
function checkBlockProducerSignatureInHead(uint256 signatureIndex) external view returns(bool);
}
2 changes: 1 addition & 1 deletion nearbridge/contracts/Migrations.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6;


contract Migrations {
Expand Down
337 changes: 177 additions & 160 deletions nearbridge/contracts/NearBridge.sol

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion nearbridge/contracts/NearDecoder.sol
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
pragma solidity ^0.5.0;
pragma solidity ^0.6;

import "@openzeppelin/contracts/math/SafeMath.sol";
import "./Borsh.sol";
Expand Down
1 change: 1 addition & 0 deletions nearbridge/dist.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ do
# Get contract name without extension and without directories.
contract_name="${filename%.*}"
node_modules/.bin/truffle-flattener "./contracts/${contract_name}.sol" > "dist/${contract_name}.full.sol"
sed -i '/^\/\/ SPDX-License-Identifier:/d' "dist/${contract_name}.full.sol"
yarn run solcjs --bin --abi --optimize "dist/${contract_name}.full.sol" -o "dist"
mv "dist/dist_${contract_name}_full_sol_${contract_name}.abi" "dist/${contract_name}.full.abi"
mv "dist/dist_${contract_name}_full_sol_${contract_name}.bin" "dist/${contract_name}.full.bin"
Expand Down
2 changes: 1 addition & 1 deletion nearbridge/dist/Borsh.full.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
60556023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea265627a7a72315820088e5b0296813c1e1c29a351db258df5946de2103682725b6985f6ac763bb37e64736f6c63430005100032
60566023600b82828239805160001a607314601657fe5b30600052607381538281f3fe73000000000000000000000000000000000000000030146080604052600080fdfea26469706673582212201eb9c1552f61cd8050581d63546f74165e1b53d547ce5b1e92a19c814ed17c5b64736f6c634300060c0033
23 changes: 12 additions & 11 deletions nearbridge/dist/Borsh.full.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

// File: @openzeppelin/contracts/math/SafeMath.sol

pragma solidity ^0.5.0;

pragma solidity ^0.6.0;

/**
* @dev Wrappers over Solidity's arithmetic operations with added overflow
Expand All @@ -24,6 +24,7 @@ library SafeMath {
* Counterpart to Solidity's `+` operator.
*
* Requirements:
*
* - Addition cannot overflow.
*/
function add(uint256 a, uint256 b) internal pure returns (uint256) {
Expand All @@ -40,6 +41,7 @@ library SafeMath {
* Counterpart to Solidity's `-` operator.
*
* Requirements:
*
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b) internal pure returns (uint256) {
Expand All @@ -53,9 +55,8 @@ library SafeMath {
* Counterpart to Solidity's `-` operator.
*
* Requirements:
* - Subtraction cannot overflow.
*
* _Available since v2.4.0._
* - Subtraction cannot overflow.
*/
function sub(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b <= a, errorMessage);
Expand All @@ -71,6 +72,7 @@ library SafeMath {
* Counterpart to Solidity's `*` operator.
*
* Requirements:
*
* - Multiplication cannot overflow.
*/
function mul(uint256 a, uint256 b) internal pure returns (uint256) {
Expand All @@ -96,6 +98,7 @@ library SafeMath {
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b) internal pure returns (uint256) {
Expand All @@ -111,12 +114,10 @@ library SafeMath {
* uses an invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*
* _Available since v2.4.0._
* - The divisor cannot be zero.
*/
function div(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
// Solidity only automatically asserts when dividing by 0
require(b > 0, errorMessage);
uint256 c = a / b;
// assert(a == b * c + a % b); // There is no case in which this doesn't hold
Expand All @@ -133,6 +134,7 @@ library SafeMath {
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
*
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b) internal pure returns (uint256) {
Expand All @@ -148,9 +150,8 @@ library SafeMath {
* invalid opcode to revert (consuming all remaining gas).
*
* Requirements:
* - The divisor cannot be zero.
*
* _Available since v2.4.0._
* - The divisor cannot be zero.
*/
function mod(uint256 a, uint256 b, string memory errorMessage) internal pure returns (uint256) {
require(b != 0, errorMessage);
Expand All @@ -160,7 +161,7 @@ library SafeMath {

// File: contracts/Borsh.sol

pragma solidity ^0.5.0;
pragma solidity ^0.6;



Expand Down Expand Up @@ -209,7 +210,7 @@ library Borsh {
bytes32[1] memory result;
// solium-disable-next-line security/no-inline-assembly
assembly {
pop(staticcall(gas, 0x02, add(add(ptr, 32), offset), length, result, 32))
pop(staticcall(gas(), 0x02, add(add(ptr, 32), offset), length, result, 32))
}
return result[0];
}
Expand Down
2 changes: 1 addition & 1 deletion nearbridge/dist/Ed25519.full.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"constant":true,"inputs":[{"internalType":"bytes32","name":"k","type":"bytes32"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes32","name":"m1","type":"bytes32"},{"internalType":"bytes9","name":"m2","type":"bytes9"}],"name":"check","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"pure","type":"function"}]
[{"inputs":[{"internalType":"bytes32","name":"k","type":"bytes32"},{"internalType":"bytes32","name":"r","type":"bytes32"},{"internalType":"bytes32","name":"s","type":"bytes32"},{"internalType":"bytes32","name":"m1","type":"bytes32"},{"internalType":"bytes9","name":"m2","type":"bytes9"}],"name":"check","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"pure","type":"function"}]
2 changes: 1 addition & 1 deletion nearbridge/dist/Ed25519.full.bin

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions nearbridge/dist/Ed25519.full.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

// File: contracts/Ed25519.sol

pragma solidity ^0.5.0;
pragma solidity ^0.6;


// https://gist.github.com/abacabadabacaba/cb927b5ebe6db63f00b98902503ffc76
Expand Down
2 changes: 1 addition & 1 deletion nearbridge/dist/INearBridge.full.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint64","name":"height","type":"uint64"},{"indexed":false,"internalType":"bytes32","name":"blockHash","type":"bytes32"}],"name":"BlockHashAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint64","name":"height","type":"uint64"},{"indexed":false,"internalType":"bytes32","name":"blockHash","type":"bytes32"}],"name":"BlockHashReverted","type":"event"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"addLightClientBlock","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":true,"inputs":[{"internalType":"address","name":"wallet","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint64","name":"blockNumber","type":"uint64"}],"name":"blockHashes","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[{"internalType":"uint64","name":"blockNumber","type":"uint64"}],"name":"blockMerkleRoots","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"uint256","name":"signatureIndex","type":"uint256"}],"name":"challenge","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":true,"inputs":[{"internalType":"uint256","name":"signatureIndex","type":"uint256"}],"name":"checkBlockProducerSignatureInHead","outputs":[{"internalType":"bool","name":"","type":"bool"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[],"name":"deposit","outputs":[],"payable":true,"stateMutability":"payable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"initWithBlock","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"bytes","name":"initialValidators","type":"bytes"}],"name":"initWithValidators","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[],"name":"withdraw","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
[{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint64","name":"height","type":"uint64"},{"indexed":false,"internalType":"bytes32","name":"blockHash","type":"bytes32"}],"name":"BlockHashAdded","type":"event"},{"anonymous":false,"inputs":[{"indexed":true,"internalType":"uint64","name":"height","type":"uint64"},{"indexed":false,"internalType":"bytes32","name":"blockHash","type":"bytes32"}],"name":"BlockHashReverted","type":"event"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"addLightClientBlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"wallet","type":"address"}],"name":"balanceOf","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"blockNumber","type":"uint64"}],"name":"blockHashes","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint64","name":"blockNumber","type":"uint64"}],"name":"blockMerkleRoots","outputs":[{"internalType":"bytes32","name":"","type":"bytes32"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"address payable","name":"receiver","type":"address"},{"internalType":"uint256","name":"signatureIndex","type":"uint256"}],"name":"challenge","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"uint256","name":"signatureIndex","type":"uint256"}],"name":"checkBlockProducerSignatureInHead","outputs":[{"internalType":"bool","name":"","type":"bool"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"deposit","outputs":[],"stateMutability":"payable","type":"function"},{"inputs":[{"internalType":"bytes","name":"data","type":"bytes"}],"name":"initWithBlock","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"bytes","name":"initialValidators","type":"bytes"}],"name":"initWithValidators","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[],"name":"withdraw","outputs":[],"stateMutability":"nonpayable","type":"function"}]
5 changes: 2 additions & 3 deletions nearbridge/dist/INearBridge.full.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

// File: contracts/INearBridge.sol

pragma solidity ^0.5.0;
pragma solidity ^0.6;


interface INearBridge {
Expand All @@ -24,7 +23,7 @@ interface INearBridge {

function initWithValidators(bytes calldata initialValidators) external;
function initWithBlock(bytes calldata data) external;
function addLightClientBlock(bytes calldata data) external payable;
function addLightClientBlock(bytes calldata data) external;
function challenge(address payable receiver, uint256 signatureIndex) external;
function checkBlockProducerSignatureInHead(uint256 signatureIndex) external view returns(bool);
}
2 changes: 1 addition & 1 deletion nearbridge/dist/Migrations.full.abi
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"inputs":[],"payable":false,"stateMutability":"nonpayable","type":"constructor"},{"constant":true,"inputs":[],"name":"lastCompletedMigration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":true,"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"payable":false,"stateMutability":"view","type":"function"},{"constant":false,"inputs":[{"internalType":"uint256","name":"completed","type":"uint256"}],"name":"setCompleted","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"},{"constant":false,"inputs":[{"internalType":"address","name":"newAddress","type":"address"}],"name":"upgrade","outputs":[],"payable":false,"stateMutability":"nonpayable","type":"function"}]
[{"inputs":[],"stateMutability":"nonpayable","type":"constructor"},{"inputs":[],"name":"lastCompletedMigration","outputs":[{"internalType":"uint256","name":"","type":"uint256"}],"stateMutability":"view","type":"function"},{"inputs":[],"name":"owner","outputs":[{"internalType":"address","name":"","type":"address"}],"stateMutability":"view","type":"function"},{"inputs":[{"internalType":"uint256","name":"completed","type":"uint256"}],"name":"setCompleted","outputs":[],"stateMutability":"nonpayable","type":"function"},{"inputs":[{"internalType":"address","name":"newAddress","type":"address"}],"name":"upgrade","outputs":[],"stateMutability":"nonpayable","type":"function"}]
2 changes: 1 addition & 1 deletion nearbridge/dist/Migrations.full.bin
Original file line number Diff line number Diff line change
@@ -1 +1 @@
608060405234801561001057600080fd5b50600080546001600160a01b031916331790556101b3806100326000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80630900f010146100515780638da5cb5b14610079578063fbdbad3c1461009d578063fdacd576146100b7575b600080fd5b6100776004803603602081101561006757600080fd5b50356001600160a01b03166100d4565b005b610081610151565b604080516001600160a01b039092168252519081900360200190f35b6100a5610160565b60408051918252519081900360200190f35b610077600480360360208110156100cd57600080fd5b5035610166565b6000546001600160a01b031633141561014e576000819050806001600160a01b031663fdacd5766001546040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561013457600080fd5b505af1158015610148573d6000803e3d6000fd5b50505050505b50565b6000546001600160a01b031681565b60015481565b6000546001600160a01b031633141561014e5760015556fea265627a7a7231582065abac4e3591dd4cf03aaeffed225ce4db8a3d12815c62ebdfb094e8379ba33964736f6c63430005100032
608060405234801561001057600080fd5b50600080546001600160a01b031916331790556101b4806100326000396000f3fe608060405234801561001057600080fd5b506004361061004c5760003560e01c80630900f010146100515780638da5cb5b14610079578063fbdbad3c1461009d578063fdacd576146100b7575b600080fd5b6100776004803603602081101561006757600080fd5b50356001600160a01b03166100d4565b005b610081610151565b604080516001600160a01b039092168252519081900360200190f35b6100a5610160565b60408051918252519081900360200190f35b610077600480360360208110156100cd57600080fd5b5035610166565b6000546001600160a01b031633141561014e576000819050806001600160a01b031663fdacd5766001546040518263ffffffff1660e01b815260040180828152602001915050600060405180830381600087803b15801561013457600080fd5b505af1158015610148573d6000803e3d6000fd5b50505050505b50565b6000546001600160a01b031681565b60015481565b6000546001600160a01b031633141561014e5760015556fea264697066735822122095e4f146388b60af7e041acf249e1e2c41b2889a3d70be0a21c3ced1b563abc364736f6c634300060c0033
3 changes: 1 addition & 2 deletions nearbridge/dist/Migrations.full.sol
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@

// File: contracts/Migrations.sol

pragma solidity ^0.5.0;
pragma solidity ^0.6;


contract Migrations {
Expand Down
Loading

0 comments on commit f4ad769

Please sign in to comment.