RISC Zero的Babybear域 及其 扩域

2024-01-02 22:36
文章标签 risc zero babybear 扩域

本文主要是介绍RISC Zero的Babybear域 及其 扩域,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

1. 引言

前序博客见:

  • 有限域的Fast Multiplication和Modular Reduction算法实现

代码实现见:

  • https://github.com/risc0/risc0/blob/main/risc0/core/src/field/baby_bear.rs
  • https://github.com/risc0/risc0/tree/main/risc0/circuit/rv32im-sys/cxx
  • https://github.com/risc0/risc0/blob/main/risc0/circuit/recursion-sys/cxx
  • https://github.com/risc0/risc0/tree/main/risc0/build_kernel/kernels/cuda(Babybear域 及其 扩域 的CUDA代码实现)
  • https://github.com/risc0/risc0/tree/main/risc0/build_kernel/kernels/metal(Babybear域 及其 扩域 的Metal代码实现)

Babybear域 F p \mathbb{F}_p Fp,其中 p = 2 31 − 2 17 + 1 = 15 ∗ 2 17 + 1 p=2^{31}-2^{17}+1=15*2^{17}+1 p=231217+1=15217+1,取其4-th 扩域 F p 4 \mathbb{F}_{p^4} Fp4的不可约多项式为 x 4 − 11 x^4-11 x411。对应的sagemath验证脚本为:

sage: p=2**31-2**27+1 
....: R.<x> = GF(p)[] 
....: (x^4 - 11).is_irreducible()                                               
True

对应的域定义为:

/// The BabyBear class is an element of the finite field F_p, where P is the
/// prime number 15*2^27 + 1. Put another way, Fp is basically integer
/// arithmetic modulo P.
///
/// The `Fp` datatype is the core type of all of the operations done within the
/// zero knowledge proofs, and is the smallest 'addressable' datatype, and the
/// base type of which all composite types are built. In many ways, one can
/// imagine it as the word size of a very strange architecture.
///
/// This specific prime P was chosen to:
/// - Be less than 2^31 so that it fits within a 32 bit word and doesn't
///   overflow on addition.
/// - Otherwise have as large a power of 2 in the factors of P-1 as possible.
///
/// This last property is useful for number theoretical transforms (the fast
/// fourier transform equivelant on finite fields). See NTT.h for details.
///
/// The Fp class wraps all the standard arithmetic operations to make the finite
/// field elements look basically like ordinary numbers (which they mostly are).
#[derive(Eq, Clone, Copy, Pod, Zeroable)]
#[repr(transparent)]
pub struct Elem(u32); //F_p
/// Alias for the Baby Bear [Elem]
pub type BabyBearElem = Elem;/// The size of the extension field in elements, 4 in this case.
const EXT_SIZE: usize = 4;/// Instances of `ExtElem` are elements of a finite field `F_p^4`. They are
/// represented as elements of `F_p[X] / (X^4 - 11)`. This large
/// finite field (about `2^128` elements) is used when the security of
/// operations depends on the size of the field. The field extension `ExtElem`
/// has `Elem` as a subfield, so operations on elements of each are compatible.
/// The irreducible polynomial `x^4 - 11` was chosen because `11` is
/// the smallest choice of `B` for `x^4 - B` that makes this polynomial
/// irreducible.
#[derive(Eq, Clone, Copy, Pod, Zeroable)]
#[repr(transparent)]
pub struct ExtElem([Elem; EXT_SIZE]); //F_{p^4}扩域/* struct Fp4 {/// The elements of Fp4, elems[0] + elems[1]*X + elems[2]*X^2 + elems[3]*x^4Fp elems[4];....} */

