Skip to content

Commit

Permalink
Initial version of cleaned up PoC codebase
Browse files Browse the repository at this point in the history
  • Loading branch information
mvdbos committed Apr 17, 2020
0 parents commit 44e0e32
Show file tree
Hide file tree
Showing 52 changed files with 2,685 additions and 0 deletions.
100 changes: 100 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
*.dSYM
.vscode
**/proving_material
**/verification_material
**/prover_verifier_shared
**/notary/bin/*
**/workflows/bin/*
#**/block_stores/**/LOCK
**/libpv*.so

.idea/*

corda/

.DS_Store

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Kotlin template
# Compiled class file
*.class

# Log file
*.log
**/logs/

# BlueJ files
*.ctxt

# Mobile Tools for Java (J2ME)
.mtj.tmp/

# Package Files #
*.jar
*.war
*.nar
*.ear
*.zip
*.tar.gz
*.rar

!pepper/*.jar

# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
hs_err_pid*

### Gradle template
.gradle
**/build/

# Ignore Gradle GUI config
gradle-app.setting

# Avoid ignoring Gradle wrapper jar file (.jar files are usually ignored)
!gradle-wrapper.jar

# Cache of project
.gradletasknamecache

# # Work around https://youtrack.jetbrains.com/issue/IDEA-116898
# gradle/wrapper/gradle-wrapper.properties

36 changes: 36 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
# For victor

## Tests to use:

`com.ing.zknotary.notary.transactions.VictorsSerializeProveVerifyTest`

This test will give you:

* a proper transaction data structure
* a place to test serialization logic
* an opportunity to test proving and verifying e2e between Kotlin and Zinc.

Feel free to created dedicated unit tests for the serializer.

## Serializer to implement:

`com.ing.zknotary.common.serializer.VictorsZKInputSerializer`

If you have a better name once you know how you will do it, please feel free to rename it. :-)

I (Matthijs) will also implement a naive JSON/CordaSerialized serializer for inspiration/reference: `com.ing.zknotary.common.serializer.JsonZKInputSerializer`.
If we can deserialize CordaSerialized components in Zinc into meaningful structures, this might even work.

## Prover/Verifier to implement:

Prover: `com.ing.zknotary.common.zkp.ZincProverCLI`

Verifier: `com.ing.zknotary.common.zkp.ZincVerifierCLI`

We have agreed to initially do it the CLI way, so that we can focus on the serialization/deserialization logic first.
Once we have that in place, we will move to `ZincProverNative` and `ZincVerifierNative`.

> Please note that the ZKId of a transaction (our custom Merkle root) is currently calculated based on the
> CordaSerialized form of transaction components. We may be able to change that to another format, but if not, we will have to
> pass that format to Zinc as well to recalculate the ZKId. Then we will have to deserialize it to verify the validity of the contents.
10 changes: 10 additions & 0 deletions bin/compile_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

cd $(git rev-parse --show-toplevel)/pepper

contract_name=$1
debug_flag=$2 # DEBUG=1, default is DEBUG=0

if [[ -z "${contract_name}" ]]; then echo "Contract name is a required argument"; exit 1; fi

docker run -v "$(pwd)":/opt/pequin/pepper -it mvdbos/corda-zk-notary bash -c "export PEPPER_BIN_PATH=\"/opt/pequin/pepper/bin\" && cd /opt/pequin/pepper && ./compile_contract.sh ${contract_name} ${debug_flag}"
47 changes: 47 additions & 0 deletions bin/deploy_contract.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#!/usr/bin/env bash

cd $(git rev-parse --show-toplevel)

contract_name=$1

if [[ -z "${contract_name}" ]]; then echo "Contract name is a required argument"; exit 1; fi


mkdir -p ./{workflows,notary}/proving_material
mkdir -p ./{workflows,notary}/verification_material
mkdir -p ./{workflows,notary}/prover_verifier_shared
mkdir -p ./{workflows,notary}/src/test/resources

