Skip to content

Commit

Permalink
Blsct arith classes with tests (#54)
Browse files Browse the repository at this point in the history
* Added the new classes Scalar and G1Point

* Added scalar.{h,cpp} and g1point.{h,cpp} to make file

* Implemented more of the operators

* Implemented more functions

* Added new << >> logic for bitwise ops

* implemented Scalar::{Rand,GetString,Hash}

* Updated the arith scalar logic

* Added more G1Point arith logic, math...

* Added hashMapTo

* Removed Scalar::hashAndMap

* Updates that I forgot to push

* Updated G1Point::Rand()

* Update the mulVec func in G1Point to throw and exception if gVec and sVec size don't match

* Removed the test code that was accidentally added

* Implemented mulVec

* Removed some unused header calls

* Added return statement for G1Point::Double

* add g1point/scalar and their tests

* ignore .vscode

* add endianness parameter to G1Point::MapToG1. add g1point_hash_and_map test

* add mulvec_mcl test

* add mulvec tests

* add scalars and g1points classes

* add MapToG1(string&)

* extracted common parts of Scalars and G1Points to Elements. add slicing functions to Elements

* wip

* wip

* drop G1point::operator^

* drop the 2nd type artument from Elements

* add skeleton elements tests

* add elements tests

* support non-zero rand generatation

* wip

* add Elements::FirstNPowers

* add .gitignore to exclude dynamically generated files on macos. add Elements::RandomVector

* wip

* add Scalar::Pow and Scalar::GetBits

* add range proof test (not tested)

* add type parameter where required

* calculate t1, t2 properly

* fix typo

* add Elements::RepeatN test

* add comment

* add integration_tests and move such tests there

* introduce std::is_same in elements.h

* add gg^z == gg^(ones * z)

* wip

* add working h^mu gg^l test

* add Scalars::FirstNInvPow

* add multiply inv power seq for G1Points

* wip

* wip

* drop FirstNInvPow. add working 65_g_part_ts_only test

* wip

* add working range proof test

* wip

* make the range proof procedure a function

* integrate inner product argument to range proof

* wip

* wip

* wip

* wip

* drop unused variable

* separate elements implementation to cpp

* clean up code

* wip

* wip

* ignore .vscode

add endianness parameter to G1Point::MapToG1. add g1point_hash_and_map test

add mulvec_mcl test

add mulvec tests

add scalars and g1points classes

add MapToG1(string&)

extracted common parts of Scalars and G1Points to Elements. add slicing functions to Elements

wip

wip

drop G1point::operator^

drop the 2nd type artument from Elements

add skeleton elements tests

add elements tests

support non-zero rand generatation

wip

add Elements::FirstNPowers

add .gitignore to exclude dynamically generated files on macos. add Elements::RandomVector

wip

add Scalar::Pow and Scalar::GetBits

add range proof test (not tested)

add type parameter where required

calculate t1, t2 properly

fix typo

add Elements::RepeatN test

add comment

add integration_tests and move such tests there

introduce std::is_same in elements.h

add gg^z == gg^(ones * z)

wip

add working h^mu gg^l test

add Scalars::FirstNInvPow

add multiply inv power seq for G1Points

wip

wip

drop FirstNInvPow. add working 65_g_part_ts_only test

wip

add working range proof test

wip

make the range proof procedure a function

integrate inner product argument to range proof

wip

drop unused variable

wip

wip

wip

separate elements implementation to cpp

clean up code

wip

wip

* squashed commits

* fix typo

* migrate indirect MulVec to Elements

* fix build issues in clang

* fix spelling errors

* add newly introduced boost depdendency to lint-includes.py

* remove local depdendent functions

* wip

* remove trailing spaces

* Added BLS and MCL libs/includes to kernel build

* Updated copy constructor and assignment operators

* Added clean steps to clean-local for mcl and bls libs

* FORCE mcl and bls libs to build using main project CC and CXX values

* replace test_integration_invert_zero by additional test case of Scalars::FirstNPow

* use fixture test suite to provide name for bls/arith tests

* throw exception when Scalar(0) is inverted

* include bls/arith headers in setup_common.h

* add g1point and mcl_initializer dependency to test_util source

* fix test_util.include

* add blsct/arith/scalar depedency to libtest_util

* Disabled LLVM use in MCL compilation, this disabled ASM

* Added NM to android host configs for depends builds

* Added ABI=32 for i386 builds of GMP in depends

* fix undefined sanitizer error

Co-authored-by: mxaddict <[email protected]>
  • Loading branch information
gogoex and mxaddict authored Aug 25, 2022
1 parent 30f4f83 commit 575880a
Show file tree
Hide file tree
Showing 24 changed files with 3,259 additions and 7,959 deletions.
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -150,3 +150,9 @@ dist/
/guix-build-*

/ci/scratch/

# ide related
.vscode

# others
null.d
2 changes: 2 additions & 0 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,8 @@ clean-local: clean-docs
rm -rf coverage_percent.txt test_bitcoin.coverage/ total.coverage/ fuzz.coverage/ test/tmp/ cache/ $(OSX_APP)
rm -rf test/functional/__pycache__ test/functional/test_framework/__pycache__ test/cache share/rpcauth/__pycache__
rm -rf osx_volname dist/
make clean -C src/bls
make clean -C src/bls/mcl

test-security-check:
if TARGET_DARWIN
Expand Down
2 changes: 2 additions & 0 deletions depends/hosts/android.mk
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
ifeq ($(HOST),armv7a-linux-android)
android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-clang++
android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-clang
android_NM=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)eabi$(ANDROID_API_LEVEL)-nm
else
android_CXX=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang++
android_CC=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-clang
android_NM=$(ANDROID_TOOLCHAIN_BIN)/$(HOST)$(ANDROID_API_LEVEL)-nm
endif

