Thursday, May 7, 2020

RISC-v emulator

Changes are based on https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html

For Ubuntu/Debian, in addition to

sudo apt install autoconf automake autotools-dev curl libmpc-dev libmpfr-dev libgmp-dev \
                 gawk build-essential bison flex texinfo gperf libtool patchutils bc \
                 zlib1g-dev libexpat-dev git

You will need the development headers for

sudo apt-get install libglib2.0-dev libpixman-1-dev libncurses-dev


Before building Busybear Linux, you will need to softlink riscv-pk into busy bear-linux because git checkout put riscv-pk into the riscv64-linux.


cd riscv64-linux/busybear-linux
rm -rf src/riscv-pk
ln -s ../riscv-pk src/


You need to enable the following modules within .config in the linux folder.

CONFIG_E100=y
CONFIG_E1000=y
CONFIG_E1000E=y


Start the QEMU emulator with the following command:

  sudo qemu-system-riscv64 \
        -nographic \
        -machine virt \
        -kernel riscv-pk/build/bbl \
        -append "root=/dev/vda ro console=ttyS0" \
        -drive file=busybear-linux/busybear.bin,format=raw,id=hd0 \
        -device virtio-blk-device,drive=hd0 \
        -netdev type=tap,script=./ifup,downscript=./ifdown,id=net0 \
        -device virtio-net-device,netdev=net0


Saturday, February 29, 2020

Hyperledger Problems and Fixes


Problem 1: 
Error: got unexpected status: BAD_REQUEST -- error validating channel creation transaction for new channel 'carsales', could not successfully apply update to template configuration: error authorizing update: error validating DeltaSet: policy for [Group]  /Channel/Application not satisfied: implicit policy evaluation failed - 0 sub-policies were satisfied, but this policy requires 1 of the 'Admins' sub-policies to be satisfied


Solution: 
Remove old channel, chaincode, and other information
$> sudo rm -rf /var/hyperledger

Then, restart all services so that information in the above folder will be recreated. E.g.,

Restart orderer
$> sudo systemctl start fabric-orderer.service

Restart peer
$> sudo systemctl start fabric-peer0-org1.service



Problem 2:
My peer nodes are behind a firewall. The docker container created for building the chaincode cannot resolve URL.

When running peer chaincode instantiate ..., I got
2020-03-10 13:52:58.465 EST [chaincodeCmd] checkChaincodeCmdParams -> INFO 001 Using default escc
2020-03-10 13:52:58.466 EST [chaincodeCmd] checkChaincodeCmdParams -> INFO 002 Using default vscc
Error: could not assemble transaction, err proposal response was not successful, error code 500, msg error starting container: error starting container: Failed to generate platform-specific docker build: Error returned from build: 1 "Copying from /chaincode/input/src/ to /tmp/tmp.sERrFqHiCD
Gradle build
Starting a Gradle Daemon, 1 incompatible and 1 stopped Daemons could not be reused, use --status for details
:compileJava FAILED

FAILURE: Build failed with an exception.

* What went wrong:
Could not resolve all files for configuration ':compileClasspath'.
> Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
  Required by:
      project :
   > Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
      > Could not get resource 'https://hyperledger.jfrog.io/hyperledger/fabric-maven/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
         > Could not GET 'https://hyperledger.jfrog.io/hyperledger/fabric-maven/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
            > hyperledger.jfrog.io
   > Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
      > Could not get resource 'https://repo.maven.apache.org/maven2/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
         > Could not GET 'https://repo.maven.apache.org/maven2/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
            > repo.maven.apache.org: Temporary failure in name resolution
   > Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
      > Could not get resource 'https://repository.mulesoft.org/nexus/content/repositories/public/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
         > Could not GET 'https://repository.mulesoft.org/nexus/content/repositories/public/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
            > repository.mulesoft.org
   > Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
      > Could not get resource 'https://repo1.maven.org/maven2/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
         > Could not GET 'https://repo1.maven.org/maven2/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
            > repo1.maven.org
   > Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
      > Could not get resource 'https://jcenter.bintray.com/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
         > Could not GET 'https://jcenter.bintray.com/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
            > jcenter.bintray.com
   > Could not resolve org.hyperledger.fabric-chaincode-java:fabric-chaincode-shim:1.4.5.
      > Could not get resource 'https://jitpack.io/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
         > Could not GET 'https://jitpack.io/org/hyperledger/fabric-chaincode-java/fabric-chaincode-shim/1.4.5/fabric-chaincode-shim-1.4.5.pom'.
            > jitpack.io