rm -rf ./{workflows,notary}/proving_material/*
rm -rf ./{workflows,notary}/verification_material/*
rm -rf ./{workflows,notary}/prover_verifier_shared/*
rm -f ./{workflows,notary}/src/test/resources/libpv.so

cp -r ./pepper/prover_verifier_shared ./workflows/
cp -r ./pepper/prover_verifier_shared ./notary/

cp ./pepper/bin/${contract_name}.params ./workflows/prover_verifier_shared/
cp ./pepper/bin/${contract_name}.params ./notary/prover_verifier_shared/

cp ./pepper/bin/${contract_name}.pws ./workflows/proving_material/
cp ./pepper/bin/${contract_name}.pws ./notary/proving_material/

cp ./pepper/proving_material/${contract_name}.pkey ./workflows/proving_material/
cp ./pepper/proving_material/${contract_name}.pkey ./notary/proving_material/

cp ./pepper/verification_material/${contract_name}.vkey ./workflows/verification_material/
cp ./pepper/verification_material/${contract_name}.vkey ./notary/verification_material/

# This should also be dynamically named for the contract
cp ./pepper/compiled_libs/libpv.so workflows/src/test/resources/
cp ./pepper/compiled_libs/libpv.so notary/src/test/resources/

## Copy Jsnark circuit files
#cp ./pepper/*.arith ./workflows/bin/
#cp ./pepper/*.arith ./notary/bin/
#cp ./pepper/*.in ./workflows/bin/
#cp ./pepper/*.in ./notary/bin/

# Copy executables
cp ./pepper/bin/* ./notary/bin/
cp ./pepper/bin/* ./workflows/bin/
4 changes: 4 additions & 0 deletions bin/enter_docker.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
#!/usr/bin/env bash
cd $(git rev-parse --show-toplevel)/pepper

docker run --rm -v /"$(pwd)":/opt/pequin/pepper -it mvdbos/corda-zk-notary bash
9 changes: 9 additions & 0 deletions bin/run_c_unit_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#!/usr/bin/env bash

cd $(git rev-parse --show-toplevel)/pepper/apps

if [ ! -f Makefile ]; then
cmake .
fi
make test
#clang simple_contract_test.c -ldl -rdynamic -lcmocka -Ied25519 -std=c89 -o /tmp/simple_contract_test && /tmp/simple_contract_test && rm /tmp/simple_contract_test
21 changes: 21 additions & 0 deletions bin/run_notary_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

cd $(git rev-parse --show-toplevel)

test_name=$1

# if test_name is empty, set it to 'com.ing.zknotary.flows.SimpleZKNotaryFlowTest'
if [[ -z "$test_name" ]]
then
test_name="com.ing.zknotary.notary.transactions.ComplexZKProofTest"
fi

# Mounting pepper dir is necessary for our gadget to be able to find the .arith files.
docker run \
--rm \
-v "$(pwd)":/src \
-v "$(pwd)/pepper":/opt/pequin/pepper \
-v ~/.gradle/caches:/root/.gradle/caches \
-v ~/.m2/repository:/root/.m2/repository \
mvdbos/corda-zk-notary \
bash -c "cd /src && export PEPPER_BIN_PATH=\"/src/notary/bin\" && gradle --no-daemon --info notary:cleanTest notary:test --tests \"${test_name}\""
10 changes: 10 additions & 0 deletions bin/run_prove_verify_test-NOCOMPILE.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

cd $(git rev-parse --show-toplevel)/pepper

contract_name=$1
debug_flag=$2 # DEBUG=1, default is DEBUG=0

if [[ -z "${contract_name}" ]]; then echo "Contract name is a required argument"; exit 1; fi

docker run -v "$(pwd)":/opt/pequin/pepper -it mvdbos/corda-zk-notary bash -c "cd /opt/pequin/pepper && ./test_prove_verify-NOCOMPILE.sh ${contract_name} ${debug_flag}"
10 changes: 10 additions & 0 deletions bin/run_prove_verify_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/usr/bin/env bash

cd $(git rev-parse --show-toplevel)/pepper

contract_name=$1
debug_flag=$2 # DEBUG=1, default is DEBUG=0

if [[ -z "${contract_name}" ]]; then echo "Contract name is a required argument"; exit 1; fi

docker run -v "$(pwd)":/opt/pequin/pepper -it mvdbos/corda-zk-notary bash -c "cd /opt/pequin/pepper && ./test_prove_verify.sh ${contract_name} ${debug_flag}"
7 changes: 7 additions & 0 deletions bin/run_tests-NOCOMPILE.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

contract_name=$1

if [[ -z "${contract_name}" ]]; then echo "Contract name is a required argument"; exit 1; fi

sh ./bin/deploy_contract.sh ${contract_name} && sh ./bin/run_notary_test.sh
8 changes: 8 additions & 0 deletions bin/run_tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/usr/bin/env bash

contract_name=$1
debug_flag=$2 # DEBUG=1, default is DEBUG=0

if [[ -z "${contract_name}" ]]; then echo "Contract name is a required argument"; exit 1; fi

sh ./bin/compile_contract.sh ${contract_name} ${debug_flag} && sh ./bin/deploy_contract.sh ${contract_name} && sh ./bin/run_notary_test.sh
103 changes: 103 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
buildscript {
Properties constants = new Properties()
file("$projectDir/./constants.properties").withInputStream { constants.load(it) }

ext {

//corda_gradle_plugins_version = '4.0.45'

corda_release_group = constants.getProperty("cordaReleaseGroup")
corda_core_release_group = constants.getProperty("cordaCoreReleaseGroup")
corda_release_version = constants.getProperty("cordaVersion")
corda_core_release_version = constants.getProperty("cordaCoreVersion")
corda_gradle_plugins_version = constants.getProperty("gradlePluginsVersion")
kotlin_version = constants.getProperty("kotlinVersion")
junit_version = constants.getProperty("junitVersion")
quasar_version = constants.getProperty("quasarVersion")
log4j_version = constants.getProperty("log4jVersion")
slf4j_version = constants.getProperty("slf4jVersion")
corda_platform_version = constants.getProperty("platformVersion").toInteger()
//springboot
spring_boot_version = '2.0.2.RELEASE'
spring_boot_gradle_plugin_version = '2.0.2.RELEASE'

spotless_plugin_version = '3.23.1'
}


repositories {
mavenLocal()
mavenCentral()
jcenter()
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
maven { url 'https://software.r3.com/artifactory/corda' }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
maven { url "https://plugins.gradle.org/m2/" }
}

dependencies {
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
classpath "net.corda.plugins:cordapp:$corda_gradle_plugins_version"
classpath "net.corda.plugins:cordformation:$corda_gradle_plugins_version"
classpath "net.corda.plugins:quasar-utils:$corda_gradle_plugins_version"
classpath "com.diffplug.spotless:spotless-plugin-gradle:$spotless_plugin_version"
classpath "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
classpath "org.springframework.boot:spring-boot-gradle-plugin:$spring_boot_gradle_plugin_version"
}
}

plugins {
id 'com.cosminpolifronie.gradle.plantuml' version '1.6.0'
}

allprojects {
apply from: "${rootProject.projectDir}/repositories.gradle"
apply plugin: 'kotlin'
apply plugin: 'com.diffplug.gradle.spotless'

repositories {
mavenLocal()
jcenter()
mavenCentral()
maven { url 'https://ci-artifactory.corda.r3cev.com/artifactory/corda-releases' }
maven { url 'https://jitpack.io' }
maven { url 'https://software.r3.com/artifactory/corda' }
maven { url 'https://repo.gradle.org/gradle/libs-releases' }
}

tasks.withType(org.jetbrains.kotlin.gradle.tasks.KotlinCompile).all {
kotlinOptions {
languageVersion = "1.2"
apiVersion = "1.2"
jvmTarget = "1.8"
javaParameters = true // Useful for reflection.
}
}

jar {
// This makes the JAR's SHA-256 hash repeatable.
preserveFileTimestamps = false
reproducibleFileOrder = true
}

spotless {
kotlin {
ktlint()
}
}

// below you can specify any env vars, for instance the path to the prover lib
test {
// environment "LD_LIBRARY_PATH", "~/pepper_deps/lib/"
}
}

apply plugin: 'net.corda.plugins.cordapp'
apply plugin: 'net.corda.plugins.cordformation'
apply plugin: 'net.corda.plugins.quasar-utils'


plantUml {
render input: 'docs/**/*.puml', output: "docs/build", format: 'png', withMetadata: false
}

Loading

0 comments on commit 44e0e32

Please sign in to comment.