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
std feature flag (enabled by default)
- Configure all dependencies with
default-features = false
- Make
thiserror optional (only available with std)
- Add
curve feature to ark-bn254 for Fr support in no_std
lib.rs:
- Add
#![cfg_attr(not(feature = "std"), no_std)]
- Import
extern crate alloc for no_std environments
- Use
alloc::vec::Vec conditionally
- Create dual implementation of
PoseidonError (with/without thiserror)
parameters/bn254_x5.rs:
- Import
alloc::vec macro for no_std
- Replace
std::convert with core::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.
Currently,
light-poseidoncannot 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_stdsupport while maintaining full backward compatibility. I have already implemented and tested this in my fork at https://github.com/orbinum/light-poseidon-nostdChanges Required
Cargo.toml:
stdfeature flag (enabled by default)default-features = falsethiserroroptional (only available with std)curvefeature toark-bn254for Fr support in no_stdlib.rs:
#![cfg_attr(not(feature = "std"), no_std)]extern crate allocfor no_std environmentsalloc::vec::VecconditionallyPoseidonError(with/without thiserror)parameters/bn254_x5.rs:
alloc::vecmacro for no_stdstd::convertwithcore::convertVerification
All changes have been tested and verified:
Usage
Benefits
I'm ready to submit a PR with these changes.