> Could not resolve com.owlike:genson:1.5.
  Required by:
      project :
   > Could not resolve com.owlike:genson:1.5.
      > Could not get resource 'https://hyperledger.jfrog.io/hyperledger/fabric-maven/com/owlike/genson/1.5/genson-1.5.pom'.
         > Could not GET 'https://hyperledger.jfrog.io/hyperledger/fabric-maven/com/owlike/genson/1.5/genson-1.5.pom'.
            > hyperledger.jfrog.io: Temporary failure in name resolution
   > Could not resolve com.owlike:genson:1.5.
      > Could not get resource 'https://repo.maven.apache.org/maven2/com/owlike/genson/1.5/genson-1.5.pom'.
         > Could not GET 'https://repo.maven.apache.org/maven2/com/owlike/genson/1.5/genson-1.5.pom'.
            > repo.maven.apache.org
   > Could not resolve com.owlike:genson:1.5.
      > Could not get resource 'https://repository.mulesoft.org/nexus/content/repositories/public/com/owlike/genson/1.5/genson-1.5.pom'.
         > Could not GET 'https://repository.mulesoft.org/nexus/content/repositories/public/com/owlike/genson/1.5/genson-1.5.pom'.
            > repository.mulesoft.org: Temporary failure in name resolution
   > Could not resolve com.owlike:genson:1.5.
      > Could not get resource 'https://repo1.maven.org/maven2/com/owlike/genson/1.5/genson-1.5.pom'.
         > Could not GET 'https://repo1.maven.org/maven2/com/owlike/genson/1.5/genson-1.5.pom'.
            > repo1.maven.org: Temporary failure in name resolution
   > Could not resolve com.owlike:genson:1.5.
      > Could not get resource 'https://jcenter.bintray.com/com/owlike/genson/1.5/genson-1.5.pom'.
         > Could not GET 'https://jcenter.bintray.com/com/owlike/genson/1.5/genson-1.5.pom'.
            > jcenter.bintray.com: Temporary failure in name resolution
   > Could not resolve com.owlike:genson:1.5.
      > Could not get resource 'https://jitpack.io/com/owlike/genson/1.5/genson-1.5.pom'.
         > Could not GET 'https://jitpack.io/com/owlike/genson/1.5/genson-1.5.pom'.
            > jitpack.io: Temporary failure in name resolution

* Try:
Run with --stacktrace option to get the stack trace. Run with --info or --debug option to get more log output. Run with --scan to get full insights.

* Get more help at https://help.gradle.org

BUILD FAILED in 22s
1 actionable task: 1 executed

"

Solution1 (Manual):
In the terminal of peer0org1, run this to attach to the docker
$> docker exec -it $(docker ps | grep hyperledger/fabric-javaenv | cut -d" " -f1) bash
In the attached docker terminal, run this 
$> sudo echo "nameserver 8.8.8.8" >> /etc/resolv.conf
Solution2 (Automated):
$> ssh -n -f USER_NAME@Peer0Org1Address "bash $PEER_ROOT/configDNS.bash 3" &
The content of the configDNS.bash is
```
sleep $SLEEP_TIME
docker exec -t $(docker ps | grep hyperledger/fabric-javaenv | cut -d" " -f1) bash -c 'echo "nameserver 8.8.8.8" >> /etc/resolv.conf'
```

Thursday, May 11, 2017

