Skip to content

Commit

Permalink
Merge pull request #120 from clearmatics/ion-stage-2
Browse files Browse the repository at this point in the history
Ion Stage 2
  • Loading branch information
Shirikatsu authored Dec 10, 2018
2 parents 82a5558 + c3e7355 commit 82899ed
Show file tree
Hide file tree
Showing 105 changed files with 14,032 additions and 6,853 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/build
/abi
/dist
/chaindata
/node_modules
Expand Down
43 changes: 43 additions & 0 deletions .travis.yml
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=
26 changes: 26 additions & 0 deletions Dockerfile
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

55 changes: 0 additions & 55 deletions Makefile

This file was deleted.

293 changes: 153 additions & 140 deletions README.md

Large diffs are not rendered by default.

3 changes: 0 additions & 3 deletions __main__.py

This file was deleted.

1 change: 0 additions & 1 deletion abi/ERC223.abi

This file was deleted.

1 change: 0 additions & 1 deletion abi/IonLink.abi

This file was deleted.

1 change: 0 additions & 1 deletion abi/IonLock.abi

This file was deleted.

1 change: 0 additions & 1 deletion abi/Token.abi

This file was deleted.

15 changes: 0 additions & 15 deletions contracts/ERC223.sol

This file was deleted.

9 changes: 0 additions & 9 deletions contracts/ERC223Compatible.sol

This file was deleted.

61 changes: 61 additions & 0 deletions contracts/EventVerifier.sol
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 );
}

}
73 changes: 73 additions & 0 deletions contracts/Ion.sol
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);
}
}
21 changes: 8 additions & 13 deletions contracts/IonCompatible.sol
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);
}
}
Loading

0 comments on commit 82899ed

Please sign in to comment.