android_CFLAGS=-std=$(C_STANDARD)
Expand Down
1 change: 1 addition & 0 deletions depends/packages/gmp.mk
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ $(package)_sha256_hash=eae9326beb4158c386e39a356818031bd28f3124cf915f8c5b1dc4c7a

define $(package)_set_vars
$(package)_config_opts+=--enable-cxx --enable-fat --with-pic --disable-shared
$(package)_config_opts_i686_linux+=ABI=32
$(package)_cflags_armv7l_linux+=-march=armv7-a
endef

Expand Down
25 changes: 20 additions & 5 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ noinst_PROGRAMS =
TESTS =
BENCHMARKS =

BITCOIN_INCLUDES=-I$(builddir) -I$(srcdir)/$(MINISKETCH_INCLUDE_DIR_INT) -I$(srcdir)/secp256k1/include -I$(srcdir)/bls/include -I$(srcdir)/bls/mcl/include -I$(srcdir)/bls/mcl/src -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS)
BLS_INCLUDES=-I$(srcdir)/bls/include -I$(srcdir)/bls/mcl/include -I$(srcdir)/bls/mcl/src

BITCOIN_INCLUDES=-I$(builddir) -I$(srcdir)/$(MINISKETCH_INCLUDE_DIR_INT) -I$(srcdir)/secp256k1/include $(BLS_INCLUDES) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT) $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS)

