Skip to content

Commit

Permalink
test pass: calling enclave through precompiled contract
Browse files Browse the repository at this point in the history
  • Loading branch information
imtypist committed Sep 7, 2022
1 parent 763bdc6 commit cb87a9d
Show file tree
Hide file tree
Showing 16 changed files with 41 additions and 19 deletions.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,5 @@

.vscode/
*.tar.gz
nodes/
nodes/
._tassl-1.1.1b-linux-x86_64
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,5 @@ cat > ~/.gitconfig << EOF
sslVerify = false
EOF
```

console v3.0.0调用预编译合约有问题,参见[https://github.com/FISCO-BCOS/console/issues/601](https://github.com/FISCO-BCOS/console/issues/601).
2 changes: 1 addition & 1 deletion build_chain.sh
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ compatibility_mtail_version=${default_mtail_version}
auth_mode="false"
monitor_mode="false"
auth_admin_account=
binary_path=""
binary_path="fisco-smart/build/fisco-bcos-air/fisco-bcos"
mtail_binary_path=""
wasm_mode="false"
serial_mode="false"
Expand Down
7 changes: 6 additions & 1 deletion console/.gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
log/
log/
deploylog.txt
account/
conf/*.crt
conf/*.cnf
conf/*.key
2 changes: 1 addition & 1 deletion console/conf/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ useSMCrypto = "false" # RPC SM crypto type
# enSslKey = "conf/sm_ensdk.key" # SM ssl cert file path

[network]
messageTimeout = "10000"
messageTimeout = "120000" # 设置2min timeout, 等待sgx执行结果
defaultGroup="group0" # Console default group to connect
peers=["127.0.0.1:20200", "127.0.0.1:20201"] # The peer list to connect

Expand Down
1 change: 1 addition & 0 deletions console/console_cmdlog.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
call InferencePrecompiled 0x0000000000000000000000000000000000006000 predict "cd /home/junqin/examples/pytorch && python3 pytorchexample.py"
1 change: 1 addition & 0 deletions console/contracts/.compiled/InferencePrecompiled.abi
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"string","name":"cmd","type":"string"}],"name":"predict","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]
1 change: 1 addition & 0 deletions console/contracts/.compiled/InferencePrecompiled.bin
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b506101ac806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063dcf4343514610030575b600080fd5b61004461003e366004610070565b50606090565b6040516100519190610121565b60405180910390f35b634e487b7160e01b600052604160045260246000fd5b60006020828403121561008257600080fd5b813567ffffffffffffffff8082111561009a57600080fd5b818401915084601f8301126100ae57600080fd5b8135818111156100c0576100c061005a565b604051601f8201601f19908116603f011681019083821181831017156100e8576100e861005a565b8160405282815287602084870101111561010157600080fd5b826020860160208301376000928101602001929092525095945050505050565b600060208083528351808285015260005b8181101561014e57858101830151858201604001528201610132565b81811115610160576000604083870101525b50601f01601f191692909201604001939250505056fea2646970667358221220c0f92e342296f313b4e223bebbd3faa5a359beb9467399653c538bf2ad76b7cf64736f6c634300080b0033
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
[{"inputs":[{"internalType":"string","name":"cmd","type":"string"}],"name":"predict","outputs":[{"internalType":"string","name":"","type":"string"}],"stateMutability":"view","type":"function"}]
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
608060405234801561001057600080fd5b506101ac806100206000396000f3fe608060405234801561001057600080fd5b506004361061002b5760003560e01c8063dcf4343514610030575b600080fd5b61004461003e366004610070565b50606090565b6040516100519190610121565b60405180910390f35b634e487b7160e01b600052604160045260246000fd5b60006020828403121561008257600080fd5b813567ffffffffffffffff8082111561009a57600080fd5b818401915084601f8301126100ae57600080fd5b8135818111156100c0576100c061005a565b604051601f8201601f19908116603f011681019083821181831017156100e8576100e861005a565b8160405282815287602084870101111561010157600080fd5b826020860160208301376000928101602001929092525095945050505050565b600060208083528351808285015260005b8181101561014e57858101830151858201604001528201610132565b81811115610160576000604083870101525b50601f01601f191692909201604001939250505056fea2646970667358221220c0f92e342296f313b4e223bebbd3faa5a359beb9467399653c538bf2ad76b7cf64736f6c634300080b0033
6 changes: 0 additions & 6 deletions console/contracts/InferencePrecompiled.sol

This file was deleted.

6 changes: 6 additions & 0 deletions console/contracts/solidity/InferencePrecompiled.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
pragma solidity >=0.6.10 <0.8.20;

contract InferencePrecompiled
{
function predict(string memory cmd) public view returns(string memory){}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,24 +54,27 @@ std::shared_ptr<PrecompiledExecResult> InferencePrecompiled::call(

if (func == name2Selector[INFERENCE_METHOD_PREDICT])
{ // predict() function call
// default retMsg
std::string retValue = "Call Inference!";
std::string retValue = "retCode: ";

// std::string execString = "cd /home/junqin/gramine/examples/pytorch;gramine-direct pytorch pytorchexample.py";
std::string resPath = "/home/junqin/examples/pytorch/result.txt";
std::string cmd;
codec.decode(data, cmd);

int retCode = system(cmd.c_str());
if (retCode != -1 and retCode != 127)

if ((retCode != -1) && WIFEXITED(retCode) && (WEXITSTATUS(retCode) == 0))
{
std::ifstream ifs;
ifs.open(resPath);
if (ifs.is_open())
{
getline(ifs, retValue);
}
PRECOMPILED_LOG(ERROR) << LOG_BADGE("InferencePrecompiled") << LOG_DESC("predict")
PRECOMPILED_LOG(TRACE) << LOG_BADGE("InferencePrecompiled") << LOG_DESC("predict")
<< LOG_KV("result", retValue);
}else
{
retValue = retValue + std::to_string(retCode);
}
_callParameters->setExecResult(codec.encode(retValue));
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@ pragma solidity >=0.6.10 <0.8.20;

contract InferencePrecompiled
{
function predict(string cmd) public view returns(string){}
}
function predict(string memory cmd) public view returns(string memory){}
}
5 changes: 4 additions & 1 deletion install_deps.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
# deps for fisco-bcos
# 注意:cmake可以用snap安装较高版本,apt默认包不满足最低版本要求
# gcc/g++-9编译可能会报错,可以安装gcc/g++-10,配合update-alternatives使用
# 重编译删除build, deps/src/*stamp, deps/src/*build文件夹后再编译:mkdir -p build && cd build; cmake ..; make -j4
# 重编译删除build, deps/src/*stamp, deps/src/*build文件夹后再编译:mkdir -p build && cd build; cmake ..; make BuildInfo.h; make fisco-bcos -j4
sudo apt install -y cmake g++ git curl build-essential autoconf texinfo flex bison libzstd-dev libpython3-dev python-dev wget libgmp-dev

curl https://sh.rustup.rs -sSf | bash -s -- -y
Expand Down Expand Up @@ -59,3 +59,6 @@ sudo ninja -C build/ install
# sudo apt-get update

# sudo apt-get install gramine # for 5.11+ upstream, in-kernel driver

# install torchvision
sudo pip3 install torchvision
5 changes: 4 additions & 1 deletion start_blockchain_network.sh
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
#!/bin/bash

# stop all nodes
bash nodes/127.0.0.1/stop_all.sh

# rm old nodes dir
rm -rf nodes/

Expand All @@ -13,4 +16,4 @@ bash nodes/127.0.0.1/start_all.sh
cp -r nodes/127.0.0.1/sdk/* console/conf

# start console
cd console && bash start.sh
bash console/start.sh

0 comments on commit cb87a9d

Please sign in to comment.