Skip to content

Commit

Permalink
Merge pull request #2 from snario/liam/containerize
Browse files Browse the repository at this point in the history
Liam/containerize
  • Loading branch information
snario authored Sep 7, 2018
2 parents 9b1bd6a + 09a7813 commit 73835c5
Show file tree
Hide file tree
Showing 10 changed files with 78 additions and 10 deletions.
1 change: 1 addition & 0 deletions .dockerignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
keys/vk.json
__pycache__
27 changes: 27 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
FROM ubuntu:18.04

RUN apt-get update && \
apt-get install software-properties-common -y && \
add-apt-repository ppa:ethereum/ethereum -y && \
apt-get update && \
apt-get install -y \
wget unzip curl \
build-essential cmake git libgmp3-dev libprocps-dev python-markdown libboost-all-dev libssl-dev pkg-config python3-pip solc

WORKDIR /root/roll_up

COPY . .

RUN pip3 install -r requirements.txt

RUN cd build \
&& cmake .. \
&& make \
&& DESTDIR=/usr/local make install \
NO_PROCPS=1 \
NO_GTEST=1 \
NO_DOCS=1 \
CURVE=ALT_BN128 \
FEATUREFLAGS="-DBINARY_OUTPUT=1 -DMONTGOMERY_OUTPUT=1 -DNO_PT_COMPRESSION=1"

ENV LD_LIBRARY_PATH $LD_LIBRARY_PATH:/usr/local/lib
Empty file added build/.gitkeep
Empty file.
2 changes: 1 addition & 1 deletion contracts/Miximus.sol
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@

pragma solidity ^0.4.19;

import "../contracts/Verifier.sol";
import "./Verifier.sol";

contract roll_up{
bytes32 root;
Expand Down
12 changes: 6 additions & 6 deletions contracts/contract_deploy.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
(at your option) any later version.
roll_up is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
but WITHOUT ANY WARRANTY without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Expand All @@ -26,9 +26,6 @@
from web3.contract import ConciseContract


w3 = Web3(HTTPProvider("http://localhost:8545"));


def hex2int(elements):
ints = []
for el in elements:
Expand All @@ -48,7 +45,9 @@ def compile(tree_depth):
return(miximus_interface, verifier_interface)


def contract_deploy(tree_depth, vk_dir, merkle_root):
def contract_deploy(tree_depth, vk_dir, merkle_root, host="localhost"):
w3 = Web3(HTTPProvider(f"http://{host}:8545"))

miximus_interface , verifier_interface = compile(tree_depth)
with open(vk_dir) as json_data:
vk = json.load(json_data)
Expand Down Expand Up @@ -98,7 +97,8 @@ def contract_deploy(tree_depth, vk_dir, merkle_root):
miximus = w3.eth.contract(address=miximus_address, abi=abi,ContractFactoryClass=ConciseContract)
return(miximus)

def verify(contract, proof):
def verify(contract, proof, host="localhost"):
w3 = Web3(HTTPProvider(f"http://{host}:8545"))

tx_hash = contract.isTrue(proof["a"] , proof["a_p"], proof["b"], proof["b_p"] , proof["c"], proof["c_p"] , proof["h"] , proof["k"], proof["input"] , transact={'from': w3.eth.accounts[0], 'gas': 4000000})
tx_receipt = w3.eth.waitForTransactionReceipt(tx_hash, 10000)
Expand Down
27 changes: 27 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
version: "3"

services:

testrpc:
image: trufflesuite/ganache-cli:v6.1.8
ports:
- 8545
networks:
- blockchain

test:
build: .
working_dir: /root/roll_up/tests
command: python3 test.py testrpc
depends_on:
- testrpc
networks:
- blockchain
volumes:
- ./tests:/root/roll_up/tests
- ./pythonWrapper:/root/roll_up/pythonWrapper
- ./keys:/root/roll_up/keys
- ./contracts/contract_deploy.py:/root/roll_up/contracts/contract_deploy.py

networks:
blockchain:
Empty file added keys/.gitkeep
Empty file.
3 changes: 3 additions & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
web3==4.6.0
py-solc==3.1.0
bitstring==3.1.5
14 changes: 11 additions & 3 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,9 @@
import ed25519 as ed

from web3 import Web3, HTTPProvider, TestRPCProvider
w3 = Web3(HTTPProvider("http://localhost:8545"));

host = sys.argv[1] if len(sys.argv) > 1 else "localhost"
w3 = Web3(HTTPProvider(f"http://{host}:8545"));

if __name__ == "__main__":

Expand Down Expand Up @@ -120,8 +122,12 @@
leaves[j-1].append(old_leaf[j-1])

address.append(0)
<<<<<<< HEAD

# Get zk proof and merkle root
=======

>>>>>>> Add volumes to docker-compose for test editing
proof, root = genWitness(leaves, pub_x, pub_y, address, tree_depth,
rhs_leaf, new_leaf , R_x, R_y, S)

Expand Down Expand Up @@ -151,9 +157,11 @@

assert(libsnark2python(proof["input"][4:6])[0] == "0x" + leaves[1][0])

contract = contract_deploy(1, "../keys/vk.json", root)
contract = contract_deploy(1, "../keys/vk.json", root, host)

result = verify(contract, proof, host)

result = verify(contract, proof)
print(result)
assert(result["status"] == 1)
assert(w3.toHex(contract.getRoot())[:65] == root_final[:65])
except:
Expand Down

0 comments on commit 73835c5

Please sign in to comment.