Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dev v2 #95

Merged
merged 6 commits into from
Jun 1, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
Fix windows build (#97)
  • Loading branch information
ChickenLover committed Jun 1, 2023
commit 24096b6cf7a4f761f5284521eee83f68df281ff6
30 changes: 15 additions & 15 deletions icicle/appUtils/poseidon/constants.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,27 @@
#include "constants/constants_8.h"
#include "constants/constants_11.h"

const std::map<uint, uint> ARITY_TO_ROUND_NUMBERS = {
{2, 55},
{4, 56},
{8, 57},
{11, 57},
uint32_t partial_rounds_number_from_arity(const uint32_t arity) {
switch (arity) {
case 2:
return 55;
case 4:
return 56;
case 8:
return 57;
case 11:
return 57;
default:
throw std::invalid_argument( "unsupported arity" );
}
};

// TO-DO: change to mapping
const uint FULL_ROUNDS_DEFAULT = 4;

static void get_round_numbers(const uint arity, uint * partial_rounds, uint * half_full_rounds) {
auto partial = ARITY_TO_ROUND_NUMBERS.find(arity);
assert(partial != ARITY_TO_ROUND_NUMBERS.end());

*partial_rounds = partial->second;
*half_full_rounds = FULL_ROUNDS_DEFAULT;
}
const uint32_t FULL_ROUNDS_DEFAULT = 4;

// TO-DO: for now, the constants are only generated in bls12_381
template <typename S>
S * load_constants(const uint arity) {
S * load_constants(const uint32_t arity) {
unsigned char * constants;
switch (arity) {
case 2:
Expand Down
15 changes: 8 additions & 7 deletions icicle/appUtils/poseidon/poseidon.cuh
Original file line number Diff line number Diff line change
Expand Up @@ -48,22 +48,22 @@ __device__ void print_scalar(S element, int data) {

template <typename S>
struct PoseidonConfiguration {
uint partial_rounds, full_rounds_half, t;
uint32_t partial_rounds, full_rounds_half, t;
S * round_constants, * mds_matrix, * non_sparse_matrix, *sparse_matrices;
};

template <typename S>
class Poseidon {
public:
uint t;
uint32_t t;
PoseidonConfiguration<S> config;

enum HashType {
ConstInputLen,
MerkleTree,
};

Poseidon(const uint arity) {
Poseidon(const uint32_t arity) {
t = arity + 1;
this->config.t = t;

Expand All @@ -79,11 +79,12 @@ class Poseidon {
// const_input_no_pad_domain_tag = S::one() << 64;
// const_input_no_pad_domain_tag *= S::from(arity);

get_round_numbers(arity, &this->config.partial_rounds, &this->config.full_rounds_half);
this->config.full_rounds_half = FULL_ROUNDS_DEFAULT;
this->config.partial_rounds = partial_rounds_number_from_arity(arity);

uint round_constants_len = t * this->config.full_rounds_half * 2 + this->config.partial_rounds;
uint mds_matrix_len = t * t;
uint sparse_matrices_len = (t * 2 - 1) * this->config.partial_rounds;
uint32_t round_constants_len = t * this->config.full_rounds_half * 2 + this->config.partial_rounds;
uint32_t mds_matrix_len = t * t;
uint32_t sparse_matrices_len = (t * 2 - 1) * this->config.partial_rounds;

// All the constants are stored in a single file
S * constants = load_constants<S>(arity);
Expand Down