Skip to content

Commit 1a48b35

Browse files
committed
Ledger Submitter Abstractions to Integrate CCF submitter along with Sawtooth Submitter.
Signed-off-by: prakashngit <[email protected]> Microsfot CCF based transaction processor for PDO, in addition to HL Sawtooth based TP. Commit includes client pieces as well as C++ code for the CCF-based PDO-TP. The transaction processor was desgined for CCF release 0.7.1. CCF 0.7.1 is included as a submodule. Certain python modules from this submodule are used as part of the client construction. CF based PDO-TP includes support for proof of commit - meaining, registry reads from ledger will be signed by CCF service which can then be used to construct offline-verifiable proof of txn commits. Signed-off-by: prakashngit <[email protected]>
1 parent b781d14 commit 1a48b35

File tree

76 files changed

+3201
-641
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

76 files changed

+3201
-641
lines changed

.gitmodules

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
[submodule "interpreters/wasm-micro-runtime"]
22
path = interpreters/wasm-micro-runtime
33
url = https://github.com/bytecodealliance/wasm-micro-runtime.git
4+
[submodule "ccf_transaction_processor/CCF"]
5+
path = ccf_transaction_processor/CCF
6+
url = https://github.com/microsoft/CCF.git

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,13 @@ smart contracts policies are enforced through execution in a Trusted Execution
1313
Environment (TEE).
1414