根据 有限域的Fast Multiplication和Modular Reduction算法实现,BabyBear域运算采用Montgomery形式:
在这里插入图片描述
在这里插入图片描述
在这里插入图片描述
鉴于单个Babybear域元素可 以32位整数表示,2个Babybear域元素 0 ≤ u , v < p 0\leq u,v <p 0u,v<p 乘积可 以64位整数表示,且无需考虑进位情况。对应为:

  • b = 2 32 b=2^{32} b=232
  • n = 1 n=1 n=1
  • R = b n = 2 32 R=b^n=2^{32} R=bn=232
  • 实际代码实现时,由于 n = 1 n=1 n=1,可预计算出相应的R2值为mod(r^2, p),相应的M值为mod(1/p,r)
sage: p=2**31-2**27+1 
sage: r=2**32                                                                   
sage: mod(r^2, p)                                                               
1172168163
sage: mod(1/p,r)                                                                
2281701377
sage: hex(2281701377)                                                           
'0x88000001'
/// Wrapping multiplication of [Elem]  using Baby Bear field modulus
// Copied from the C++ implementation (fp.h)
const fn mul(lhs: u32, rhs: u32) -> u32 {// uint64_t o64 = uint64_t(a) * uint64_t(b);let mut o64: u64 = (lhs as u64).wrapping_mul(rhs as u64);// uint32_t low = -uint32_t(o64);let low: u32 = 0u32.wrapping_sub(o64 as u32);// uint32_t red = M * low;let red = M.wrapping_mul(low);// o64 += uint64_t(red) * uint64_t(P);o64 += (red as u64).wrapping_mul(P_U64);// uint32_t ret = o64 >> 32;let ret = (o64 >> 32) as u32;// return (ret >= P ? ret - P : ret);if ret >= P {ret - P} else {ret}
}/// Encode to Montgomery form from direct form.
const fn encode(a: u32) -> u32 {mul(R2, a)
}/// Decode from Montgomery form from direct form.
const fn decode(a: u32) -> u32 {mul(1, a)
}

RISC Zero系列博客

  • RISC0:Towards a Unified Compilation Framework for Zero Knowledge
  • Risc Zero ZKVM:zk-STARKs + RISC-V
  • 2023年 ZK Hack以及ZK Summit 9 亮点记
  • RISC Zero zkVM 白皮书
  • Risc0:使用Continunations来证明任意EVM交易
  • Zeth:首个Type 0 zkEVM
  • RISC Zero项目简介
  • RISC Zero zkVM性能指标
  • Continuations:扩展RISC Zero zkVM支持(无限)大计算
  • A summary on the FRI low degree test前2页导读
  • Reed-Solomon Codes及其与RISC Zero zkVM的关系
  • RISC Zero zkVM架构
  • RISC-V与RISC Zero zkVM的关系
  • 有限域的Fast Multiplication和Modular Reduction算法实现
  • RISC Zero的Bonsai证明服务
  • RISC Zero ZKP协议中的商多项式
  • FRI的Commit、Query以及FRI Batching内部机制
  • RISC Zero的手撕STARK
  • RISC Zero zkVM guest程序优化技巧 及其 与物理CPU的关键差异
  • ZK*FM:RISC Zero zkVM的形式化验证
  • Zirgen MLIR:RISC-Zero的ZK-circuits形式化验证
  • 以RISC Zero ZK Fraud Proof赋能Optimistic Rollups
  • zkSummit10 亮点记
  • 技术探秘:在RISC Zero中验证FHE——由隐藏到证明:FHE验证的ZK路径(1)
  • 技术探秘:在RISC Zero中验证FHE——RISC Zero应用的DevOps(2)
  • RISC Zero STARK证明系统时序图及规范
  • RISC Zero zkVM Host & Guest 101
  • RISC Zero zk-STARK证明系统代码解析

这篇关于RISC Zero的Babybear域 及其 扩域的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/563845

相关文章

uva 10061 How many zero's and how many digits ?(不同进制阶乘末尾几个0)+poj 1401

题意是求在base进制下的 n!的结果有几位数,末尾有几个0。 想起刚开始的时候做的一道10进制下的n阶乘末尾有几个零,以及之前有做过的一道n阶乘的位数。 当时都是在10进制下的。 10进制下的做法是: 1. n阶位数:直接 lg(n!)就是得数的位数。 2. n阶末尾0的个数:由于2 * 5 将会在得数中以0的形式存在,所以计算2或者计算5,由于因子中出现5必然出现2,所以直接一

