-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #120 from clearmatics/ion-stage-2
Ion Stage 2
- Loading branch information
Showing
105 changed files
with
14,032 additions
and
6,853 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
/build | ||
/abi | ||
/dist | ||
/chaindata | ||
/node_modules | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
os: linux | ||
dist: trusty | ||
|
||
matrix: | ||
include: | ||
- name: "Javascript Contract Tests" | ||
services: | ||
- docker | ||
|
||
before_script: | ||
- npm install | ||
- npm run testrpc & | ||
|
||
script: | ||
- npm run test | ||
|
||
before_install: | ||
- docker build . -t node | ||
- docker run --name testrpc --rm -d -it -p 127.0.0.1:8501:8545 node bash | ||
- docker exec -d -it testrpc /bin/bash ./docker_build/launch_geth.sh | ||
|
||
- name: "Ion-CLI Tests" | ||
language: go | ||
go: 1.9.x | ||
script: | ||
- cd ./ion-cli | ||
- go get github.com/ethereum/go-ethereum | ||
- curl https://raw.githubusercontent.com/golang/dep/master/install.sh | sh | ||
- dep ensure | ||
- cp -r "${GOPATH}/src/github.com/ethereum/go-ethereum/crypto/secp256k1/libsecp256k1" "vendor/github.com/ethereum/go-ethereum/crypto/secp256k1/" | ||
- make build | ||
- make test | ||
|
||
before_install: | ||
- sudo add-apt-repository ppa:ethereum/ethereum -y | ||
- sudo apt-get update | ||
- sudo apt-get install solc -y | ||
|
||
|
||
notifications: | ||
slack: | ||
on_failure: always | ||
secure: k6j6BWCTMJ6U7JXhy0yBcJpfkOw4eUNnL9xyufiI6Ue5Cf+NvN9FJxNZvoz4BvVSitq/BSlcWGjQoIW5AoWtf15tl4hvQmFN4YYHT79TKjRGEcSBg1+D55aXmjIM3UwHtCOuSJxAkl7dTgWAJ3FU0/aBqy96OsODjhcP8VeuMay+2Z+kT/QQjtO5rduHfLpeJxVfoEdhXR9QjHozV287rE49E6wWV6KzNCDOYy3CFGkQsgBQzlxkmlvhwbjDeNb72UcruSh50ic78/NLru3AXwRFx2yc1fkr2Nv9q6l5r9I1iWek8EZ46OCe/dQ004s7PI7knVx1vssdA3ksLDyRzhNHvWpn1EI1fi4Aqc+ki9vHbccR5c1pw85zwcQiLEoVFpJ+MpfHi9ExmAJmvvrzz2RBMqsL5JuSfInxiSLyX6vSVpufgZYrDKAemWXhR030dQQZ8BVQOCbt2lzCgHZajmDvrOktq6QdTFzEz/JjyorXn+0Rpho+7FHY5sW9KdgvmexI9SAjjz0BgcQzof9QKpyuRZpbboWRxPsfPUQDlx+Wxm541ndunGNQ2mVXqSgKaTQShiKhhu7dOPevw1a+dreJ6n8afL9pfW4SHcs0O+FlHvAnLAbRDvbnxROF89RRDiTVBdC6h7vcAX6lNDFUxF0F1bYTiWE0s4+umB2zlqc= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
FROM ubuntu:16.04 | ||
|
||
LABEL version="1.0" | ||
LABEL maintainer="[email protected]" | ||
|
||
ENV DEBIAN_FRONTEND=noninteractive | ||
|
||
RUN apt-get update && apt-get install --yes software-properties-common | ||
RUN add-apt-repository ppa:ethereum/ethereum | ||
RUN apt-get update && apt-get install --yes geth | ||
|
||
RUN adduser --disabled-login --gecos "" eth_user | ||
|
||
COPY docker_build /home/eth_user/docker_build | ||
RUN chown -R eth_user:eth_user /home/eth_user/docker_build | ||
|
||
USER eth_user | ||
|
||
WORKDIR /home/eth_user | ||
|
||
RUN geth --datadir docker_build/account/ init docker_build/clique.json | ||
|
||
EXPOSE 8545 | ||
|
||
ENTRYPOINT bash | ||
|
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
// Copyright (c) 2016-2018 Clearmatics Technologies Ltd | ||
// SPDX-License-Identifier: LGPL-3.0+ | ||
pragma solidity ^0.4.23; | ||
|
||
import "./libraries/RLP.sol"; | ||
import "./libraries/SolidityUtils.sol"; | ||
|
||
/* | ||
EventVerifier | ||
This contract is the basic global EventVerifier interface that all specific event verifiers must inherit from. | ||
It supplies a function `retrieveLog` that will output the relevant log for a specified event signature from the | ||
provided receipts. Each specific verifier that inherits this contract must hold knowledge of the event signature it | ||
intends to consume which will be passed to the retrieval function for log separation. | ||
*/ | ||
|
||
contract EventVerifier { | ||
/* | ||
retrieveLog | ||
param: _eventSignature (bytes32) Hash representing the event signature of the event type to be consumed | ||
param: _contractEmittedAddress (bytes20) Address of the contract expected to have emitted the event | ||
param: _rlpReceipt (bytes) RLP-encoded receipt containing the relevant logs | ||
returns: log (RLP.RLPItem[]) Decoded log object in the form [ contractAddress, topics, data ] | ||
This decodes an RLP-encoded receipt and trawls through the logs to find the event that matches the event | ||
signature required and checks if the event was emitted from the correct source. If no log could be found with | ||
the relevant signature or emitted from the expected source the execution fails with an assert. | ||
If a log is not found, an `assert(false)` consumes all the gas and fails the transaction in order to incentivise | ||
submission of proper data. | ||
*/ | ||
function retrieveLog(bytes32 _eventSignature, bytes20 _contractEmittedAddress, bytes _rlpReceipt) | ||
internal returns (RLP.RLPItem[]) | ||
{ | ||
/* Decode the receipt into it's consituents and grab the logs with it's known position in the receipt | ||
object and proceed to decode the logs also. | ||
*/ | ||
RLP.RLPItem[] memory receipt = RLP.toList(RLP.toRLPItem(_rlpReceipt)); | ||
RLP.RLPItem[] memory logs = RLP.toList(receipt[3]); | ||
|
||
/* The receipts could contain multiple event logs if a single transaction emitted multiple events. We need to | ||
separate them and locate the relevant event by signature. | ||
*/ | ||
for (uint i = 0; i < logs.length; i++) { | ||
RLP.RLPItem[] memory log = RLP.toList(logs[i]); | ||
RLP.RLPItem[] memory topics = RLP.toList(log[1]); | ||
|
||
bytes32 containedEventSignature = RLP.toBytes32(topics[0]); | ||
if (containedEventSignature == _eventSignature) { | ||
// If event signature is found, check the contract address it was emitted from | ||
bytes20 b20_emissionSource = SolUtils.BytesToBytes20(RLP.toData(log[0]), 0); | ||
assert( b20_emissionSource == _contractEmittedAddress); | ||
return log; | ||
} | ||
} | ||
assert( false ); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
// Copyright (c) 2016-2018 Clearmatics Technologies Ltd | ||
// SPDX-License-Identifier: LGPL-3.0+ | ||
pragma solidity ^0.4.23; | ||
|
||
import "./libraries/ECVerify.sol"; | ||
import "./libraries/RLP.sol"; | ||
import "./libraries/PatriciaTrie.sol"; | ||
import "./libraries/SolidityUtils.sol"; | ||
import "./storage/BlockStore.sol"; | ||
|
||
contract Ion { | ||
|
||
bytes32 public chainId; | ||
mapping (address => bool) public m_registered_validation; | ||
address[] public validation_modules; | ||
|
||
/* | ||
* Constructor | ||
* param: id (bytes32) Unique id to identify this chain that the contract is being deployed to. | ||
* | ||
* Supplied with a unique id to identify this chain to others that may interoperate with it. | ||
* The deployer must assert that the id is indeed public and that it is not already being used | ||
* by another chain | ||
*/ | ||
constructor(bytes32 _id) public { | ||
chainId = _id; | ||
} | ||
|
||
/* | ||
* onlyRegisteredValidation | ||
* param: _addr (address) Address of the Validation module being registered | ||
* | ||
* Modifier that checks if the provided chain id has been registered to this contract | ||
*/ | ||
modifier onlyRegisteredValidation() { | ||
require( isContract(msg.sender), "Caller address is not a valid contract. Please inherit the BlockStore contract for proper usage." ); | ||
require( m_registered_validation[msg.sender], "Validation module is not registered"); | ||
_; | ||
} | ||
|
||
// Pseudo-modifier returns boolean, used with different 'require's to input custom revert messages | ||
function isContract(address _addr) internal returns (bool) { | ||
uint size; | ||
assembly { size := extcodesize(_addr) } | ||
return (size > 0); | ||
} | ||
|
||
|
||
function registerValidationModule() public { | ||
require( isContract(msg.sender), "Caller address is not a valid contract. Please inherit the BlockStore contract for proper usage." ); | ||
require( !m_registered_validation[msg.sender], "Validation module has already been registered." ); | ||
|
||
m_registered_validation[msg.sender] = true; | ||
validation_modules.push(msg.sender); | ||
} | ||
|
||
function addChain(address _storageAddress, bytes32 _chainId) onlyRegisteredValidation public { | ||
BlockStore store = BlockStore(_storageAddress); | ||
store.addChain(_chainId); | ||
} | ||
|
||
/* | ||
* storeBlock | ||
* param: | ||
* | ||
*/ | ||
function storeBlock(address _storageAddress, bytes32 _chainId, bytes32 _blockHash, bytes _blockBlob) onlyRegisteredValidation public { | ||
require( isContract(_storageAddress), "Storage address provided is not contract."); | ||
BlockStore store = BlockStore(_storageAddress); | ||
|
||
store.addBlock(_chainId, _blockHash, _blockBlob); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
// Copyright (c) 2016-2018 Clearmatics Technologies Ltd | ||
// SPDX-License-Identifier: LGPL-3.0+ | ||
pragma solidity ^0.4.18; | ||
|
||
contract IonLinkInterface { | ||
function Verify(uint256 block_id, uint256 leaf_hash, uint256[] proof) | ||
public view returns (bool); | ||
} | ||
|
||
pragma solidity ^0.4.0; | ||
import "./Ion.sol"; | ||
|
||
contract IonCompatible { | ||
event IonTransfer(address _recipient, address _currency, uint256 indexed value, bytes32 indexed ref, bytes data); | ||
|
||
event IonWithdraw(address _recipient, address _currency, uint256 indexed value, bytes32 indexed ref); | ||
|
||
event IonMint(uint256 value, bytes32 indexed ref); | ||
/* The Ion contract that proofs would be made to. Ensure that prior to verification attempts that the relevant | ||
blocks have been submitted to the Ion contract. */ | ||
Ion internal ion; | ||
|
||
event IonBurn(uint256 value, bytes32 indexed ref); | ||
constructor(address _ionAddr) public { | ||
ion = Ion(_ionAddr); | ||
} | ||
} |
Oops, something went wrong.