e6dc3dac45
Computing Poseidon[0] hashes is too expensive to be done in a Solana program in one transaction. Poseidon is a zero-knowlege proof friendly hash function, used by the majority of ZK-based projects, including the ones built on top of Solana. This change introduces the `sol_poseidon` syscall which takes 2D byte slice as an input and then calculates a Poseidon hash using a BN254 curve and the following Poseidon parameters: * x^5 S-boxes * width - 2 ≤ t ≤ 13 * inputs - 1 ≤ n ≤ 12 * 8 full rounds and partial rounds depending on t: [56, 57, 56, 60, 60, 63, 64, 63, 60, 66, 60, 65] Computation of Poseidon hashes is done with the light-poseidon[1] crate, which is audited[2] and compatible with Circom[3] (BN254 curve, the same parameters and constants). Proposed compute costs depend on number of inputs and are based on light-poseidon benchmarks[4]. [0] https://www.poseidon-hash.info/ [1] https://crates.io/crates/light-poseidon [2] https://github.com/Lightprotocol/light-poseidon/blob/main/assets/audit.pdf [3] https://docs.circom.io/ [4] https://github.com/Lightprotocol/light-poseidon/tree/main#performance |
||
---|---|---|
.. | ||
inc | ||
README.md | ||
sbf.ld | ||
sbf.mk |
README.md
Development
Quick start
To get started create a makefile
containing:
include path/to/sbf.mk
and src/program.c
containing:
#include <solana_sdk.h>
bool entrypoint(const uint8_t *input) {
SolKeyedAccount ka[1];
uint8_t *data;
uint64_t data_len;
if (!sol_deserialize(buf, ka, SOL_ARRAY_SIZE(ka), NULL, &data, &data_len)) {
return false;
}
print_params(1, ka, data, data_len);
return true;
}
Then run make
to build out/program.o
.
Run make help
for more details.
Unit tests
Built-in support for unit testing is provided by the
Criterion test framework.
To get started create the file test/example.c
containing:
#include <criterion/criterion.h>
#include "../src/program.c"
Test(test_suite_name, test_case_name) {
cr_assert(true);
}
Then run make test
.
Limitations
- Programs must be fully contained within a single .c file
- No libc is available but
solana_sdk.h
provides a minimal set of primitives