SAM2POINT:以zero-shot且快速的方式将任何 3D 视频分割为视频

摘要 我们介绍 SAM2POINT,这是一种采用 Segment Anything Model 2 (SAM 2) 进行零样本和快速 3D 分割的初步探索。 SAM2POINT 将任何 3D 数据解释为一系列多向视频,并利用 SAM 2 进行 3D 空间分割,无需进一步训练或 2D-3D 投影。 我们的框架支持各种提示类型,包括 3D 点、框和掩模,并且可以泛化到不同的场景,例如 3D 对象、室

RISC-V (十二)系统调用

系统模式:用户态和内核态         当前的代码都是实现在machine模式下。 系统模式的切换         epc寄存器的值存放的是ecall指本身的地址 。 用ecall指令 系统调用的执行流程         mret这条指令会利用status的mpp值恢复到之前的特权级别。  蓝色的线表示涉及到权限切换。  系统调用的传参

RISC-V (十)任务同步和锁

并发与同步 并发:指多个控制流同时执行。         多处理器多任务。一般在多处理器架构下内存是共享的。           单处理器多任务,通过调度器,一会调度这个任务,一会调度下个任务。  共享一个处                                理器一个内存。                 单处理器任务+中断: 同步: 是为了保证在并发执行的环境中各个控制流可

Banana Pi BPI-F3 进迭时空RISC-V架构下,AI融合算力及其软件栈实践

RISC-V架构下,AI融合算力及其软件栈实践 面对未来大模型(LLM)、AIGC等智能化浪潮的挑战,进迭时空在RISC-V方向全面布局,通过精心设计的RISC-V DSA架构以及软硬一体的优化策略,将全力为未来打造高效且易用的AI算力解决方案。目前,进迭时空已经取得了显著的进展,成功推出了第一个版本的智算核(带AI融合算力的智算CPU)以及配套的AI软件栈。 软件栈简介 AI算法部署旨

《Zero-Shot Object Counting》CVPR2023

摘要 论文提出了一种新的计数设置,称为零样本对象计数(Zero-Shot Object Counting, ZSC),旨在测试时对任意类别的对象实例进行计数,而只需在测试时提供类别名称。现有的类无关计数方法需要人类标注的示例作为输入,这在许多实际应用中是不切实际的。ZSC方法不依赖于人类标注者,可以自动操作。研究者们提出了一种方法,可以从类别名称开始,准确识别出最佳的图像块(patches),用

class _ContiguousArrayStorage deallocated with non-zero retain count

Xcode报错 : Object 0x11c614000 of class _ContiguousArrayStorage deallocated with non-zero retain count 2. This object's deinit, or something called from it, may have created a strong reference to self w

零样本学习(zero-shot learning)——综述

-------本文内容来自对论文A Survey of Zero-Shot Learning: Settings, Methods, and Applications 的理解和整理,这里省去了众多的数学符号,以比较通俗的语言对零样本学习做一个简单的入门介绍,用词上可能缺乏一定的严谨性。一些图和公式直接来自于论文,并且省略了论文中讲的比较细的东西,如果感兴趣建议还是去通读论文 注1:为了方便,文中

RISC-V (八)定时器中断

​​​​​​​riscv中断的分类 Core local INTerrupt: CLINT CLINT编程接口-寄存器         mtime寄存器,由中断触发的时钟,按照固定频率计数。

【go-zero】win启动rpc服务报错 panic: context deadline exceeded

win启动rpc服务报错 panic: context deadline exceeded 问题来源 在使用go-zero生成的rpc项目后 启动不起来 原因 这个问题原因是wndows没有启动etcd 官方文档是删除了etcd配置 而我自己的测试yaml配置有etcd,所以需要启动etcd 下载安装好etcd后,在etcd的安装目录下,打开cmd,.\etcd 启动 然后