[solved] Gitlab upgrade problem 'GitlabCiService'

 ================================================================================
    Error executing action `run` on resource 'bash[migrate gitlab-rails database]'
    ================================================================================
    
    Mixlib::ShellOut::ShellCommandFailed
    ------------------------------------
    Expected process to exit with [0], but received '1'
    ---- Begin output of "bash"  "/tmp/chef-script20170511-11989-rxzicg" ----
    STDOUT: rake aborted!
    StandardError: An error has occurred, this and all later migrations canceled:
    
    The single-table inheritance mechanism failed to locate the subclass: 'GitlabCiService'. This error is raised because the column 'type' is reserved for storing the class in case of inheritance. Please rename this column if you didn't intend it to be used for storing the inheritance class or overwrite Service.inheritance_column to use another column for that information./opt/gitlab/embedded/service/gitlab-rails/db/migrate/20140907220153_serialize_service_properties.rb:26:in `each'
    /opt/gitlab/embedded/service/gitlab-rails/db/migrate/20140907220153_serialize_service_properties.rb:26:in `change'

    /opt/gitlab/embedded/service/gitlab-rails/lib/tasks/gitlab/db.rake:50:in `block (3 levels) in <top (required)>'


try
> sudo gitlab-rails dbconsole 
gitlabhq_production=> DELETE FROM services WHERE type = 'GitlabCiService';

after run 
> gitlab-ctl reconfigure

then it should fix the table.




Monday, August 3, 2015

Homomorphic-Simon implementation: Flint library compile error

g++ -I/usr/local/include -I/opt/local/include -O3 -fopenmp -Wall -pedantic -DYASHE -o Simon main.o Simon.o timing.o YASHE/BitVector.o YASHE/Ciphertext.o YASHE/Entropy.o YASHE/Sampler.o YASHE/YASHEKey.o -L/opt/local/lib -lgmp -lgmpxx -lcrypto -lm -lmpfr -lflint
main.o: In function `YASHEParams::~YASHEParams()':
main.cpp:(.text._ZN11YASHEParamsD2Ev[_ZN11YASHEParamsD5Ev]+0x39): undefined reference to `_fmpz_clear_mpz'
main.cpp:(.text._ZN11YASHEParamsD2Ev[_ZN11YASHEParamsD5Ev]+0x51): undefined reference to `_fmpz_clear_mpz'
main.cpp:(.text._ZN11YASHEParamsD2Ev[_ZN11YASHEParamsD5Ev]+0x74): undefined reference to `_fmpz_clear_mpz'
main.o: In function `std::vector<Ciphertext, std::allocator<Ciphertext> >::~vector()':
main.cpp:(.text._ZNSt6vectorI10CiphertextSaIS0_EED2Ev[_ZNSt6vectorI10CiphertextSaIS0_EED5Ev]+0x1d): undefined reference to `fmpz_mod_poly_clear'
main.o: In function `std::vector<std::vector<Ciphertext, std::allocator<Ciphertext> >, std::allocator<std::vector<Ciphertext, std::allocator<Ciphertext> > > >::~vector()':
main.cpp:(.text._ZNSt6vectorIS_I10CiphertextSaIS0_EESaIS2_EED2Ev[_ZNSt6vectorIS_I10CiphertextSaIS0_EESaIS2_EED5Ev]+0x35): undefined reference to `fmpz_mod_poly_clear'
main.o: In function `void std::__uninitialized_fill_n<false>::__uninit_fill_n<std::vector<Ciphertext, std::allocator<Ciphertext> >*, unsigned long, std::vector<Ciphertext, std::allocator<Ciphertext> > >(std::vector<Ciphertext, std::allocator<Ciphertext> >*, unsigned long, std::vector<Ciphertext, std::allocator<Ciphertext> > const&)':
main.cpp:(.text._ZNSt22__uninitialized_fill_nILb0EE15__uninit_fill_nIPSt6vectorI10CiphertextSaIS3_EEmS5_EEvT_T0_RKT1_[_ZNSt22__uninitialized_fill_nILb0EE15__uninit_fill_nIPSt6vectorI10CiphertextSaIS3_EEmS5_EEvT_T0_RKT1_]+0x113): undefined reference to `fmpz_mod_poly_clear'
main.o: In function `main':
main.cpp:(.text.startup+0x6f): undefined reference to `fmpz_set_str'
main.cpp:(.text.startup+0x7c): undefined reference to `fmpz_cmp'
main.cpp:(.text.startup+0x531): undefined reference to `_fmpz_clear_mpz'

