Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/build-and-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -431,7 +431,7 @@ jobs:

if [ "${{ matrix.config.unit_tests }}" = "true" ] || [ "${{ matrix.config.functional_tests }}" = "true" ]; then
echo ::group::Params
util/fetch-params.sh $PARAMS_DIR
./params/install-params.sh $PARAMS_DIR
echo ::endgroup::
fi

Expand Down
17 changes: 15 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ SUBDIRS = src
if ENABLE_MAN
SUBDIRS += doc/man
endif
SUBDIRS += params
.PHONY: deploy FORCE

export PYTHONPATH
Expand Down Expand Up @@ -53,7 +54,7 @@ DIST_CARGO = \
$(top_srcdir)/Cargo.lock \
$(top_srcdir)/Cargo.toml \
$(top_srcdir)/rust-toolchain \
$(top_srcdir)/util/fetch-params.sh
$(top_srcdir)/params/install-params.sh

BIN_CHECKS=$(top_srcdir)/contrib/devtools/symbol-check.py \
$(top_srcdir)/contrib/devtools/security-check.py
Expand All @@ -73,6 +74,9 @@ OSX_PACKAGING = $(OSX_DEPLOY_SCRIPT) $(OSX_FANCY_PLIST) $(OSX_INSTALLER_ICONS) \
$(top_srcdir)/contrib/macdeploy/detached-sig-apply.sh \
$(top_srcdir)/contrib/macdeploy/detached-sig-create.sh

SPEND_PARAMS = $(top_srcdir)/params/sapling-spend.params
OUTPUT_PARAMS = $(top_srcdir)/params/sapling-output.params

COVERAGE_INFO = baseline.info \
test_pivx_filtered.info total_coverage.info \
baseline_filtered.info functional_test.info functional_test_filtered.info \
Expand Down Expand Up @@ -114,9 +118,18 @@ $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings:
$(MKDIR_P) $(@D)
echo '{ CFBundleDisplayName = "$(PACKAGE_NAME)"; CFBundleName = "$(PACKAGE_NAME)"; }' > $@

$(OSX_APP)/Contents/Resources/sapling-spend.params: $(SPEND_PARAMS)
$(MKDIR_P) $(@D)
$(INSTALL_DATA) $< $@

$(OSX_APP)/Contents/Resources/sapling-output.params: $(OUTPUT_PARAMS)
$(MKDIR_P) $(@D)
$(INSTALL_DATA) $< $@

OSX_APP_BUILT=$(OSX_APP)/Contents/PkgInfo $(OSX_APP)/Contents/Resources/empty.lproj \
$(OSX_APP)/Contents/Resources/bitcoin.icns $(OSX_APP)/Contents/Info.plist \
$(OSX_APP)/Contents/MacOS/PIVX-Qt $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings
$(OSX_APP)/Contents/MacOS/PIVX-Qt $(OSX_APP)/Contents/Resources/Base.lproj/InfoPlist.strings \
$(OSX_APP)/Contents/Resources/sapling-spend.params $(OSX_APP)/Contents/Resources/sapling-output.params

