-
Notifications
You must be signed in to change notification settings - Fork 20
Open
Description
Currently, light-poseidon cannot be used in Substrate runtimes or other WASM environments that don't have access to the standard library. This limits its adoption in the Polkadot/Substrate ecosystem and other blockchain platforms.
Add no_std support while maintaining full backward compatibility. I have already implemented and tested this in my fork at https://github.com/orbinum/light-poseidon-nostd
Changes Required
Cargo.toml:
- Add
stdfeature flag (enabled by default) - Configure all dependencies with
default-features = false - Make
thiserroroptional (only available with std) - Add
curvefeature toark-bn254for Fr support in no_std
lib.rs:
- Add
#![cfg_attr(not(feature = "std"), no_std)] - Import
extern crate allocfor no_std environments - Use
alloc::vec::Vecconditionally - Create dual implementation of
PoseidonError(with/without thiserror)
parameters/bn254_x5.rs:
- Import
alloc::vecmacro for no_std - Replace
std::convertwithcore::convert
Verification
All changes have been tested and verified:
# no_std build for WASM
cargo build --no-default-features --target wasm32-unknown-unknown ✓
# Standard build
cargo build ✓
# All tests pass
cargo test ✓ (35 tests)Usage
# For no_std environments
[dependencies]
light-poseidon = { version = "0.4.0", default-features = false }
# For std environments (default, unchanged)
[dependencies]
light-poseidon = "0.4.0"Benefits
- Enables use in Substrate runtimes and WASM targets
- Zero breaking changes (std enabled by default)
- All existing tests pass
- No performance impact
I'm ready to submit a PR with these changes.
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels