Skip to content

Commit

Permalink
Release v1.2.0 (#364)
Browse files Browse the repository at this point in the history
Release v1.2.0:

- [FEAT] Add Poseidon hash as primitive
- [FEAT] Add Merkle tree using poseidon hash
- [BUG] Fix NTT overflow when using large cosets
  • Loading branch information
jeremyfelder authored Feb 7, 2024
2 parents 77a7613 + 5a13836 commit b6dded8
Show file tree
Hide file tree
Showing 55 changed files with 46,664 additions and 7,330 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/main-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ jobs:
# Building from the root workspace will build all members of the workspace by default
run: cargo build --release --verbose

# TODO: Reenable once Golang bindings for v1+ is finished
# TODO: Re-enable once Golang bindings for v1+ is finished
# build-golang-linux:
# name: Build Golang on Linux
# runs-on: [self-hosted, Linux, X64, icicle]
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/main-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ jobs:
if: needs.check-changed-files.outputs.cpp_cuda == 'true'
run: ctest

# TODO: Reenable once Golang bindings for v1+ is finished
# TODO: Re-enable once Golang bindings for v1+ is finished
# test-golang-linux:
# name: Test Golang on Linux
# runs-on: [self-hosted, Linux, X64, icicle]
Expand Down
7 changes: 7 additions & 0 deletions icicle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ include_directories("${CMAKE_SOURCE_DIR}")

# when adding a new curve/field, append its name to the end of this list
set(SUPPORTED_CURVES bn254;bls12_381;bls12_377;bw6_761)
set(SUPPORTED_CURVES_WITH_POSEIDON bn254;bls12_381;bls12_377;bw6_761)

set(IS_CURVE_SUPPORTED FALSE)
set(I 0)
Expand All @@ -94,6 +95,11 @@ if (NOT BUILD_TESTS)

message(STATUS "Building without tests.")

if (CURVE IN_LIST SUPPORTED_CURVES_WITH_POSEIDON)
list(APPEND ICICLE_SOURCES appUtils/poseidon/poseidon.cu)
list(APPEND ICICLE_SOURCES appUtils/tree/merkle.cu)
endif()

add_library(
icicle
utils/vec_ops.cu
Expand All @@ -102,6 +108,7 @@ if (NOT BUILD_TESTS)
primitives/projective.cu
appUtils/msm/msm.cu
appUtils/ntt/ntt.cu
${ICICLE_SOURCES}
)
set_target_properties(icicle PROPERTIES OUTPUT_NAME "ingo_${CURVE}")
target_compile_definitions(icicle PRIVATE CURVE=${CURVE})
Expand Down
1 change: 1 addition & 0 deletions icicle/appUtils/poseidon/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
test_poseidon
3 changes: 3 additions & 0 deletions icicle/appUtils/poseidon/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
test_poseidon: test.cu poseidon.cu kernels.cu constants.cu
nvcc -o test_poseidon -I. -I../.. test.cu
./test_poseidon
115 changes: 115 additions & 0 deletions icicle/appUtils/poseidon/constants.cu
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
#include "poseidon.cuh"

/// These are pre-calculated constants for different curves
#if CURVE_ID == BN254
#include "appUtils/poseidon/constants/bn254_poseidon.h"
using namespace poseidon_constants_bn254;
#elif CURVE_ID == BLS12_381
#include "appUtils/poseidon/constants/bls12_381_poseidon.h"
using namespace poseidon_constants_bls12_381;
#elif CURVE_ID == BLS12_377
#include "appUtils/poseidon/constants/bls12_377_poseidon.h"
using namespace poseidon_constants_bls12_377;
#elif CURVE_ID == BW6_761
#include "appUtils/poseidon/constants/bw6_761_poseidon.h"
using namespace poseidon_constants_bw6_761;
#endif

namespace poseidon {
template <typename S>
cudaError_t create_optimized_poseidon_constants(
int arity,
int full_rounds_half,
int partial_rounds,
const S* constants,
device_context::DeviceContext& ctx,
PoseidonConstants<S>* poseidon_constants)
{
CHK_INIT_IF_RETURN();
cudaStream_t& stream = ctx.stream;
int width = arity + 1;
int round_constants_len = width * full_rounds_half * 2 + partial_rounds;
int mds_matrix_len = width * width;
int sparse_matrices_len = (width * 2 - 1) * partial_rounds;
int constants_len = round_constants_len + mds_matrix_len * 2 + sparse_matrices_len;

// Malloc memory for copying constants
S* d_constants;
CHK_IF_RETURN(cudaMallocAsync(&d_constants, sizeof(S) * constants_len, stream));

// Copy constants
CHK_IF_RETURN(cudaMemcpyAsync(d_constants, constants, sizeof(S) * constants_len, cudaMemcpyHostToDevice, stream));

S* round_constants = d_constants;
S* mds_matrix = round_constants + round_constants_len;
S* non_sparse_matrix = mds_matrix + mds_matrix_len;
S* sparse_matrices = non_sparse_matrix + mds_matrix_len;

// Pick the domain_tag accordinaly
// For now, we only support Merkle tree mode
uint32_t tree_domain_tag_value = 1;
tree_domain_tag_value = (tree_domain_tag_value << (width - 1)) - tree_domain_tag_value;
S domain_tag = S::from(tree_domain_tag_value);

// Make sure all the constants have been copied
CHK_IF_RETURN(cudaStreamSynchronize(stream));
*poseidon_constants = {arity, partial_rounds, full_rounds_half, round_constants,
mds_matrix, non_sparse_matrix, sparse_matrices, domain_tag};

return CHK_LAST();
}

template <typename S>
cudaError_t init_optimized_poseidon_constants(
int arity, device_context::DeviceContext& ctx, PoseidonConstants<S>* poseidon_constants)
{
CHK_INIT_IF_RETURN();
int full_rounds_half = FULL_ROUNDS_DEFAULT;
int partial_rounds;
unsigned char* constants;
switch (arity) {
case 2:
constants = poseidon_constants_2;
partial_rounds = partial_rounds_2;
break;
case 4:
constants = poseidon_constants_4;
partial_rounds = partial_rounds_4;
break;
case 8:
constants = poseidon_constants_8;
partial_rounds = partial_rounds_8;
break;
case 11:
constants = poseidon_constants_11;
partial_rounds = partial_rounds_11;
break;
default:
THROW_ICICLE_ERR(
IcicleError_t::InvalidArgument, "init_optimized_poseidon_constants: #arity must be one of [2, 4, 8, 11]");
}
S* h_constants = reinterpret_cast<S*>(constants);

create_optimized_poseidon_constants(arity, full_rounds_half, partial_rounds, h_constants, ctx, poseidon_constants);

return CHK_LAST();
}

extern "C" cudaError_t CONCAT_EXPAND(CURVE, CreateOptimizedPoseidonConstants)(
int arity,
int full_rounds_half,
int partial_rounds,
const curve_config::scalar_t* constants,
device_context::DeviceContext& ctx,
PoseidonConstants<curve_config::scalar_t>* poseidon_constants)
{
return create_optimized_poseidon_constants<curve_config::scalar_t>(
arity, full_rounds_half, partial_rounds, constants, ctx, poseidon_constants);
}

extern "C" cudaError_t CONCAT_EXPAND(CURVE, InitOptimizedPoseidonConstants)(
int arity, device_context::DeviceContext& ctx, PoseidonConstants<curve_config::scalar_t>* constants)
{
return init_optimized_poseidon_constants<curve_config::scalar_t>(arity, ctx, constants);
}
} // namespace poseidon
54 changes: 0 additions & 54 deletions icicle/appUtils/poseidon/constants.cuh

This file was deleted.

Loading

0 comments on commit b6dded8

Please sign in to comment.