1515
PDO uses a distributed ledger, in this case the
16-
[Hyperledger Sawtooth](httphttps://sawtooth.hyperledger.org/)
16+
[Hyperledger Sawtooth](https://sawtooth.hyperledger.org/)
1717
distributed ledger, to ensure that there is a single, authoritative
1818
instance of the object, and to provide a means of guaranteeing atomicity of
19-
updates across interacting objects. The long-term goal for PDO is to perform
20-
contract execution and storage off the blockchain, with only a hash of
21-
blockchain state stored on the distributed ledger
19+
updates across interacting objects. There is also ongoing efforts to support
20+
[Microsoft Confidential Consortium Framework (CCF)](https://microsoft.github.io/CCF/) based ledger.
21+
PDO performs contract execution and storage off the blockchain, with only a hash of
22+
blockchain state stored on the distributed ledger.
2223

2324
PDO provides benefits for both application developers seeking to define and
2425
implement privacy-preserving distributed ledgers, and for service providers

build/Makefile

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ ifndef SGX_MODE
2929
$(error Incomplete configuration, SGX_MODE is not defined)
3030
endif
3131

32+
ifndef PDO_LEDGER_TYPE
33+
$(error Incomplete configuration, PDO_LEDGER_TYPE is not defined)
34+
endif
35+
3236
SCRIPTDIR ?= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
3337
DSTDIR ?= $(PDO_INSTALL_ROOT)
3438
SRCDIR ?= $(abspath $(SCRIPTDIR)/..)
@@ -86,6 +90,11 @@ $(PYTHON_DIR) :
8690
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade cryptography
8791
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade pyparsing
8892
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade lmdb
93+
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade loguru
94+
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade requests_http_signature
95+
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade websocket-client
96+
. $(abspath $(DSTDIR)/bin/activate) ; pip install --upgrade msgpack
97+
8998

9099
$(DSTDIR) :
91100
@echo CREATE INSTALLATION DIRECTORY $(DSTDIR)
@@ -111,7 +120,13 @@ ${PDO_ENCLAVE_CODE_SIGN_PEM} :
111120
openssl genrsa -3 -out ${PDO_ENCLAVE_CODE_SIGN_PEM} 3072
112121

113122
service_indexes := 1 2 3 4 5
114-
ESERVICE_SKF := $(addprefix $(KEYDIR),$(foreach i,$(service_indexes),eservice$(i)_private.skf))
123+
124+
ifeq ($(PDO_LEDGER_TYPE),sawtooth)
125+
ESERVICE_KEYS := $(addprefix $(KEYDIR),$(foreach i,$(service_indexes),eservice$(i)_private.skf))
126+
else
127+
ESERVICE_KEYS := $(addprefix $(KEYDIR),$(foreach i,$(service_indexes),eservice$(i)_private.pem))
128+
endif
129+
115130
SSERVICE_PEM := $(addprefix $(KEYDIR),$(foreach i,$(service_indexes),sservice$(i)_private.pem))
116131
PSERVICE_PEM := $(addprefix $(KEYDIR),$(foreach i,$(service_indexes),pservice$(i)_private.pem))
117132

@@ -124,7 +139,7 @@ USER_PEM := $(addprefix $(KEYDIR),$(foreach i,$(user_indexes),user$(i)_private.p
124139
%.pem :
125140
. $(abspath $(DSTDIR)/bin/activate) ; $(KEYGEN) --keyfile $(subst _private,,$*) --format pem
126141

127-
keys : $(ESERVICE_SKF) $(SSERVICE_PEM) $(PSERVICE_PEM) $(USER_PEM)
142+
keys : $(ESERVICE_KEYS) $(SSERVICE_PEM) $(PSERVICE_PEM) $(USER_PEM)
128143

129144
ESERVICE_CONF := $(ETCDIR)/eservice1.toml
130145
SSERVICE_CONF := $(ETCDIR)/sservice1.toml
@@ -185,7 +200,7 @@ template : $(PYTHON_DIR)
185200
mkdir -p $(DSTDIR)/opt/pdo/data
186201
mkdir -p $(DSTDIR)/opt/pdo/etc
187202
mkdir -p $(DSTDIR)/opt/pdo/etc/keys/sgx
188-
mkdir -p $(DSTDIR)/opt/pdo/etc/keys/sawtooth
203+
mkdir -p $(DSTDIR)/opt/pdo/etc/keys/ledger
189204
mkdir -p $(DSTDIR)/opt/pdo/keys
190205
mkdir -p $(DSTDIR)/opt/pdo/logs
191206

build/__tools__/expand-config

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,22 @@ import pdo.common.config as pconfig
2929
try :
3030
ContractHome = os.environ["PDO_HOME"]
3131
LedgerURL = os.environ["PDO_LEDGER_URL"]
32+
LedgerType = os.environ["PDO_LEDGER_TYPE"]
3233
SPID = os.environ["PDO_SPID"]
3334
SPID_API_KEY = os.environ["PDO_SPID_API_KEY"]
3435
except KeyError as ke :
3536
print("incomplete configuration, missing definition of {0}".format(str(ke)))
3637
sys.exit(-1)
3738

39+
#deduce eservice key format based on ledger type
40+
if LedgerType == 'sawtooth':
41+
EserviceKeyFormat = 'skf'
42+
elif LedgerType == 'ccf':
43+
EserviceKeyFormat = 'pem'
44+
else:
45+
print("Cannot configure eservice keys. Invalid ledger type, Must be 'sawtooth' or 'ccf'" )
46+
sys.exit(-1)
47+
3848
ContractHost = os.environ.get("HOSTNAME", "localhost")
3949
ContractEtc = os.path.join(ContractHome, "etc")
4050
ContractKeys = os.path.join(ContractHome, "keys")
@@ -50,6 +60,8 @@ config_map = {
5060
'keys' : ContractKeys,
5161
'logs' : ContractLogs,
5262
'ledger' : LedgerURL,
63+
'ledger_type': LedgerType,
64+
'eservice_key_format': EserviceKeyFormat,
5365
'proxy' : HttpsProxy,
5466
'spid' : SPID,
5567
'spid_api_key' : SPID_API_KEY

build/__tools__/run-tests.sh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ function cleanup {
5454

5555
trap cleanup EXIT
5656

57+
5758
# -----------------------------------------------------------------
5859
yell run unit tests for python, common, contracts and eservice
5960
# -----------------------------------------------------------------

build/common-config.sh

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -75,11 +75,16 @@ var_set() {
7575

7676
env_val[PDO_LEDGER_URL]="${PDO_LEDGER_URL:-http://127.0.0.1:8008}"
7777
env_desc[PDO_LEDGER_URL]="
78-
PDO_PDO_LEDGER_URL is the URL is to submit transactions to the
79-
Sawtooth ledger.
78+
PDO_LEDGER_URL is the URL is to submit transactions to the ledger.
8079
"
8180
env_key_sort[$i]="PDO_LEDGER_URL"; i=$i+1; export PDO_LEDGER_URL=${env_val[PDO_LEDGER_URL]}
8281

82+
env_val[PDO_LEDGER_TYPE]="${PDO_LEDGER_TYPE:-sawtooth}"
83+
env_desc[PDO_LEDGER_TYPE]="
84+
PDO_LEDGER_TYPE is the ledger used by PDO. Choose either sawtooth or ccf
85+
"
86+
env_key_sort[$i]="PDO_LEDGER_TYPE"; i=$i+1; export PDO_LEDGER_TYPE=${env_val[PDO_LEDGER_TYPE]}
87+
8388
env_val[PDO_INSTALL_ROOT]="${PDO_INSTALL_ROOT:-${SCRIPTDIR}/_dev}"
8489
env_desc[PDO_INSTALL_ROOT]="
8590
PDO_INSTALL_ROOT is the root of the directory in which the virtual
@@ -130,19 +135,20 @@ var_set() {
130135
"
131136
env_key_sort[$i]="PDO_SPID_API_KEY"; i=$i+1; export PDO_SPID_API_KEY=${env_val[PDO_SPID_API_KEY]}
132137

133-
env_val[PDO_STL_KEY_ROOT]="${PDO_STL_KEY_ROOT:-${PDO_INSTALL_ROOT}/opt/pdo/etc/keys/sawtooth}"
134-
env_desc[PDO_STL_KEY_ROOT]="
135-
PDO_STL_KEY_ROOT is the root directory where the system keys are stored
136-
for Sawtooth integration; files in this directory
137-
are not automatically generated.
138+
env_val[PDO_LEDGER_KEY_ROOT]="${PDO_LEDGER_KEY_ROOT:-${PDO_INSTALL_ROOT}/opt/pdo/etc/keys/ledger}"
139+
env_desc[PDO_LEDGER_KEY_ROOT]="
140+
PDO_LEDGER_KEY_ROOT is the root directory where the system keys are stored
141+
for ledger integration; files in this directory are not automatically generated. When ccf is used
142+
as ledger, the ccf keys {networkcert.pem, userccf_cert.pem, userccf_privk.pem} must be
143+
placed under this folder. These keys get generated during ccf deployment.
138144
"
139-
env_key_sort[$i]="PDO_STL_KEY_ROOT"; i=$i+1; export PDO_STL_KEY_ROOT=${env_val[PDO_STL_KEY_ROOT]}
145+
env_key_sort[$i]="PDO_LEDGER_KEY_ROOT"; i=$i+1; export PDO_LEDGER_KEY_ROOT=${env_val[PDO_LEDGER_KEY_ROOT]}
140146

141-
env_val[PDO_LEDGER_KEY_SKF]="${PDO_LEDGER_KEY_SKF:-${PDO_STL_KEY_ROOT}/pdo_validator.priv}"
147+
env_val[PDO_LEDGER_KEY_SKF]="${PDO_LEDGER_KEY_SKF:-${PDO_LEDGER_KEY_ROOT}/pdo_validator.priv}"
142148
env_desc[PDO_LEDGER_KEY_SKF]="
143149
PDO_LEDGER_KEY_SKF is used to update settings in the Sawtooth validator.
144150
This is the key used by the Sawtooth ledger and is generally
145-
found in the file .sawtooth/keys/sawtooth.priv in the
151+
found in the file .sawtooth/keys/ledger.priv in the
146152
Sawtooth installation directory hiearchy.
147153
"
148154
env_key_sort[$i]="PDO_LEDGER_KEY_SKF"; i=$i+1; export PDO_LEDGER_KEY_SKF=${env_val[PDO_LEDGER_KEY_SKF]}
@@ -172,16 +178,17 @@ in the build, installation & execution process. While the build should
172178
progress with only the default values specified, commonly five variables
173179
are set and then this file is evaluated. These five variables are:
174180
WASM_SRC, TINY_SCHEME_SRC, PDO_LEDGER_URL, PDO_INSTALL_ROOT, and
175-
PDO_STL_KEY_ROOT. In case you run in SGX HW mode you usally will define
181+
PDO_LEDGER_KEY_ROOT. In case you run in SGX HW mode you usally will define
176182
PDO_SGX_KEY_ROOT. See further down information on these variables and
177183
others you could override from defaults.
178184
179185
The default usage of this script is to be sourced. For example,
180186
local configuration file may be constructed as:
181187
182-
export PDO_STL_KEY_ROOT=${HOME}/keys
188+
export PDO_LEDGER_KEY_ROOT=${HOME}/keys/ledger
183189
export PDO_INSTALL_ROOT=${HOME}/pdo-test-env
184190
export PDO_LEDGER_URL=http://127.0.0.1:8008
191+
export PDO_LEDGER_TYPE=sawtooth
185192
export TINY_SCHEME_SRC=${HOME}/tinyscheme-1.41
186193
export WASM_SRC=${HOME}/wasm
187194
@@ -216,7 +223,7 @@ do
216223
case $opt in
217224
--reset-keys|-r)
218225
# -----------------------------------------------------------------
219-
# if you change either PDO_SGX_KEY_ROOT or PDO_STL_KEY_ROOT variable
226+
# if you change either PDO_SGX_KEY_ROOT or PDO_LEDGER_KEY_ROOT variable
220227
# and re-source this file you should unset all of the variables that
221228
# depend on those variables
222229
# -----------------------------------------------------------------

build/opt/pdo/etc/template/eservice.toml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,12 @@ URL = "http://localhost:${{7200+_count_}}"
3232
BlockStore = "${data}/${{identity.replace('eservice','sservice')}}.mdb"
3333

3434
# --------------------------------------------------
35-
# Sawtooth -- sawtooth ledger configuration
35+
# Ledger -- ledger configuration
3636
# --------------------------------------------------
37-
[Sawtooth]
37+
[Ledger]
3838
# LedgerURL is used to submit the registration transaction should
3939
# the enclave require registration
40+
LedgerType = "${ledger_type}"
4041
LedgerURL = "${ledger}"
4142
Organization = "Widgets R Us"
4243

@@ -54,7 +55,7 @@ LogFile = "${logs}/${identity}.log"
5455
# Keys are used to sign the registration transaction
5556
# should it be required
5657
SearchPath = [ ".", "./keys", "${keys}" ]
57-
FileName = "${identity}_private.skf"
58+
FileName = "${identity}_private.${eservice_key_format}"
5859

5960
# --------------------------------------------------
6061
# EnclaveData -- configuration of sealed storage for the enclave

build/opt/pdo/etc/template/pcontract.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,14 @@
1919
Identity = "${identity}"
2020

2121
# --------------------------------------------------
22-
# Sawtooth -- sawtooth ledger configuration
22+
# Ledger -- ledger configuration
2323
# --------------------------------------------------
24-
[Sawtooth]
24+
[Ledger]
25+
# LedgerURL is used to submit the registration transaction should
26+
# the enclave require registration
27+
LedgerType = "${ledger_type}"
2528
LedgerURL = "${ledger}"
29+
Organization = "Widgets R Us"
2630

2731
# --------------------------------------------------
2832
# Service -- Information about enclave/provisioning services

build/opt/pdo/etc/template/pservice.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,14 @@ HttpPort = ${{7000+_count_}}
2121
Host = "localhost"
2222

2323
# --------------------------------------------------
24-
# Sawtooth -- sawtooth ledger configuration
24+
# Ledger -- ledger configuration
2525
# --------------------------------------------------
26-
[Sawtooth]
26+
[Ledger]
27+
# LedgerURL is used to submit the registration transaction should
28+
# the enclave require registration
29+
LedgerType = "${ledger_type}"
2730
LedgerURL = "${ledger}"
31+
Organization = "Widgets R Us"
2832

2933
# --------------------------------------------------
3034
# Logging -- configuration of service logging

ccf_transaction_processor/CCF

Submodule CCF added at 80476b2

ccf_transaction_processor/Readme.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<!---
2+
Licensed under Creative Commons Attribution 4.0 International License
3+
https://creativecommons.org/licenses/by/4.0/
4+
--->
5+
6+
## Microsoft CCF based PDO Transaction Processor
7+
8+
This folder contains software for PDO transaction processor (TP) based on Microsoft's CCF blockchain.
9+
The software is located under transaction_processor/. The folder CCF/ points to CCF tag 0.7.1 which is
10+
included as a submodule under the PDO repo. The TP software is written and tested for CCF tag 0.7.1.
11+
Compatability with other CCF versions is not guaranteed.
12+
13+
The TP must viewed as a CCF application. Documentation for building and deploying CCF applications
14+
can be found at https://microsoft.github.io/CCF/. The CCF legder that stores the PDO TP registries is
15+
encrypted, and is accessible only within CCF encalves. Currently PDO/CCF combination is supported
16+
only under the virtual enclave mode for both PDO and CCF. (set env variable SGX_MODE=SIM for PDO &
17+
set cmake flag TARGET=virtual for ccf). Support for HW mode for both PDO and CCF will be added soon.
18+
19+
CCF uses mutually authenticated TLS channels for transactions. Given that in PDO client authentication is implemented within the transaction processor itself, we do not utilize the client authentication feature provided by CCF. Once CCF is deployed, CCF's network certificate (networkcert.pem) and one set of user keys (userccf_cert.pem & userccf_privk.pem)
20+
must be made available to all PDO processes that want to submit a CCF transaction. In this case, every
21+
PDO process behaves as though it is a CCF user corresponding to the private key userccf_privk.pem.
22+
These keys must be stored under $PDO_LEDGER_KEY_ROOT as part of PDO deployment.
23+
24+
It may be noted that PDO also supports TP based on the Hyperledger Sawtooth blockchain.
25+
As far as PDO is concerned, CCF based TP is functionally identical to the Sawtooth based
26+
TP (except for one additional feature described below). A key difference beween the two ledgers
27+
is the fact that while the ledger in CCF is encrypted as noted above, the ledger is Sawtooth is stored in plain text.
28+
Even though the no part of conract state gets stored in the ledger in both CCF & Sawtooth, encrypting the
29+
ledger as in CCF helps to hide transaction patterns that are otherwise visible in Sawtooth ledger. Detailed documentation
30+
about Sawtooth based TP can be found at $PDO_SRC/sawtooth/docs. The schema for JSON payloads used to submit
31+
CCF transactions can be found at
32+
[${PDO_SRC}/python/pdo/submitter/ccf/docs/](../python/pdo/submitter/ccf/docs/ccf_payload_schema.json).
33+
For additional references to documentation about PDO, including transaction processor protocols,
34+
see [${PDO_SRC}/README.md](../README.md)
35+
36+
A feature of the CCF based TP that is not supported by Sawtooth based TP is the fact that
37+
responses to read-transactions include a payload signature, where the signature is generated by the CCF enclave
38+
serving the read request. The (signing key, verifying key) pair is created within the TP,
39+
and is globally persisted among all CCF enclaves. The verifying_key can be obtained from CCF using
40+
the "get_ledger_verifying_key" transaction. In fact, the very first invocation of "get_ledger_verifying_key" rpc
41+
after the service is started is used to create the key pair, which will then be globally committed.
42+
This feature may be used by PDO clients to establish offline verifiable proof of transaction commits as
43+
desired by the PDO smart contract application. Note that for trust purposes, it is recommended that
44+
any entity that uses the above verifying_key gets it directly from the CCF service using the
45+
"get_ledger_verifying_key" transaction.
46+

0 commit comments

Comments
 (0)