Skip to content

Commit

Permalink
Use the tinyscheme source to build the gipsy development interpreter. (
Browse files Browse the repository at this point in the history
…hyperledger-labs#189)

We have required three separate tinyscheme packages, one for gipsy
inside the enclave, one source install to build pcontract.so and
one for contract development outside the enclave. This update uses
the source install to build a scheme package that can be used for
development out of the enclave. A script (gipsyscheme) invokes the
scheme interpreter with the appropriate parameters & load files to
mimic (as closely as possible) the environment inside an enclave.

Signed-off-by: Mic Bowman <[email protected]>
  • Loading branch information
cmickeyb authored and prakashngit committed May 1, 2019
1 parent c3c6c5b commit aa83e40
Show file tree
Hide file tree
Showing 13 changed files with 380 additions and 51 deletions.
35 changes: 34 additions & 1 deletion LICENSE
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,40 @@ separate copyright notices and license terms. Your use of the source code for
the these components is subject to the terms and conditions of the following
licenses.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
tinyscheme

Copyright (c) 2000, Dimitrios Souflis
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are
met:

Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

Redistributions in binary form must reproduce the above copyright
notice, this list of conditions and the following disclaimer in the
documentation and/or other materials provided with the distribution.

Neither the name of Dimitrios Souflis nor the names of the
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
parson
Expand Down Expand Up @@ -312,4 +346,3 @@ operation of ;this software will be error-free, and I am under no obligation to
conjunction with products arising from the use of this ;material, there shall be
no use of my name in any advertising, ;promotional, or sales literature without
prior written consent in ;each case.

3 changes: 3 additions & 0 deletions build/__tools__/clean.sh
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ SRCDIR="$(realpath ${SCRIPTDIR}/../..)"
cd $SRCDIR/common/crypto/verify_ias_report
rm -f ias-certificates.cpp

cd $SRCDIR/common/interpreter/gipsy_scheme/packages
rm -f package.h package.scm

cd $SRCDIR/common
rm -rf build

Expand Down
2 changes: 1 addition & 1 deletion build/__tools__/verify.sh
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ try command -v cmake
try command -v swig
try command -v make
try command -v g++
try command -v tinyscheme
try command -v ${TINY_SCHEME_SRC}/scheme

if [ ! -d "${PDO_INSTALL_ROOT}" ]; then
warn "PDO_INSTALL_ROOT directory does not exist"
Expand Down
46 changes: 42 additions & 4 deletions common/interpreter/gipsy_scheme/packages/build-init-package.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,45 @@

F_PACKAGE_NAME='_init_package'

# -----------------------------------------------------------------
# -----------------------------------------------------------------
cred=`tput setaf 1`
cgrn=`tput setaf 2`
cblu=`tput setaf 4`
cmag=`tput setaf 5`
cwht=`tput setaf 7`
cbld=`tput bold`
bred=`tput setab 1`
bgrn=`tput setab 2`
bblu=`tput setab 4`
bwht=`tput setab 7`
crst=`tput sgr0`

function recho () {
echo "${cbld}${cred}" $@ "${crst}" >&2
}

function becho () {
echo "${cbld}${cblu}" $@ "${crst}" >&2
}

function say () {
echo "$(basename $0): $*" >&2;
}

function yell () {
becho "$(basename $0): $*" >&2;
}

function die() {
recho "$(basename $0): $*" >&2
exit 111
}

try() {
"$@" || die "test failed: $*"
}

# -----------------------------------------------------------------
# Process command line arguments
# -----------------------------------------------------------------
Expand All @@ -33,7 +72,7 @@ while true ; do
case "$1" in
-p|--package) F_PACKAGE_NAME="$2" ; shift 2 ;;
--) shift ; break ;;
*) echo "Internal error!" ; exit 1 ;;
*) die "Internal error!" ;;
esac
done