osx_volname:
echo $(OSX_VOLNAME) >$@
Expand Down
10 changes: 7 additions & 3 deletions build-aux/snap/snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -175,9 +175,9 @@ parts:
fi
./autogen.sh
if [ $DEPENDS = 1 ]; then
./configure --prefix=`pwd`/depends/${HOST} --with-params-dir=${SNAP_USER_COMMON}/${PARAMSDIR}
./configure --prefix=`pwd`/depends/${HOST}
else
./configure --with-incompatible-bdb --with-params-dir=${SNAP_USER_COMMON}/${PARAMSDIR}
./configure --with-incompatible-bdb
fi
echo "-----------------------------------------------"
echo "+++++++++++++++++++++++++++++++++++++++++++++++"
Expand Down Expand Up @@ -231,19 +231,20 @@ parts:
echo "CONFIG FILE" # create .pivx folder and copy example config - !!!warning!!!: do not copy as pivx.conf
echo "+++++++++++++++++++++++++++++++++++++++++++++++"
mkdir -p ${SNAP_USER_COMMON}/.${DATADIR}
mkdir -p ${SNAP_USER_COMMON}/${PARAMSDIR}
if [ $COPYCONF = 1 ]; then
cp ${SNAPCRAFT_PART_BUILD}/contrib/debian/manpages/${CONF}.conf.5 ${SNAP_USER_COMMON}/.${DATADIR}/${CONF}-example.conf
else
echo "COPY CONFIG FILE disabled, skipping"
fi
cp ${SNAPCRAFT_PART_BUILD}/params/*.params ${SNAP_USER_COMMON}/${PARAMSDIR}/
echo "-----------------------------------------------"
echo "+++++++++++++++++++++++++++++++++++++++++++++++"
echo "RUN TESTS" # if tests fail to pass, build and release will fail
echo "+++++++++++++++++++++++++++++++++++++++++++++++"
cd ${SNAPCRAFT_PART_BUILD}
if [ ! $SNAPCRAFT_ARCH_TRIPLET = "s390x-linux-gnu" ]; then
if [ $RUNTESTS = 1 ]; then
${SNAPCRAFT_PROJECT_DIR}/util/fetch-params.sh ${SNAP_USER_COMMON}/${PARAMSDIR}
make check
else
echo "RUN TESTS disabled, skipping"
Expand Down Expand Up @@ -300,6 +301,7 @@ parts:
- libdb++-dev
stage-packages:
- libxkbcommon0
- libxcb-xinerama0
- ttf-ubuntu-font-family
- dmz-cursor-theme
- light-themes
Expand All @@ -324,6 +326,8 @@ parts:
- libpgm-5.2-0
- libprotobuf10
- libqrencode3
- libqt5core5a
- libqt5dbus5
- libqt5charts5
- libqt5test5
- libsodium23
Expand Down
3 changes: 2 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,7 @@ case $host in
fi

AX_CHECK_LINK_FLAG([[-Wl,-headerpad_max_install_names]], [LDFLAGS="$LDFLAGS -Wl,-headerpad_max_install_names"])
AX_CHECK_LINK_FLAG([[-framework CoreFoundation]], [LDFLAGS="$LDFLAGS -framework CoreFoundation"], [AC_MSG_ERROR([could not find CoreFoundation framework])])
CPPFLAGS="$CPPFLAGS -DMAC_OSX -DOBJC_OLD_DISPATCH_PROTOTYPES=0"
OBJCXXFLAGS="$CXXFLAGS"
;;
Expand Down Expand Up @@ -1485,7 +1486,7 @@ AC_SUBST(HAVE_BUILTIN_PREFETCH)
AC_SUBST(HAVE_MM_PREFETCH)
AC_SUBST(HAVE_STRONG_GETAUXVAL)
AC_SUBST(HAVE_WEAK_GETAUXVAL)
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
AC_CONFIG_FILES([Makefile src/Makefile doc/man/Makefile params/Makefile share/setup.nsi share/qt/Info.plist test/config.ini])
AC_CONFIG_FILES([contrib/devtools/split-debug.sh],[chmod +x contrib/devtools/split-debug.sh])
AM_COND_IF([HAVE_DOXYGEN], [AC_CONFIG_FILES([doc/Doxyfile])])
AC_CONFIG_LINKS([contrib/filter-lcov.py:contrib/filter-lcov.py])
Expand Down
1 change: 1 addition & 0 deletions contrib/gitian-descriptors/gitian-linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,7 @@ script: |
find ${DISTNAME}/bin -type f -executable -print0 | xargs -0 -n1 -I{} ../contrib/devtools/split-debug.sh {} {} {}.dbg
#find ${DISTNAME}/lib -type f -print0 | xargs -0 -n1 -I{} ../contrib/devtools/split-debug.sh {} {} {}.dbg
cp ../doc/README.md ${DISTNAME}/
cp ../params/install-params.sh ${DISTNAME}/
find ${DISTNAME} -not -name "*.dbg" | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz
find ${DISTNAME} -name "*.dbg" | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}-debug.tar.gz
cd ../../
Expand Down
1 change: 1 addition & 0 deletions contrib/gitian-descriptors/gitian-osx.yml
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,7 @@ script: |
find . -name "lib*.la" -delete
find . -name "lib*.a" -delete
rm -rf ${DISTNAME}/lib/pkgconfig
cp ../params/install-params.sh ${DISTNAME}/
find ${DISTNAME} | sort | tar --no-recursion --mode='u+rw,go+r-w,a+X' --owner=0 --group=0 -c -T - | gzip -9n > ${OUTDIR}/${DISTNAME}-${i}.tar.gz
cd ../../
done
Expand Down
2 changes: 2 additions & 0 deletions doc/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ Unpack the files into a directory and run:
- `bin/pivx-qt` (GUI) or
- `bin/pivxd` (headless)

If this is the first time running PIVX Core (since v5.0.0), you'll need to install the sapling params by running the included `install-params.sh` script, which copies the two params files to `$HOME/.pivx-params`

### Windows

Unpack the files into a directory, and then run pivx-qt.exe.
Expand Down
3 changes: 3 additions & 0 deletions params/Makefile.am
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dist_data_DATA =

dist_data_DATA+=sapling-output.params sapling-spend.params
141 changes: 141 additions & 0 deletions params/install-params.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
#!/usr/bin/env bash
#
# Copyright (c) 2015-2020 The Zcash developers
# Copyright (c) 2020 The PIVX developers
# Distributed under the MIT software license, see the accompanying
# file COPYING or http://www.opensource.org/licenses/mit-license.php.

export LC_ALL=C.UTF-8

set -eu

if [ -n "${1:-}" ]; then
PARAMS_DIR="$1"
else
if [[ "$OSTYPE" == "darwin"* ]]; then
PARAMS_DIR="$HOME/Library/Application Support/PIVXParams"
else
PARAMS_DIR="$HOME/.pivx-params"
fi
fi

SAPLING_SPEND_NAME='sapling-spend.params'
SAPLING_OUTPUT_NAME='sapling-output.params'

SHA256CMD="$(command -v sha256sum || echo shasum)"
SHA256ARGS="$(command -v sha256sum >/dev/null || echo '-a 256')"

pushd () {
command pushd "$@" > /dev/null
}

popd () {
command popd > /dev/null
}

function install_params {
local filename="$1"
local output="$2"
local expectedhash="$3"

# if the params don't exist in the current directory, assume we're running from release tarballs
if ! [ -f "$filename" ]
then
filename="share/$filename"
fi

if ! [ -f "$output" ]
then
"$SHA256CMD" $SHA256ARGS -c <<EOF
$expectedhash $filename
EOF

# Check the exit code of the shasum command:
CHECKSUM_RESULT=$?
if [ $CHECKSUM_RESULT -eq 0 ]; then
cp -v "$filename" "$output"
else
echo "Failed to verify parameter checksums!" >&2
exit 1
fi
fi
}

# Use flock to prevent parallel execution.
function lock() {
local lockfile=/tmp/install_params.lock
if [[ "$OSTYPE" == "darwin"* ]]; then
if shlock -f ${lockfile} -p $$; then
return 0
else
return 1
fi
else
# create lock file
eval "exec 200>$lockfile"
# acquire the lock
flock -n 200 \
&& return 0 \
|| return 1
fi
}

function exit_locked_error {
echo "Only one instance of install-params.sh can be run at a time." >&2
exit 1
}

function main() {

lock install-params.sh \
|| exit_locked_error

cat <<EOF
PIVX - install-params.sh

This script will install the PIVX zkSNARK parameters and verify their
integrity with sha256sum.

If they already exist locally, it will exit now and do nothing else.
EOF

# Now create PARAMS_DIR and insert a README if necessary:
if ! [ -d "$PARAMS_DIR" ]
then
mkdir -p "$PARAMS_DIR"
README_PATH="$PARAMS_DIR/README"
cat >> "$README_PATH" <<EOF
This directory stores common PIVX zkSNARK parameters. Note that it is
distinct from the daemon's -datadir argument because the parameters are
large and may be shared across multiple distinct -datadir's such as when
setting up test networks.
EOF

# This may be the first time the user's run this script, so give
# them some info:
cat <<EOF
If the files are already present and have the correct
sha256sum, nothing else is done.

Creating params directory. For details about this directory, see:
$README_PATH

EOF
fi

if [ -d ".git" ] || [ -f autogen.sh ]
then
echo "Installing from source repo or dist tarball"
pushd params
fi

# Sapling parameters:
install_params "$SAPLING_SPEND_NAME" "$PARAMS_DIR/$SAPLING_SPEND_NAME" "8e48ffd23abb3a5fd9c5589204f32d9c31285a04b78096ba40a79b75677efc13"
install_params "$SAPLING_OUTPUT_NAME" "$PARAMS_DIR/$SAPLING_OUTPUT_NAME" "2f0ebbcbb9bb0bcffe95a397e7eba89c29eb4dde6191c339db88570e3f3fb0e4"

popd
}

main
rm -f /tmp/install_params.lock
exit 0
Binary file added params/sapling-output.params
Binary file not shown.
Binary file added params/sapling-spend.params
Binary file not shown.
3 changes: 3 additions & 0 deletions share/setup.nsi.in
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,9 @@ Section -Main SEC0000
File @abs_top_srcdir@/release/@BITCOIN_CLI_NAME@@EXEEXT@
SetOutPath $INSTDIR\doc
File /r @abs_top_srcdir@/doc\*.*
SetOutPath $APPDATA\PIVXParams
File @abs_top_srcdir@/params/sapling-output.params
File @abs_top_srcdir@/params/sapling-spend.params
SetOutPath $INSTDIR
WriteRegStr HKCU "${REGKEY}\Components" Main 1
SectionEnd
Expand Down
42 changes: 38 additions & 4 deletions src/util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@
#include <sys/prctl.h>
#endif

#ifdef MAC_OSX
#include <CoreFoundation/CoreFoundation.h>
#endif

#include <boost/program_options/detail/config_file.hpp>
#include <boost/program_options/parsers.hpp>
#include <openssl/conf.h>
Expand Down Expand Up @@ -441,11 +445,41 @@ void initZKSNARKS()
fs::path sapling_spend = path / "sapling-spend.params";
fs::path sapling_output = path / "sapling-output.params";

if (!(fs::exists(sapling_spend) &&
fs::exists(sapling_output)
)) {
throw std::runtime_error("Sapling params don't exist");
bool fParamsFound = false;
if (fs::exists(sapling_spend) && fs::exists(sapling_output)) {
fParamsFound = true;
} else {
#ifdef MAC_OSX
// macOS fallback path for params located within the app bundle
// This is a somewhat convoluted series of CoreFoundation calls
// that will result in the full path to the app bundle's "Resources"
// directory, which will contain the sapling params.
LogPrintf("Attempting to find params in app bundle...\n");
CFBundleRef mainBundle = CFBundleGetMainBundle();
CFURLRef bundleURL = CFBundleCopyBundleURL(mainBundle);

CFStringRef strBundlePath = CFURLCopyFileSystemPath(bundleURL, kCFURLPOSIXPathStyle);
const char* pathBundle = CFStringGetCStringPtr(strBundlePath, CFStringGetSystemEncoding());

fs::path bundle_path = fs::path(pathBundle);
LogPrintf("App bundle Resources path: %s\n", bundle_path);
sapling_spend = bundle_path / "Contents/Resources/sapling-spend.params";
sapling_output = bundle_path / "Contents/Resources/sapling-output.params";

// Release the CF objects
CFRelease(strBundlePath);
CFRelease(bundleURL);
CFRelease(mainBundle);
#else
// Linux fallback path for debuild/ppa based installs
sapling_spend = "/usr/local/share/sapling-spend.params";
sapling_output = "/usr/local/share/sapling-output.params";
#endif
if (fs::exists(sapling_spend) && fs::exists(sapling_output))
fParamsFound = true;
}
if (!fParamsFound)
throw std::runtime_error("Sapling params don't exist");

static_assert(
sizeof(fs::path::value_type) == sizeof(codeunit),
Expand Down