与博客Polynomial Commitments代码实现【1】——scipr-lab/poly-commit(含不同曲线性能对比)中类似,lovesh/kzg-poly-commit也是基于论文《Polynomial Commitments∗》的代码实现。
1. finite域及group element运算https://github.com/lovesh/amcl_rust_wrapper是在https://github.com/miracl/amcl基础上进行了二次封装,同时:
- 重载了
+, -, *, +=, -=
运算,保证方法运行为constant time。对于scalar multiplication,也提供了variable time算法实现。 - 抽象了field元素和group元素vector的创建方法,支持scale,add,inner product和Hadamard product运算。
- 通过
serde
进行序列化。 - 实用
clear_on_drop
来清理不用的field和group元素。 - 提供了wNAF variable time scalar multiplication方法,以及其它constant time和variable time multi-scalar multiplication方法,提供了batch(simultaneous)inversion 和Barrett reduction方法。
在Cargo.toml
中配置features来指定所需使用的曲线(支持bls381/secp256k1等等曲线):
[dependencies.amcl_wrapper]
git = "https://github.com/lovesh/amcl_rust_wrapper"
branch = "master"
features = ["bls381"]
目前https://github.com/miracl/amcl仅做bug维护,不做新功能更新。最新的库见https://github.com/miracl/core,该库为多曲线多语言实现,MIRACL Core was designed from the ground up with side-channel attack resistance in mind.
参考资料: [1] 论文《Polynomial Commitments∗》 [2] 代码库:https://github.com/lovesh/kzg-poly-commit [3] 博客polynomial commitment及实现方式对比 [4] 博客椭圆曲线形式下的Pedersen commitment——vector commitmnt和polynomial commitment