main.cpp:(.text.startup+0x5b1): undefined reference to `_fmpz_clear_mpz'
...
...
...

YASHE/YASHEKey.o:YASHEKey.cpp:(.text._ZNSt6vectorIN5flint26fmpz_mod_polyxx_expressionINS0_10operations9immediateENS0_6detail18fmpz_mod_poly_dataEEESaIS6_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS6_S8_EEmRKS6_[_ZNSt6vectorIN5flint26fmpz_mod_polyxx_expressionINS0_10operations9immediateENS0_6detail18fmpz_mod_poly_dataEEESaIS6_EE14_M_fill_insertEN9__gnu_cxx17__normal_iteratorIPS6_S8_EEmRKS6_]+0x4d4): more undefined references to `fmpz_mod_poly_clear' follow
collect2: error: ld returned 1 exit status


This is caused by the installation of the old flint library. Typically done by apt-get install. 
So get remove the error, you need to run
$> sudo apt-get remove libflint-dev

then soft symlink the flint.h to the /usr/local/include/ by this command
$> sudo ln -s /usr/local/include/flint/flint.h /usr/local/include/flint.h


LD_LIBRARY_PATH=/usr/local/lib
export LD_LIBRARY_PATH

then it should work.

Monday, June 29, 2015

NTL library: symbol(s) not found for architecture x86_64


It took me a few days to resolve this problem with the NTL library on Mac OS X.
http://www.shoup.net/ntl/doc/tour-unix.html

So I am going to share the solution with anyone who might run into this problem.

The error:

ph$ clang++ -v -g -O2   -o bv_scheme NTL_examples.o  -lm -lgmp -lntl
Apple LLVM version 6.1.0 (clang-602.0.53) (based on LLVM 3.6.0svn)
Target: x86_64-apple-darwin14.3.0
Thread model: posix
 "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/ld" -demangle -dynamic -arch x86_64 -macosx_version_min 10.10.0 -o bv_scheme NTL_examples.o -lm -lgmp -lntl -lc++ -lSystem /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/../lib/clang/6.1.0/lib/darwin/libclang_rt.osx.a
Undefined symbols for architecture x86_64:
  "NTL::operator<<(std::__1::basic_ostream<char, std::__1::char_traits<char> >&, NTL::ZZ const&)", referenced from:
      _main in NTL_examples.o
  "std::istream::get()", referenced from:
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
  "std::istream::peek()", referenced from:
      NTL::SkipWhiteSpace(std::istream&) in libntl.a(tools.o)
  "std::ostream& std::ostream::_M_insert<long>(long)", referenced from:
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::ios_base::Init::Init()", referenced from:
      __GLOBAL__sub_I_lip.c in libntl.a(lip.o)
      __GLOBAL__sub_I_tools.c in libntl.a(tools.o)
  "std::ios_base::Init::~Init()", referenced from:
      __GLOBAL__sub_I_lip.c in libntl.a(lip.o)
      __GLOBAL__sub_I_tools.c in libntl.a(tools.o)
  "std::basic_ios<char, std::char_traits<char> >::clear(std::_Ios_Iostate)", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
  "std::basic_ostream<char, std::char_traits<char> >& std::__ostream_insert<char, std::char_traits<char> >(std::basic_ostream<char, std::char_traits<char> >&, char const*, long)", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
      NTL::PrintTime(std::ostream&, double) in libntl.a(tools.o)
  "std::cerr", referenced from:
      NTL::TerminalError(char const*) in libntl.a(tools.o)
ld: symbol(s) not found for architecture x86_64

