Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Offchain worker EVM demo #1028

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
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
90 changes: 90 additions & 0 deletions cli/demo_ocw_smart_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
#!/bin/bash

# local setup (if not built with docker):
# build the integritee-node (https://github.com/integritee-network/integritee-node) with
# cargo build --release --features skip-ias-check,skip-extrinsic-filtering
# build the offchain worker with:
# WORKER_MODE=offchain-worker ADDITIONAL_FEATURES=evm make
#
# run all on localhost:
# parentchain:
# cd integritee-node/target/release
# ./integritee-node purge-chain --dev
# ./integritee-node --tmp --dev -lruntime=debug
#
# worker:
# cd worker/bin
# export RUST_LOG=integritee_service=info,ita_stf=debug
# ./integritee-service --clean-reset run --skip-ra --dev
#
# then run this script:
# cd worker/cli
# export RUST_LOG=integritee-cli=info,ita_stf=info
# ./demo_ocw_smart_contract.sh
#
# Note: you can change the chain node with -p and the worker port with -P :
# ./demo_ocw_smart_contract.sh -p 9994 -P 2094

while getopts ":m:p:P:" opt; do
case $opt in
m)
READMRENCLAVE=$OPTARG
;;
p)
NPORT=$OPTARG
;;
P)
RPORT=$OPTARG
;;
esac
done

# Bytecode from Counter.sol with slightly modified values
SMARTCONTRACT="608060405234801561001057600080fd5b50602260008190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550610378806100696000396000f3fe6080604052600436106100435760003560e01c80631003e2d21461004e57806333cf508014610077578063371303c0146100a257806358992216146100b957610044565b5b6042600081905550005b34801561005a57600080fd5b50610075600480360381019061007091906101e4565b6100e4565b005b34801561008357600080fd5b5061008c610140565b604051610099919061024a565b60405180910390f35b3480156100ae57600080fd5b506100b7610149565b005b3480156100c557600080fd5b506100ce6101a5565b6040516100db919061022f565b60405180910390f35b806000808282546100f59190610265565b9250508190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff16021790555050565b60008054905090565b600160008082825461015b9190610265565b9250508190555033600160006101000a81548173ffffffffffffffffffffffffffffffffffffffff021916908373ffffffffffffffffffffffffffffffffffffffff160217905550565b6000600160009054906101000a900473ffffffffffffffffffffffffffffffffffffffff16905090565b6000813590506101de8161032b565b92915050565b6000602082840312156101fa576101f9610326565b5b6000610208848285016101cf565b91505092915050565b61021a816102bb565b82525050565b610229816102ed565b82525050565b60006020820190506102446000830184610211565b92915050565b600060208201905061025f6000830184610220565b92915050565b6000610270826102ed565b915061027b836102ed565b9250827fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff038211156102b0576102af6102f7565b5b828201905092915050565b60006102c6826102cd565b9050919050565b600073ffffffffffffffffffffffffffffffffffffffff82169050919050565b6000819050919050565b7f4e487b7100000000000000000000000000000000000000000000000000000000600052601160045260246000fd5b600080fd5b610334816102ed565b811461033f57600080fd5b5056fea26469706673582212206242c58933a5e80fcfdd7f0044569af44caa21c61740067483a287cc361fc5b464736f6c63430008070033"
INCFUNTION="371303c0"
DEFAULTFUNCTION="371303c1"
ADDFUNCTION="1003e2d20000000000000000000000000000000000000000000000000000000000000003"

# using default port if none given as arguments
NPORT=${NPORT:-9944}
RPORT=${RPORT:-2000}

echo "Using node-port ${NPORT}"
echo "Using trusted-worker-port ${RPORT}"

AMOUNTSHIELD=50000000000
AMOUNTTRANSFER=40000000000

CLIENT="./../bin/integritee-cli -p ${NPORT} -P ${RPORT}"

# this will always take the first MRENCLAVE found in the registry !!
read -r MRENCLAVE <<< "$($CLIENT list-workers | awk '/ MRENCLAVE: / { print $2; exit }')"
echo "Reading MRENCLAVE from worker list: ${MRENCLAVE}"

ACCOUNTALICE=//Alice

echo "Create smart contract"
${CLIENT} trusted --mrenclave ${MRENCLAVE} evm-create ${ACCOUNTALICE} ${SMARTCONTRACT}
echo ""

echo "Get storage"
${CLIENT} trusted --mrenclave ${MRENCLAVE} evm-read ${ACCOUNTALICE} 0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f
echo ""

echo "Call inc function"
${CLIENT} trusted --mrenclave ${MRENCLAVE} evm-call ${ACCOUNTALICE} 0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f ${INCFUNTION}
echo ""

echo "Get storage"
${CLIENT} trusted --mrenclave ${MRENCLAVE} evm-read ${ACCOUNTALICE} 0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f
echo ""

echo "Call add 3 function"
${CLIENT} trusted --mrenclave ${MRENCLAVE} evm-call ${ACCOUNTALICE} 0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f ${ADDFUNCTION}
echo ""

echo "Get storage"
${CLIENT} trusted --mrenclave ${MRENCLAVE} evm-read ${ACCOUNTALICE} 0x8a50db1e0f9452cfd91be8dc004ceb11cb08832f
echo ""

exit 0
20 changes: 20 additions & 0 deletions docker/demo-ocw-smart-contract.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
services:
demo-ocw-smart-contract:
image: integritee-cli:dev
container_name: integritee-ocw-smart-contract-demo
build:
context: ..
dockerfile: build.Dockerfile
target: deployed-client
depends_on: ['integritee-node', 'integritee-worker-1', 'integritee-worker-2']
environment:
- RUST_LOG=warn,ws=warn,itc_rpc_client=warn
networks:
- integritee-test-network
entrypoint: "dockerize -wait http://integritee-worker-2:4646/is_initialized -timeout 250s
/usr/local/worker-cli/demo_direct_call_2_workers.sh -p 9912 -u ws://integritee-node
-V wss://integritee-worker-1 -A 2011 -W wss://integritee-worker-2 -B 2012 -C /usr/local/bin/integritee-cli 2>&1"
restart: "no"
networks:
integritee-test-network:
driver: bridge