LIBBITCOIN_NODE=libbitcoin_node.a
LIBBITCOIN_COMMON=libbitcoin_common.a
Expand Down Expand Up @@ -73,10 +75,10 @@ $(LIBSECP256K1): $(wildcard secp256k1/src/*.h) $(wildcard secp256k1/src/*.c) $(w
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C $(@D) $(@F)

$(LIBBLS):
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C bls lib/libbls384_256.a
$(AM_V_at) CC='$(CC)' CXX='$(CXX)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) $(AM_MAKEFLAGS) -C bls lib/libbls384_256.a

$(LIBMCL):
$(AM_V_at)$(MAKE) $(AM_MAKEFLAGS) -C bls/mcl lib/libmcl.a
$(AM_V_at) MCL_USE_LLVM=0 CC='$(CC)' CXX='$(CXX)' CPPFLAGS='$(CPPFLAGS)' LDFLAGS='$(LDFLAGS)' $(MAKE) $(AM_MAKEFLAGS) -C bls/mcl lib/libmcl.a

# Make is not made aware of per-object dependencies to avoid limiting building parallelization
# But to build the less dependent modules first, we manually select their order here:
Expand Down Expand Up @@ -133,6 +135,10 @@ BITCOIN_CORE_H = \
bech32.h \
blockencodings.h \
blockfilter.h \
blsct/arith/elements.h \
blsct/arith/g1point.h \
blsct/arith/mcl_initializer.h \
blsct/arith/scalar.h \
chain.h \
chainparams.h \
chainparamsbase.h \
Expand Down Expand Up @@ -361,6 +367,10 @@ libbitcoin_node_a_SOURCES = \
banman.cpp \
blockencodings.cpp \
blockfilter.cpp \
blsct/arith/elements.cpp \
blsct/arith/g1point.cpp \
blsct/arith/mcl_initializer.cpp \
blsct/arith/scalar.cpp \
chain.cpp \
consensus/tx_verify.cpp \
dbwrapper.cpp \
Expand Down Expand Up @@ -858,8 +868,8 @@ if BUILD_BITCOIN_KERNEL_LIB
lib_LTLIBRARIES += $(LIBBITCOINKERNEL)

libbitcoinkernel_la_LDFLAGS = $(AM_LDFLAGS) -no-undefined $(RELDFLAGS) $(PTHREAD_FLAGS)
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBSECP256K1)
libbitcoinkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include -DBUILD_BITCOIN_INTERNAL $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)
libbitcoinkernel_la_LIBADD = $(LIBBITCOIN_CRYPTO) $(LIBUNIVALUE) $(LIBLEVELDB) $(LIBMEMENV) $(LIBBLS) $(LIBMCL) $(LIBSECP256K1)
libbitcoinkernel_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(builddir)/obj -I$(srcdir)/secp256k1/include $(BLS_INCLUDES) -DBUILD_BITCOIN_INTERNAL $(BOOST_CPPFLAGS) $(LEVELDB_CPPFLAGS) -I$(srcdir)/$(UNIVALUE_INCLUDE_DIR_INT)

# libbitcoinkernel requires default symbol visibility, explicitly specify that
# here so that things still work even when user configures with
Expand All @@ -884,6 +894,11 @@ endif
libbitcoinkernel_la_SOURCES = \
kernel/bitcoinkernel.cpp \
arith_uint256.cpp \
blockfilter.cpp \
blsct/arith/elements.cpp \
blsct/arith/g1point.cpp \
blsct/arith/mcl_initializer.cpp \
blsct/arith/scalar.cpp \
chain.cpp \
chainparamsbase.cpp \
chainparams.cpp \
Expand Down
4 changes: 4 additions & 0 deletions src/Makefile.test.include
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ BITCOIN_TESTS =\
test/blockfilter_index_tests.cpp \
test/blockfilter_tests.cpp \
test/bloom_tests.cpp \
test/blsct/arith/elements_tests.cpp \
test/blsct/arith/g1point_tests.cpp \
test/blsct/arith/scalar_tests.cpp \
test/blsct/arith/bls_arith_integration_tests.cpp \
test/bswap_tests.cpp \
test/checkqueue_tests.cpp \
test/coins_tests.cpp \
Expand Down
7 changes: 7 additions & 0 deletions src/Makefile.test_util.include
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@ EXTRA_LIBRARIES += \

TEST_UTIL_H = \
test/util/blockfilter.h \
blsct/arith/g1point.h \
blsct/arith/mcl_initializer.h \
blsct/arith/scalar.h \
test/util/chainstate.h \
test/util/logging.h \
test/util/mining.h \
Expand All @@ -22,7 +25,11 @@ TEST_UTIL_H = \

libtest_util_a_CPPFLAGS = $(AM_CPPFLAGS) $(BITCOIN_INCLUDES) $(MINIUPNPC_CPPFLAGS) $(NATPMP_CPPFLAGS) $(EVENT_CFLAGS) $(EVENT_PTHREADS_CFLAGS)
libtest_util_a_CXXFLAGS = $(AM_CXXFLAGS) $(PIE_FLAGS)
libtest_util_a_LIBADD = $(LIBBLS) $(LIBMCL)
libtest_util_a_SOURCES = \
blsct/arith/g1point.cpp \
blsct/arith/mcl_initializer.cpp \
blsct/arith/scalar.cpp \
test/util/blockfilter.cpp \
test/util/logging.cpp \
test/util/mining.cpp \
Expand Down
4 changes: 4 additions & 0 deletions src/bls/mcl/src/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
base64.ll
func.list
gen
gen.dSYM/
Loading

0 comments on commit 575880a

Please sign in to comment.