Skip to content

Commit

Permalink
add workflows & fix bandersnatch test error
Browse files Browse the repository at this point in the history
  • Loading branch information
guozhengxuan committed Aug 22, 2024
1 parent b605bc0 commit cd3eafc
Show file tree
Hide file tree
Showing 6 changed files with 139 additions and 94 deletions.
61 changes: 59 additions & 2 deletions .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ jobs:
- name: vcpkg essentials
run: |
git clone https://github.com/microsoft/vcpkg.git
export VCPKG_ROOT=$(pwd)/vcpkg
export PATH=$PATH:$VCPKG_ROOT
echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV"
echo "PATH=$PATH:$VCPKG_ROOT" >> "$GITHUB_ENV"
- name: configure
if: runner.os == 'macOS'
run: |
Expand All @@ -47,5 +47,62 @@ jobs:
cmake --preset=test
- name: compile
run: cmake --build build -j2
- name: run test
run: cd build/bandersnatch && ctest
build_with_gcc:
name: build_with_gcc
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-20.04]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: install Ubuntu dependencies
run: |
sudo apt update
sudo apt install -y git curl build-essential cmake
- name: vcpkg essentials
run: |
git clone https://github.com/microsoft/vcpkg.git
echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV"
echo "PATH=$PATH:$VCPKG_ROOT" >> "$GITHUB_ENV"
- name: configure
run: |
export GCC='gcc-10'
export CXX='g++-10'
cmake --preset=test
- name: compile
run: cmake --build build -j2
- name: run test
run: cd build/bandersnatch && ctest
ubuntu22_04_build_with_gcc:
name: ubuntu22_04_build_with_gcc
runs-on: ${{ matrix.os }}
strategy:
matrix:
os: [ubuntu-22.04]
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 5
- name: install Ubuntu dependencies
run: |
sudo apt-get update
sudo apt-get install -y git curl build-essential cmake lcov libzstd-dev python3-dev
- name: vcpkg essentials
run: |
git clone https://github.com/microsoft/vcpkg.git
echo "VCPKG_ROOT=$(pwd)/vcpkg" >> "$GITHUB_ENV"
echo "PATH=$PATH:$VCPKG_ROOT" >> "$GITHUB_ENV"
- name: configure
run: |
export GCC='gcc-10'
export CXX='g++-10'
export CPATH=/Library/Developer/CommandLineTools/usr/include/c++/v1
cmake --preset=test
- name: compile
run: cmake --build build -j2
- name: run test
run: cd build/bandersnatch && ctest
1 change: 1 addition & 0 deletions bandersnatch/bandersnatch/Fr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
//

#include <cstdint>
#include <cstring>
#include <random>
#include "Fr.h"