Expand All @@ -55,6 +94,5 @@ function cleanup {

trap cleanup EXIT


tinyscheme -1 $SCRIPTFILE $@ > ${F_PACKAGE_NAME}.scm
xxd -i ${F_PACKAGE_NAME}.scm ${F_PACKAGE_NAME}.h
TINYSCHEMEINIT=${TINY_SCHEME_SRC}/init.scm try ${TINY_SCHEME_SRC}/scheme -1 $SCRIPTFILE $@ > ${F_PACKAGE_NAME}.scm
try xxd -i ${F_PACKAGE_NAME}.scm ${F_PACKAGE_NAME}.h
6 changes: 0 additions & 6 deletions common/interpreter/gipsy_scheme/packages/init-package.scm
Original file line number Diff line number Diff line change
Expand Up @@ -451,12 +451,6 @@

(define (acons x y z) (cons (cons x y) z))

;;;; Handy for imperative programs
;;;; Used as: (define-with-return (foo x y) .... (return z) ...)
(macro (define-with-return form)
`(define ,(cadr form)
(call/cc (lambda (return) ,@(cddr form)))))

;;;;; Definition of MAKE-ENVIRONMENT, to be used with two-argument EVAL

(macro (make-environment form)
Expand Down
8 changes: 4 additions & 4 deletions contracts/auction/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PDO_HOME ?= /opt/pdo

SRCDIR?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
ROOTDIR := $(abspath $(SRCDIR)/../..)
EXTENSIONPATH := $(ROOTDIR)/common/build
GIPSY_SCHEME := $(ROOTDIR)/contracts/bin/gipsyscheme
INSTALLDIR = $(PDO_HOME)/contracts

CONTRACTS := _integer-key-auction.scm
Expand All @@ -32,13 +32,13 @@ test : $(TESTS)
@echo No automated tests defined

_integer-key-auction.scm : integer-key-auction.bld integer-key-auction.scm
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 integer-key-auction.bld
$(GIPSY_SCHEME) -1 integer-key-auction.bld

_debug_integer-key-auction.scm : integer-key-auction.bld integer-key-auction.scm auction-test.scm
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 integer-key-auction.bld debug test-auction
$(GIPSY_SCHEME) -1 integer-key-auction.bld debug test-auction

_aptest.scm : aptest.bld auction-protocol-test.scm ../integer-key/integer-key.scm integer-key-auction.scm
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 aptest.bld debug aptest
$(GIPSY_SCHEME) -1 aptest.bld debug aptest

install : $(CONTRACTS)
@echo copy $(CONTRACTS) to $(INSTALLDIR)
Expand Down
80 changes: 80 additions & 0 deletions contracts/bin/gipsyscheme
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
#!/bin/bash

# Copyright 2018 Intel Corporation
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

# This script performs several tests on the environment to ensure
# that it is set up correctly. It should be run prior to building

# -----------------------------------------------------------------
# -----------------------------------------------------------------
cred=`tput setaf 1`
cgrn=`tput setaf 2`
cblu=`tput setaf 4`
cmag=`tput setaf 5`
cwht=`tput setaf 7`
cbld=`tput bold`
bred=`tput setab 1`
bgrn=`tput setab 2`
bblu=`tput setab 4`
bwht=`tput setab 7`
crst=`tput sgr0`

function recho () {
echo "${cbld}${cred}" $@ "${crst}" >&2
}

function becho () {
echo "${cbld}${cblu}" $@ "${crst}" >&2
}

function say () {
echo "$(basename $0): $*" >&2;
}

function yell () {
becho "$(basename $0): $*" >&2;
}

function die() {
recho "$(basename $0): $*" >&2
exit 111
}

: "${TINY_SCHEME_SRC:-$(die Missing environment variable TINY_SCHEME_SRC)}"

INIT_FILE=$(mktemp /tmp/pdo-init.XXXXXXXXX)
function cleanup {
rm -f ${INIT_FILE}
}

trap cleanup EXIT

SCRIPT_DIR="$(dirname $(readlink --canonicalize ${BASH_SOURCE}))"
PDO_SOURCE_ROOT="$(realpath ${SCRIPT_DIR}/../..)"

EXTENSION_PATH=${PDO_SOURCE_ROOT}/common/build
if [ ! -f ${EXTENSION_PATH}/pcontract.so ]; then
die unable to locate pcontract.so, please build first
fi

GIPSY_INIT_FILE=${PDO_SOURCE_ROOT}/contracts/packages/init.scm
if [ ! -f ${GIPSY_INIT_FILE} ]; then
die unable to locate gipsy init file
fi

GIPSY_PACKAGE_DIR=${PDO_SOURCE_ROOT}/common/interpreter/gipsy_scheme/packages/
sed "s@PACKAGE_DIRECTORY@${GIPSY_PACKAGE_DIR}@" ${GIPSY_INIT_FILE} > ${INIT_FILE}

LD_LIBRARY_PATH=${EXTENSION_PATH} TINYSCHEMEINIT=${INIT_FILE} ${TINY_SCHEME_SRC}/scheme $@
24 changes: 12 additions & 12 deletions contracts/exchange/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PDO_HOME ?= /opt/pdo

SRCDIR?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
ROOTDIR := $(abspath $(SRCDIR)/../..)
EXTENSIONPATH := $(ROOTDIR)/common/build
GIPSY_SCHEME := $(ROOTDIR)/contracts/bin/gipsyscheme
INSTALLDIR = $(PDO_HOME)/contracts

CONTRACT_SRC := auction.scm asset_type.scm exchange.scm issuer.scm vetting_organization.scm
Expand All @@ -43,34 +43,34 @@ debug :

test : $(TEST_CONTRACTS)
@echo Run exchange contract tests
@LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 _issuer_test.scm loglevel 2
@LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 _exchange_test.scm loglevel 2
@LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 _auction_test.scm loglevel 2
@$(GIPSY_SCHEME) -1 _issuer_test.scm loglevel 2
@$(GIPSY_SCHEME) -1 _exchange_test.scm loglevel 2
@$(GIPSY_SCHEME) -1 _auction_test.scm loglevel 2
@rm -f exchange-test.mdb exchange-test.mdb-lock

_auction_test.scm : tests/auction_test.bld tests/auction_test.scm $(CONTRACT_SRC) $(PACKAGE_SRC) $(TEST_PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 tests/auction_test.bld debug
$(GIPSY_SCHEME) -1 tests/auction_test.bld debug

_exchange_test.scm : tests/exchange_test.bld tests/exchange_test.scm $(CONTRACT_SRC) $(PACKAGE_SRC) $(TEST_PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 tests/exchange_test.bld debug
$(GIPSY_SCHEME) -1 tests/exchange_test.bld debug

_issuer_test.scm : tests/issuer_test.bld tests/issuer_test.scm $(CONTRACT_SRC) $(PACKAGE_SRC) $(TEST_PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 tests/issuer_test.bld debug
$(GIPSY_SCHEME) -1 tests/issuer_test.bld debug

_asset_type.scm : asset_type.bld asset_type.scm $(PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 asset_type.bld
$(GIPSY_SCHEME) -1 asset_type.bld

_auction.scm : auction.bld auction.scm $(PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 auction.bld
$(GIPSY_SCHEME) -1 auction.bld

_exchange.scm : exchange.bld exchange.scm $(PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 exchange.bld
$(GIPSY_SCHEME) -1 exchange.bld

_issuer.scm : issuer.bld issuer.scm $(PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 issuer.bld
$(GIPSY_SCHEME) -1 issuer.bld

_vetting_organization.scm : vetting_organization.bld vetting_organization.scm $(PACKAGE_SRC)
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 vetting_organization.bld
$(GIPSY_SCHEME) -1 vetting_organization.bld

install : $(CONTRACTS) $(PLUGINS)
@echo copy $(CONTRACTS) to $(INSTALLDIR)
Expand Down
6 changes: 3 additions & 3 deletions contracts/integer-key/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ PDO_HOME ?= /opt/pdo

SRCDIR?=$(dir $(abspath $(lastword $(MAKEFILE_LIST))))
ROOTDIR := $(abspath $(SRCDIR)/../..)
EXTENSIONPATH := $(ROOTDIR)/common/build
GIPSY_SCHEME := $(ROOTDIR)/contracts/bin/gipsyscheme
INSTALLDIR = $(PDO_HOME)/contracts

CONTRACTS := _integer-key.scm
Expand All @@ -31,10 +31,10 @@ test :
@echo No automated tests defined

_integer-key.scm : integer-key.bld integer-key.scm
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 integer-key.bld
$(GIPSY_SCHEME) -1 integer-key.bld

_debug_integer-key.scm : integer-key.bld integer-key.scm integer-key-test.scm
LD_LIBRARY_PATH=$(EXTENSIONPATH) tinyscheme -1 integer-key.bld debug test-integer-key
$(GIPSY_SCHEME) -1 integer-key.bld debug test-integer-key

install : $(CONTRACTS)
@echo copy $(CONTRACTS) to $(INSTALLDIR)
Expand Down
9 changes: 0 additions & 9 deletions contracts/packages/debug.scm
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,6 @@
;; See the License for the specific language governing permissions and
;; limitations under the License.

;; scheme code to incorporate Gipsy interpreter setup in a tinyscheme
;; interpreter that runs outside the enclave

(load-extension "pcontract")

(require "init-package.scm")
(require "catch-package.scm")
(require "oops-package.scm")

;; -----------------------------------------------------------------
;; NAME: catch-success
;;
Expand Down
Loading

0 comments on commit aa83e40

Please sign in to comment.