clang: error: linker command failed with exit code 1 (use -v to see invocation)

Because Mac OS X now using libc++ rather than libstdc++, so you will need to compile the NTL library with libc++. You have to force it to use the libc++ option. The new compiling steps:

1. ./configure  NTL_GMP_LIP=on
2. open makefile under src/ and change to the following
CXX=clang++
# A C++ compiler, e.g., g++, CC, xlC 
LDLIBS=-lm -lc++
# libraries for linking C++ programs

3. make & sudo make install

Then you should be able to use the NTL library natively in Mac OS X.

Thursday, May 21, 2015

Things about PhoneLab

I am starting this post to document things about PhoneLab (www.phone-lab.org). Hopefully you find it useful.
https://www.phone-lab.org/experiment/start/


Download source

Initialize the repo
repo init -u http://platform.phone-lab.org:8080/platform/manifest -b phonelab/android-4.4.4_r1/develop

actually download the code with
repo sync


Build the source


source build/envsetup.sh
lunch aosp_hammerhead-userdebug
Compile the code with multiple cores.
make -j4



Build the Cruncher tool

source: https://www.phone-lab.org/experiment/data/#cruncher


git clone http://platform.phone-lab.org:8080/p/phonelab/cruncher.git
cd cruncher/crunchersudo



add these packages to the packages.txt
gfortran
libblas-dev
liblas-bin
liblas-c-dev
libatlas-dev
libatlas-base-dev
 
 
xargs -a packages.txt apt-get install
sudo pip install -r requirements.txt

Monday, April 13, 2015

node-red-contrib-bean installation error

> xpc-connection@0.1.3 install /Users/ph/.node-red/node_modules/node-red-contrib-bean/node_modules/ble-bean/node_modules/noble/node_modules/xpc-connection
> node-gyp rebuild

  CXX(target) Release/obj.target/binding/src/XpcConnection.o
cc1plus: error: argument to '-O' should be a non-negative integer, 'g', 's' or 'fast'
make: *** [Release/obj.target/binding/src/XpcConnection.o] Error 1
gyp ERR! build error 
gyp ERR! stack Error: `make` failed with exit code: 2
gyp ERR! stack     at ChildProcess.onExit (/usr/local/lib/node_modules/npm/node_modules/node-gyp/lib/build.js:267:23)
gyp ERR! stack     at ChildProcess.emit (events.js:98:17)
gyp ERR! stack     at Process.ChildProcess._handle.onexit (child_process.js:820:12)
gyp ERR! System Darwin 14.3.0
gyp ERR! command "node" "/usr/local/lib/node_modules/npm/node_modules/node-gyp/bin/node-gyp.js" "rebuild"
gyp ERR! cwd /Users/ph/.node-red/node_modules/node-red-contrib-bean/node_modules/ble-bean/node_modules/noble/node_modules/xpc-connection
gyp ERR! node -v v0.10.36
gyp ERR! node-gyp -v v1.0.1
gyp ERR! not ok 
npm WARN optional dep failed, continuing xpc-connection@0.1.3

> noble@0.3.13 install /Users/ph/.node-red/node_modules/node-red-contrib-bean/node_modules/ble-bean/node_modules/noble
> node-gyp rebuild

  LINK(target) Release/hci-ble
  LINK(target) Release/hci-ble: Finished
  LINK(target) Release/l2cap-ble
  LINK(target) Release/l2cap-ble: Finished
node-red-contrib-bean@0.3.2 .node-red/node_modules/node-red-contrib-bean

└── ble-bean@2.1.0 (noble-device@0.1.3, crc@2.1.1, noble@0.3.13)


This is because the use of wrong GCC, as documented in 
https://github.com/sandeepmistry/node-xpc-connection/issues/2

$ which gcc
/usr/bin/gcc
Try setting the path, just before npm install:
export PATH=/usr/bin:$PATH

RISC-v emulator

Changes are based on https://risc-v-getting-started-guide.readthedocs.io/en/latest/linux-qemu.html For Ubuntu/Debian, in addition to sud...