Expand Down
30 changes: 14 additions & 16 deletions bandersnatch/test/unittests/Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,27 +6,25 @@ namespace verkle::test
{
static inline const bandersnatch::Fr& FixedFr1()
{
static bandersnatch::Fr fr1(
(uint64_t[4]){
0xe5d76b4ca918a221,
0x81ed0b8d092ec3c6,
0xd124e15f2054fa57,
0x2ef123703093cbbb,
}
);
static uint64_t raw[4] = {
0xe5d76b4ca918a221,
0x81ed0b8d092ec3c6,
0xd124e15f2054fa57,
0x2ef123703093cbbb,
};
static bandersnatch::Fr fr1(raw);
return fr1;
}

static inline const bandersnatch::Fr& FixedFr2()
{
static bandersnatch::Fr fr2(
(uint64_t[4]){
0xd894647091277b9c,
0x5182f0e810967f58,
0x42958c4a5cf47f12,
0x61b589a0f601132d,
}
);
static uint64_t raw[4] = {
0xd894647091277b9c,
0x5182f0e810967f58,
0x42958c4a5cf47f12,
0x61b589a0f601132d,
};
static bandersnatch::Fr fr2(raw);
return fr2;
}

Expand Down
80 changes: 36 additions & 44 deletions bandersnatch/test/unittests/ElementTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ BOOST_FIXTURE_TEST_SUITE(ElementTest, TestPromptFixture)

BOOST_AUTO_TEST_CASE(testAdd)
{
bandersnatch::Element exp(
(uint8_t[96]){
0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0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x9d, 0x28
};
bandersnatch::Element exp(raw, 96);
auto g = FixedGenerator();
auto res = bandersnatch::Element::add(g, g);
BOOST_ASSERT(res == exp);
Expand All @@ -34,17 +32,15 @@ BOOST_AUTO_TEST_CASE(testAdd)

BOOST_AUTO_TEST_CASE(testDouble)
{
bandersnatch::Element exp(
(uint8_t[96]){
0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc,
0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a,
0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e,
0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38,
0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a,
0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28
},
96
);
uint8_t raw[96] = {
0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc,
0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a,
0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e,
0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38,
0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a,
0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28
};
bandersnatch::Element exp(raw, 96);
auto g = FixedGenerator();
auto res = bandersnatch::Element::dbl(g);
BOOST_ASSERT(res == exp);
Expand All @@ -56,17 +52,15 @@ BOOST_AUTO_TEST_CASE(testDouble)

BOOST_AUTO_TEST_CASE(testMult)
{
bandersnatch::Element exp(
(uint8_t[96]){
0x16, 0xf8, 0x9e, 0x71, 0x6a, 0xbc, 0x6e, 0x4f, 0x4e, 0xc9, 0xd7, 0x1a, 0x5f, 0x5, 0x38, 0x32,
0x51, 0xc0, 0x1e, 0xd9, 0xc4, 0xf, 0x2f, 0x4d, 0xdc, 0x9a, 0x77, 0xd8, 0x7b, 0xf6, 0xc, 0x4a,
0xa2, 0xea, 0x60, 0x3a, 0x8d, 0x3a, 0xda, 0x49, 0x4f, 0x6f, 0x6d, 0x15, 0x87, 0x87, 0xa4, 0x49,
0xd, 0x83, 0x9, 0x7b, 0xa7, 0x85, 0x97, 0x4, 0x2, 0x4b, 0x49, 0x41, 0xfd, 0x76, 0xf, 0x85,
0xbc, 0xa6, 0xdb, 0xc4, 0xa8, 0x4a, 0x7, 0x1a, 0xf9, 0xef, 0x44, 0x3c, 0x1a, 0x55, 0x3f, 0xc8,
0x7f, 0xc6, 0x1e, 0x9, 0x92, 0xa4, 0x0, 0x6d, 0x54, 0xfa, 0x36, 0x70, 0x5f, 0x61, 0x16, 0x90
},
96
);
uint8_t raw[96] = {
0x16, 0xf8, 0x9e, 0x71, 0x6a, 0xbc, 0x6e, 0x4f, 0x4e, 0xc9, 0xd7, 0x1a, 0x5f, 0x5, 0x38, 0x32,
0x51, 0xc0, 0x1e, 0xd9, 0xc4, 0xf, 0x2f, 0x4d, 0xdc, 0x9a, 0x77, 0xd8, 0x7b, 0xf6, 0xc, 0x4a,
0xa2, 0xea, 0x60, 0x3a, 0x8d, 0x3a, 0xda, 0x49, 0x4f, 0x6f, 0x6d, 0x15, 0x87, 0x87, 0xa4, 0x49,
0xd, 0x83, 0x9, 0x7b, 0xa7, 0x85, 0x97, 0x4, 0x2, 0x4b, 0x49, 0x41, 0xfd, 0x76, 0xf, 0x85,
0xbc, 0xa6, 0xdb, 0xc4, 0xa8, 0x4a, 0x7, 0x1a, 0xf9, 0xef, 0x44, 0x3c, 0x1a, 0x55, 0x3f, 0xc8,
0x7f, 0xc6, 0x1e, 0x9, 0x92, 0xa4, 0x0, 0x6d, 0x54, 0xfa, 0x36, 0x70, 0x5f, 0x61, 0x16, 0x90
};
bandersnatch::Element exp(raw, 96);
auto g = FixedGenerator();
auto fr1 = FixedFr1();
auto res1 = bandersnatch::Element::mult(fr1, g);
Expand All @@ -79,17 +73,15 @@ BOOST_AUTO_TEST_CASE(testMult)

BOOST_AUTO_TEST_CASE(testEqual)
{
bandersnatch::Element e(
(uint8_t[96]){
0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc,
0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a,
0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e,
0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38,
0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a,
0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28
},
96
);
uint8_t raw[96] = {
0x5, 0x72, 0xcb, 0xea, 0x90, 0x4d, 0x67, 0x46, 0x88, 0x8, 0xc8, 0xeb, 0x50, 0xa9, 0x45, 0xc,
0x97, 0x21, 0xdb, 0x30, 0x91, 0x28, 0x1, 0x25, 0x43, 0x90, 0x2d, 0xa, 0xc3, 0x58, 0xa6, 0x2a,
0xe2, 0x8f, 0x75, 0xbb, 0x8f, 0x1c, 0x7c, 0x42, 0xc3, 0x9a, 0x8c, 0x55, 0x29, 0xbf, 0xf, 0x4e,
0x16, 0x6a, 0x9d, 0x8c, 0xab, 0xc6, 0x73, 0xa3, 0x22, 0xfd, 0xa6, 0x73, 0x77, 0x9d, 0x8e, 0x38,
0x22, 0xba, 0x3e, 0xcb, 0x86, 0x70, 0xe4, 0x61, 0xf7, 0x3b, 0xb9, 0x2, 0x1d, 0x5f, 0xd7, 0x6a,
0x4c, 0x56, 0xd9, 0xd4, 0xcd, 0x16, 0xbd, 0x1b, 0xba, 0x86, 0x88, 0x19, 0x79, 0x74, 0x9d, 0x28
};
bandersnatch::Element e(raw, 96);
bandersnatch::Element e1(e);
bandersnatch::Element e2(e);
BOOST_ASSERT(e1 == e2);
Expand Down
61 changes: 29 additions & 32 deletions bandersnatch/test/unittests/FrTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,14 +40,13 @@ BOOST_AUTO_TEST_CASE(testRandom)

BOOST_AUTO_TEST_CASE(testAdd)
{
bandersnatch::Fr exp(
(uint64_t[4]){
0xbe6bcfbe3a401dbc,
0x7fb2587219c6e720,
0xe08095a173a7a164,
0x1cb905bdfcf761a0,
}
);
uint64_t raw[4] = {
0xbe6bcfbe3a401dbc,
0x7fb2587219c6e720,
0xe08095a173a7a164,
0x1cb905bdfcf761a0,
};
bandersnatch::Fr exp(raw);
auto f1 = FixedFr1();
auto f2 = FixedFr2();

Expand All @@ -61,14 +60,14 @@ BOOST_AUTO_TEST_CASE(testAdd)

BOOST_AUTO_TEST_CASE(testSub)
{
bandersnatch::Fr exp(
(uint64_t[4]){
0xd4306db17f12686,
0x8427bea7f896a06d,
0xc1c92d1ccd02534a,
0x41294122643035d6,
}
);
uint64_t raw[4] =
{
0xd4306db17f12686,
0x8427bea7f896a06d,
0xc1c92d1ccd02534a,
0x41294122643035d6,
};
bandersnatch::Fr exp(raw);
auto f1 = FixedFr1();
auto f2 = FixedFr2();

Expand All @@ -82,14 +81,13 @@ BOOST_AUTO_TEST_CASE(testSub)

BOOST_AUTO_TEST_CASE(testMult)
{
bandersnatch::Fr exp(
(uint64_t[4]){
0xe9f26c96d15bb807,
0x6ad84e7137609152,
0xe193b5e1ce7d01c4,
0x27625b6a622c0518,
}
);
uint64_t raw[4] = {
0xe9f26c96d15bb807,
0x6ad84e7137609152,
0xe193b5e1ce7d01c4,
0x27625b6a622c0518,
};
bandersnatch::Fr exp(raw);
auto f1 = FixedFr1();
auto f2 = FixedFr2();

Expand All @@ -103,14 +101,13 @@ BOOST_AUTO_TEST_CASE(testMult)

BOOST_AUTO_TEST_CASE(testInv)
{
bandersnatch::Fr exp(
(uint64_t[4]){
0xc2eecde5714050d6,
0x19f77495338244b4,
0x65208d07b3ef94b1,
0x524a236a985c691d,
}
);
uint64_t raw[4] = {
0xc2eecde5714050d6,
0x19f77495338244b4,
0x65208d07b3ef94b1,
0x524a236a985c691d,
};
bandersnatch::Fr exp(raw);
auto f1 = FixedFr1();
auto res = f1.inv();
BOOST_ASSERT(res == exp);
Expand Down
File renamed without changes.

0 comments on commit cd3eafc

Please sign in to comment.