mirror of
https://github.com/logos-storage/plonky2.git
synced 2026-02-09 08:23:09 +00:00
Make some functions const (#1407)
This commit is contained in:
parent
7ac6bf2c66
commit
2d36559dad
@ -83,7 +83,7 @@ pub(crate) const NUM_TABLES: usize = Table::Memory as usize + 1;
|
||||
|
||||
impl Table {
|
||||
/// Returns all STARK table indices.
|
||||
pub(crate) fn all() -> [Self; NUM_TABLES] {
|
||||
pub(crate) const fn all() -> [Self; NUM_TABLES] {
|
||||
[
|
||||
Self::Arithmetic,
|
||||
Self::BytePacking,
|
||||
|
||||
@ -91,7 +91,7 @@ impl BinaryOperator {
|
||||
}
|
||||
|
||||
/// Maps a binary arithmetic operation to its associated flag column in the trace.
|
||||
pub(crate) fn row_filter(&self) -> usize {
|
||||
pub(crate) const fn row_filter(&self) -> usize {
|
||||
match self {
|
||||
BinaryOperator::Add => columns::IS_ADD,
|
||||
BinaryOperator::Mul => columns::IS_MUL,
|
||||
@ -130,7 +130,7 @@ impl TernaryOperator {
|
||||
}
|
||||
|
||||
/// Maps a ternary arithmetic operation to its associated flag column in the trace.
|
||||
pub(crate) fn row_filter(&self) -> usize {
|
||||
pub(crate) const fn row_filter(&self) -> usize {
|
||||
match self {
|
||||
TernaryOperator::AddMod => columns::IS_ADDMOD,
|
||||
TernaryOperator::MulMod => columns::IS_MULMOD,
|
||||
@ -208,7 +208,7 @@ impl Operation {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn range_check(
|
||||
pub(crate) const fn range_check(
|
||||
input0: U256,
|
||||
input1: U256,
|
||||
input2: U256,
|
||||
|
||||
@ -222,7 +222,7 @@ impl<F: RichField + Extendable<D>, const D: usize> BytePackingStark<F, D> {
|
||||
row
|
||||
}
|
||||
|
||||
fn generate_padding_row(&self) -> [F; NUM_COLUMNS] {
|
||||
const fn generate_padding_row(&self) -> [F; NUM_COLUMNS] {
|
||||
[F::ZERO; NUM_COLUMNS]
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ pub struct StarkConfig {
|
||||
impl StarkConfig {
|
||||
/// A typical configuration with a rate of 2, resulting in fast but large proofs.
|
||||
/// Targets ~100 bit conjectured security.
|
||||
pub fn standard_fast_config() -> Self {
|
||||
pub const fn standard_fast_config() -> Self {
|
||||
Self {
|
||||
security_bits: 100,
|
||||
num_challenges: 2,
|
||||
|
||||
@ -34,7 +34,7 @@ pub(crate) enum ContextMetadata {
|
||||
impl ContextMetadata {
|
||||
pub(crate) const COUNT: usize = 14;
|
||||
|
||||
pub(crate) fn all() -> [Self; Self::COUNT] {
|
||||
pub(crate) const fn all() -> [Self; Self::COUNT] {
|
||||
[
|
||||
Self::ParentContext,
|
||||
Self::ParentProgramCounter,
|
||||
@ -54,7 +54,7 @@ impl ContextMetadata {
|
||||
}
|
||||
|
||||
/// The variable name that gets passed into kernel assembly code.
|
||||
pub(crate) fn var_name(&self) -> &'static str {
|
||||
pub(crate) const fn var_name(&self) -> &'static str {
|
||||
match self {
|
||||
ContextMetadata::ParentContext => "CTX_METADATA_PARENT_CONTEXT",
|
||||
ContextMetadata::ParentProgramCounter => "CTX_METADATA_PARENT_PC",
|
||||
|
||||
@ -93,7 +93,7 @@ pub(crate) enum GlobalMetadata {
|
||||
impl GlobalMetadata {
|
||||
pub(crate) const COUNT: usize = 48;
|
||||
|
||||
pub(crate) fn all() -> [Self; Self::COUNT] {
|
||||
pub(crate) const fn all() -> [Self; Self::COUNT] {
|
||||
[
|
||||
Self::LargestContext,
|
||||
Self::MemorySize,
|
||||
@ -147,7 +147,7 @@ impl GlobalMetadata {
|
||||
}
|
||||
|
||||
/// The variable name that gets passed into kernel assembly code.
|
||||
pub(crate) fn var_name(&self) -> &'static str {
|
||||
pub(crate) const fn var_name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::LargestContext => "GLOBAL_METADATA_LARGEST_CONTEXT",
|
||||
Self::MemorySize => "GLOBAL_METADATA_MEMORY_SIZE",
|
||||
|
||||
@ -16,7 +16,7 @@ pub(crate) enum JournalEntry {
|
||||
impl JournalEntry {
|
||||
pub(crate) const COUNT: usize = 11;
|
||||
|
||||
pub(crate) fn all() -> [Self; Self::COUNT] {
|
||||
pub(crate) const fn all() -> [Self; Self::COUNT] {
|
||||
[
|
||||
Self::AccountLoaded,
|
||||
Self::AccountDestroyed,
|
||||
@ -33,7 +33,7 @@ impl JournalEntry {
|
||||
}
|
||||
|
||||
/// The variable name that gets passed into kernel assembly code.
|
||||
pub(crate) fn var_name(&self) -> &'static str {
|
||||
pub(crate) const fn var_name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::AccountLoaded => "JOURNAL_ENTRY_ACCOUNT_LOADED",
|
||||
Self::AccountDestroyed => "JOURNAL_ENTRY_ACCOUNT_DESTROYED",
|
||||
|
||||
@ -26,7 +26,7 @@ impl PartialTrieType {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn all() -> [Self; Self::COUNT] {
|
||||
pub(crate) const fn all() -> [Self; Self::COUNT] {
|
||||
[
|
||||
Self::Empty,
|
||||
Self::Hash,
|
||||
@ -37,7 +37,7 @@ impl PartialTrieType {
|
||||
}
|
||||
|
||||
/// The variable name that gets passed into kernel assembly code.
|
||||
pub(crate) fn var_name(&self) -> &'static str {
|
||||
pub(crate) const fn var_name(&self) -> &'static str {
|
||||
match self {
|
||||
Self::Empty => "MPT_NODE_EMPTY",
|
||||
Self::Hash => "MPT_NODE_HASH",
|
||||
|
||||
@ -28,7 +28,7 @@ pub(crate) enum NormalizedTxnField {
|
||||
impl NormalizedTxnField {
|
||||
pub(crate) const COUNT: usize = 16;
|
||||
|
||||
pub(crate) fn all() -> [Self; Self::COUNT] {
|
||||
pub(crate) const fn all() -> [Self; Self::COUNT] {
|
||||
[
|
||||
Self::ChainIdPresent,
|
||||
Self::ChainId,
|
||||
@ -50,7 +50,7 @@ impl NormalizedTxnField {
|
||||
}
|
||||
|
||||
/// The variable name that gets passed into kernel assembly code.
|
||||
pub(crate) fn var_name(&self) -> &'static str {
|
||||
pub(crate) const fn var_name(&self) -> &'static str {
|
||||
match self {
|
||||
NormalizedTxnField::ChainIdPresent => "TXN_FIELD_CHAIN_ID_PRESENT",
|
||||
NormalizedTxnField::ChainId => "TXN_FIELD_CHAIN_ID",
|
||||
|
||||
@ -26,12 +26,12 @@ fn cost_estimate_item(item: &Item) -> u32 {
|
||||
}
|
||||
}
|
||||
|
||||
fn cost_estimate_standard_op(_op: &str) -> u32 {
|
||||
const fn cost_estimate_standard_op(_op: &str) -> u32 {
|
||||
// For now we just treat any standard operation as having the same cost. This is pretty naive,
|
||||
// but should work fine with our current set of simple optimization rules.
|
||||
1
|
||||
}
|
||||
|
||||
fn cost_estimate_push(num_bytes: usize) -> u32 {
|
||||
const fn cost_estimate_push(num_bytes: usize) -> u32 {
|
||||
num_bytes as u32
|
||||
}
|
||||
|
||||
@ -912,7 +912,7 @@ impl<'a> Interpreter<'a> {
|
||||
self.generation_state.registers.gas_used = gas_used_val;
|
||||
}
|
||||
|
||||
pub(crate) fn stack_len(&self) -> usize {
|
||||
pub(crate) const fn stack_len(&self) -> usize {
|
||||
self.generation_state.registers.stack_len
|
||||
}
|
||||
|
||||
@ -924,7 +924,7 @@ impl<'a> Interpreter<'a> {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn is_kernel(&self) -> bool {
|
||||
pub(crate) const fn is_kernel(&self) -> bool {
|
||||
self.generation_state.registers.is_kernel
|
||||
}
|
||||
|
||||
@ -932,7 +932,7 @@ impl<'a> Interpreter<'a> {
|
||||
self.generation_state.registers.is_kernel = is_kernel
|
||||
}
|
||||
|
||||
pub(crate) fn context(&self) -> usize {
|
||||
pub(crate) const fn context(&self) -> usize {
|
||||
self.generation_state.registers.context
|
||||
}
|
||||
|
||||
|
||||
@ -31,7 +31,7 @@ pub(crate) fn u256_to_trimmed_be_bytes(u256: &U256) -> Vec<u8> {
|
||||
(0..num_bytes).rev().map(|i| u256.byte(i)).collect()
|
||||
}
|
||||
|
||||
pub(crate) fn u256_from_bool(b: bool) -> U256 {
|
||||
pub(crate) const fn u256_from_bool(b: bool) -> U256 {
|
||||
if b {
|
||||
U256::one()
|
||||
} else {
|
||||
|
||||
@ -11,13 +11,13 @@ use crate::cpu::membus::NUM_GP_CHANNELS;
|
||||
use crate::cpu::stack;
|
||||
use crate::memory::segments::Segment;
|
||||
|
||||
fn get_addr_load<T: Copy>(lv: &CpuColumnsView<T>) -> (T, T, T) {
|
||||
const fn get_addr_load<T: Copy>(lv: &CpuColumnsView<T>) -> (T, T, T) {
|
||||
let addr_context = lv.mem_channels[0].value[0];
|
||||
let addr_segment = lv.mem_channels[1].value[0];
|
||||
let addr_virtual = lv.mem_channels[2].value[0];
|
||||
(addr_context, addr_segment, addr_virtual)
|
||||
}
|
||||
fn get_addr_store<T: Copy>(lv: &CpuColumnsView<T>) -> (T, T, T) {
|
||||
const fn get_addr_store<T: Copy>(lv: &CpuColumnsView<T>) -> (T, T, T) {
|
||||
let addr_context = lv.mem_channels[1].value[0];
|
||||
let addr_segment = lv.mem_channels[2].value[0];
|
||||
let addr_virtual = lv.mem_channels[3].value[0];
|
||||
|
||||
@ -17,7 +17,7 @@ where
|
||||
}
|
||||
|
||||
impl<T: FieldExt> Curve<T> {
|
||||
pub(crate) fn unit() -> Self {
|
||||
pub(crate) const fn unit() -> Self {
|
||||
Curve {
|
||||
x: T::ZERO,
|
||||
y: T::ZERO,
|
||||
@ -237,7 +237,7 @@ pub(crate) fn bn_cord(p1: Curve<BN254>, p2: Curve<BN254>, q: Curve<Fp2<BN254>>)
|
||||
|
||||
/// The tangent and cord functions output sparse Fp12 elements.
|
||||
/// This map embeds the nonzero coefficients into an Fp12.
|
||||
pub(crate) fn bn_sparse_embed(g000: BN254, g01: Fp2<BN254>, g11: Fp2<BN254>) -> Fp12<BN254> {
|
||||
pub(crate) const fn bn_sparse_embed(g000: BN254, g01: Fp2<BN254>, g11: Fp2<BN254>) -> Fp12<BN254> {
|
||||
let g0 = Fp6 {
|
||||
t0: Fp2 {
|
||||
re: g000,
|
||||
|
||||
@ -298,7 +298,7 @@ fn parse_storage_value(value_rlp: &[u8]) -> Result<Vec<U256>, ProgramError> {
|
||||
Ok(vec![value])
|
||||
}
|
||||
|
||||
fn empty_nibbles() -> Nibbles {
|
||||
const fn empty_nibbles() -> Nibbles {
|
||||
Nibbles {
|
||||
count: 0,
|
||||
packed: U512::zero(),
|
||||
|
||||
@ -29,7 +29,7 @@ pub(crate) fn read_state_trie_value(slice: &[U256]) -> Result<AccountTrieRecord,
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn read_storage_trie_value(slice: &[U256]) -> U256 {
|
||||
pub(crate) const fn read_storage_trie_value(slice: &[U256]) -> U256 {
|
||||
slice[0]
|
||||
}
|
||||
|
||||
|
||||
@ -136,7 +136,7 @@ pub(crate) fn ctl_looking_memory<F: Field>(i: usize) -> Vec<Column<F>> {
|
||||
}
|
||||
|
||||
/// Returns the number of `KeccakSponge` tables looking into the `LogicStark`.
|
||||
pub(crate) fn num_logic_ctls() -> usize {
|
||||
pub(crate) const fn num_logic_ctls() -> usize {
|
||||
const U8S_PER_CTL: usize = 32;
|
||||
ceil_div_usize(KECCAK_RATE_BYTES, U8S_PER_CTL)
|
||||
}
|
||||
|
||||
@ -70,7 +70,7 @@ pub(crate) enum Segment {
|
||||
impl Segment {
|
||||
pub(crate) const COUNT: usize = 36;
|
||||
|
||||
pub(crate) fn all() -> [Self; Self::COUNT] {
|
||||
pub(crate) const fn all() -> [Self; Self::COUNT] {
|
||||
[
|
||||
Self::Code,
|
||||
Self::Stack,
|
||||
@ -112,7 +112,7 @@ impl Segment {
|
||||
}
|
||||
|
||||
/// The variable name that gets passed into kernel assembly code.
|
||||
pub(crate) fn var_name(&self) -> &'static str {
|
||||
pub(crate) const fn var_name(&self) -> &'static str {
|
||||
match self {
|
||||
Segment::Code => "SEGMENT_CODE",
|
||||
Segment::Stack => "SEGMENT_STACK",
|
||||
@ -153,7 +153,7 @@ impl Segment {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn bit_range(&self) -> usize {
|
||||
pub(crate) const fn bit_range(&self) -> usize {
|
||||
match self {
|
||||
Segment::Code => 8,
|
||||
Segment::Stack => 256,
|
||||
|
||||
@ -8,7 +8,7 @@ pub(crate) const G_LOW: u64 = 5;
|
||||
pub(crate) const G_MID: u64 = 8;
|
||||
pub(crate) const G_HIGH: u64 = 10;
|
||||
|
||||
pub(crate) fn gas_to_charge(op: Operation) -> u64 {
|
||||
pub(crate) const fn gas_to_charge(op: Operation) -> u64 {
|
||||
use crate::arithmetic::BinaryOperator::*;
|
||||
use crate::arithmetic::TernaryOperator::*;
|
||||
use crate::witness::operation::Operation::*;
|
||||
|
||||
@ -38,7 +38,7 @@ pub(crate) struct MemoryAddress {
|
||||
}
|
||||
|
||||
impl MemoryAddress {
|
||||
pub(crate) fn new(context: usize, segment: Segment, virt: usize) -> Self {
|
||||
pub(crate) const fn new(context: usize, segment: Segment, virt: usize) -> Self {
|
||||
Self {
|
||||
context,
|
||||
segment: segment as usize,
|
||||
@ -120,7 +120,11 @@ impl MemoryOp {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn new_dummy_read(address: MemoryAddress, timestamp: usize, value: U256) -> Self {
|
||||
pub(crate) const fn new_dummy_read(
|
||||
address: MemoryAddress,
|
||||
timestamp: usize,
|
||||
value: U256,
|
||||
) -> Self {
|
||||
Self {
|
||||
filter: false,
|
||||
timestamp,
|
||||
@ -130,7 +134,7 @@ impl MemoryOp {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn sorting_key(&self) -> (usize, usize, usize, usize) {
|
||||
pub(crate) const fn sorting_key(&self) -> (usize, usize, usize, usize) {
|
||||
(
|
||||
self.address.context,
|
||||
self.address.segment,
|
||||
|
||||
@ -20,7 +20,7 @@ pub struct RegistersState {
|
||||
}
|
||||
|
||||
impl RegistersState {
|
||||
pub(crate) fn code_context(&self) -> usize {
|
||||
pub(crate) const fn code_context(&self) -> usize {
|
||||
if self.is_kernel {
|
||||
KERNEL_CONTEXT
|
||||
} else {
|
||||
|
||||
@ -187,7 +187,7 @@ fn fill_op_flag<F: Field>(op: Operation, row: &mut CpuColumnsView<F>) {
|
||||
}
|
||||
|
||||
// Equal to the number of pops if an operation pops without pushing, and `None` otherwise.
|
||||
fn get_op_special_length(op: Operation) -> Option<usize> {
|
||||
const fn get_op_special_length(op: Operation) -> Option<usize> {
|
||||
let behavior_opt = match op {
|
||||
Operation::Push(0) | Operation::Pc => STACK_BEHAVIORS.pc_push0,
|
||||
Operation::Push(1..) => STACK_BEHAVIORS.push,
|
||||
@ -229,7 +229,7 @@ fn get_op_special_length(op: Operation) -> Option<usize> {
|
||||
|
||||
// These operations might trigger a stack overflow, typically those pushing without popping.
|
||||
// Kernel-only pushing instructions aren't considered; they can't overflow.
|
||||
fn might_overflow_op(op: Operation) -> bool {
|
||||
const fn might_overflow_op(op: Operation) -> bool {
|
||||
match op {
|
||||
Operation::Push(1..) => MIGHT_OVERFLOW.push,
|
||||
Operation::Dup(_) | Operation::Swap(_) => MIGHT_OVERFLOW.dup_swap,
|
||||
|
||||
@ -278,6 +278,7 @@ fn signed_tx() -> Vec<u8> {
|
||||
fn bloom_bytes() -> [u8; 256] {
|
||||
hex!("00000000000000000400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000008000000000000000000000000000000000040000000000000000000000000000000000000000000000014000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000002000000000000000000000000000000000000000000000042000000000000000000000000000000000000000000020000000000080000000000000000000000000000000000000000000000000000000000000000")
|
||||
}
|
||||
|
||||
fn bloom() -> [U256; 8] {
|
||||
let bloom = bloom_bytes()
|
||||
.chunks_exact(32)
|
||||
|
||||
@ -2,7 +2,7 @@ use crate::packable::Packable;
|
||||
use crate::packed::PackedField;
|
||||
use crate::types::Field;
|
||||
|
||||
fn pack_with_leftovers_split_point<P: PackedField>(slice: &[P::Scalar]) -> usize {
|
||||
const fn pack_with_leftovers_split_point<P: PackedField>(slice: &[P::Scalar]) -> usize {
|
||||
let n = slice.len();
|
||||
let n_leftover = n % P::WIDTH;
|
||||
n - n_leftover
|
||||
|
||||
@ -17,11 +17,11 @@ impl<F: OEF<D>, const D: usize> ExtensionAlgebra<F, D> {
|
||||
F::ONE.into()
|
||||
}
|
||||
|
||||
pub fn from_basefield_array(arr: [F; D]) -> Self {
|
||||
pub const fn from_basefield_array(arr: [F; D]) -> Self {
|
||||
Self(arr)
|
||||
}
|
||||
|
||||
pub fn to_basefield_array(self) -> [F; D] {
|
||||
pub const fn to_basefield_array(self) -> [F; D] {
|
||||
self.0
|
||||
}
|
||||
|
||||
|
||||
@ -114,14 +114,14 @@ impl Mul for QuinticExtension<GoldilocksField> {
|
||||
|
||||
/// Return `a`, `b` such that `a + b*2^128 = 3*(x + y*2^128)` with `a < 2^128` and `b < 2^32`.
|
||||
#[inline(always)]
|
||||
fn u160_times_3(x: u128, y: u32) -> (u128, u32) {
|
||||
const fn u160_times_3(x: u128, y: u32) -> (u128, u32) {
|
||||
let (s, cy) = x.overflowing_add(x << 1);
|
||||
(s, 3 * y + (x >> 127) as u32 + cy as u32)
|
||||
}
|
||||
|
||||
/// Return `a`, `b` such that `a + b*2^128 = 7*(x + y*2^128)` with `a < 2^128` and `b < 2^32`.
|
||||
#[inline(always)]
|
||||
fn u160_times_7(x: u128, y: u32) -> (u128, u32) {
|
||||
const fn u160_times_7(x: u128, y: u32) -> (u128, u32) {
|
||||
let (d, br) = (x << 3).overflowing_sub(x);
|
||||
// NB: subtracting the borrow can't underflow
|
||||
(d, 7 * y + (x >> (128 - 3)) as u32 - br as u32)
|
||||
|
||||
@ -381,7 +381,7 @@ unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 {
|
||||
|
||||
#[inline(always)]
|
||||
#[cfg(not(target_arch = "x86_64"))]
|
||||
unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 {
|
||||
const unsafe fn add_no_canonicalize_trashing_input(x: u64, y: u64) -> u64 {
|
||||
let (res_wrapped, carry) = x.overflowing_add(y);
|
||||
// Below cannot overflow unless the assumption if x + y < 2**64 + ORDER is incorrect.
|
||||
res_wrapped + EPSILON * (carry as u64)
|
||||
@ -415,7 +415,7 @@ fn reduce128(x: u128) -> GoldilocksField {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn split(x: u128) -> (u64, u64) {
|
||||
const fn split(x: u128) -> (u64, u64) {
|
||||
(x as u64, (x >> 64) as u64)
|
||||
}
|
||||
|
||||
|
||||
@ -51,7 +51,7 @@ impl FriConfig {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn num_cap_elements(&self) -> usize {
|
||||
pub const fn num_cap_elements(&self) -> usize {
|
||||
1 << self.cap_height
|
||||
}
|
||||
}
|
||||
@ -85,11 +85,11 @@ impl FriParams {
|
||||
self.reduction_arity_bits.iter().copied().max()
|
||||
}
|
||||
|
||||
pub fn lde_bits(&self) -> usize {
|
||||
pub const fn lde_bits(&self) -> usize {
|
||||
self.degree_bits + self.config.rate_bits
|
||||
}
|
||||
|
||||
pub fn lde_size(&self) -> usize {
|
||||
pub const fn lde_size(&self) -> usize {
|
||||
1 << self.lde_bits()
|
||||
}
|
||||
|
||||
|
||||
@ -29,28 +29,28 @@ pub struct ArithmeticGate {
|
||||
}
|
||||
|
||||
impl ArithmeticGate {
|
||||
pub fn new_from_config(config: &CircuitConfig) -> Self {
|
||||
pub const fn new_from_config(config: &CircuitConfig) -> Self {
|
||||
Self {
|
||||
num_ops: Self::num_ops(config),
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the maximum number of operations that can fit in one gate for the given config.
|
||||
pub(crate) fn num_ops(config: &CircuitConfig) -> usize {
|
||||
pub(crate) const fn num_ops(config: &CircuitConfig) -> usize {
|
||||
let wires_per_op = 4;
|
||||
config.num_routed_wires / wires_per_op
|
||||
}
|
||||
|
||||
pub fn wire_ith_multiplicand_0(i: usize) -> usize {
|
||||
pub const fn wire_ith_multiplicand_0(i: usize) -> usize {
|
||||
4 * i
|
||||
}
|
||||
pub fn wire_ith_multiplicand_1(i: usize) -> usize {
|
||||
pub const fn wire_ith_multiplicand_1(i: usize) -> usize {
|
||||
4 * i + 1
|
||||
}
|
||||
pub fn wire_ith_addend(i: usize) -> usize {
|
||||
pub const fn wire_ith_addend(i: usize) -> usize {
|
||||
4 * i + 2
|
||||
}
|
||||
pub fn wire_ith_output(i: usize) -> usize {
|
||||
pub const fn wire_ith_output(i: usize) -> usize {
|
||||
4 * i + 3
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,28 +25,28 @@ pub struct ArithmeticExtensionGate<const D: usize> {
|
||||
}
|
||||
|
||||
impl<const D: usize> ArithmeticExtensionGate<D> {
|
||||
pub fn new_from_config(config: &CircuitConfig) -> Self {
|
||||
pub const fn new_from_config(config: &CircuitConfig) -> Self {
|
||||
Self {
|
||||
num_ops: Self::num_ops(config),
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the maximum number of operations that can fit in one gate for the given config.
|
||||
pub(crate) fn num_ops(config: &CircuitConfig) -> usize {
|
||||
pub(crate) const fn num_ops(config: &CircuitConfig) -> usize {
|
||||
let wires_per_op = 4 * D;
|
||||
config.num_routed_wires / wires_per_op
|
||||
}
|
||||
|
||||
pub fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
|
||||
4 * D * i..4 * D * i + D
|
||||
}
|
||||
pub fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
|
||||
4 * D * i + D..4 * D * i + 2 * D
|
||||
}
|
||||
pub fn wires_ith_addend(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_addend(i: usize) -> Range<usize> {
|
||||
4 * D * i + 2 * D..4 * D * i + 3 * D
|
||||
}
|
||||
pub fn wires_ith_output(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_output(i: usize) -> Range<usize> {
|
||||
4 * D * i + 3 * D..4 * D * i + 4 * D
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ pub struct BaseSumGate<const B: usize> {
|
||||
}
|
||||
|
||||
impl<const B: usize> BaseSumGate<B> {
|
||||
pub fn new(num_limbs: usize) -> Self {
|
||||
pub const fn new(num_limbs: usize) -> Self {
|
||||
Self { num_limbs }
|
||||
}
|
||||
|
||||
@ -45,7 +45,7 @@ impl<const B: usize> BaseSumGate<B> {
|
||||
pub const START_LIMBS: usize = 1;
|
||||
|
||||
/// Returns the index of the `i`th limb wire.
|
||||
pub fn limbs(&self) -> Range<usize> {
|
||||
pub const fn limbs(&self) -> Range<usize> {
|
||||
Self::START_LIMBS..Self::START_LIMBS + self.num_limbs
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ pub struct ConstantGate {
|
||||
}
|
||||
|
||||
impl ConstantGate {
|
||||
pub fn new(num_consts: usize) -> Self {
|
||||
pub const fn new(num_consts: usize) -> Self {
|
||||
Self { num_consts }
|
||||
}
|
||||
|
||||
|
||||
@ -86,16 +86,16 @@ impl<F: RichField + Extendable<D>, const D: usize> CosetInterpolationGate<F, D>
|
||||
}
|
||||
}
|
||||
|
||||
fn num_points(&self) -> usize {
|
||||
const fn num_points(&self) -> usize {
|
||||
1 << self.subgroup_bits
|
||||
}
|
||||
|
||||
/// Wire index of the coset shift.
|
||||
pub(crate) fn wire_shift(&self) -> usize {
|
||||
pub(crate) const fn wire_shift(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
fn start_values(&self) -> usize {
|
||||
const fn start_values(&self) -> usize {
|
||||
1
|
||||
}
|
||||
|
||||
@ -106,31 +106,31 @@ impl<F: RichField + Extendable<D>, const D: usize> CosetInterpolationGate<F, D>
|
||||
start..start + D
|
||||
}
|
||||
|
||||
fn start_evaluation_point(&self) -> usize {
|
||||
const fn start_evaluation_point(&self) -> usize {
|
||||
self.start_values() + self.num_points() * D
|
||||
}
|
||||
|
||||
/// Wire indices of the point to evaluate the interpolant at.
|
||||
pub(crate) fn wires_evaluation_point(&self) -> Range<usize> {
|
||||
pub(crate) const fn wires_evaluation_point(&self) -> Range<usize> {
|
||||
let start = self.start_evaluation_point();
|
||||
start..start + D
|
||||
}
|
||||
|
||||
fn start_evaluation_value(&self) -> usize {
|
||||
const fn start_evaluation_value(&self) -> usize {
|
||||
self.start_evaluation_point() + D
|
||||
}
|
||||
|
||||
/// Wire indices of the interpolated value.
|
||||
pub(crate) fn wires_evaluation_value(&self) -> Range<usize> {
|
||||
pub(crate) const fn wires_evaluation_value(&self) -> Range<usize> {
|
||||
let start = self.start_evaluation_value();
|
||||
start..start + D
|
||||
}
|
||||
|
||||
fn start_intermediates(&self) -> usize {
|
||||
const fn start_intermediates(&self) -> usize {
|
||||
self.start_evaluation_value() + D
|
||||
}
|
||||
|
||||
pub fn num_routed_wires(&self) -> usize {
|
||||
pub const fn num_routed_wires(&self) -> usize {
|
||||
self.start_intermediates()
|
||||
}
|
||||
|
||||
|
||||
@ -32,7 +32,7 @@ pub struct ExponentiationGate<F: RichField + Extendable<D>, const D: usize> {
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
||||
pub fn new(num_power_bits: usize) -> Self {
|
||||
pub const fn new(num_power_bits: usize) -> Self {
|
||||
Self {
|
||||
num_power_bits,
|
||||
_phantom: PhantomData,
|
||||
@ -51,7 +51,7 @@ impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
||||
max_for_routed_wires.min(max_for_wires)
|
||||
}
|
||||
|
||||
pub fn wire_base(&self) -> usize {
|
||||
pub const fn wire_base(&self) -> usize {
|
||||
0
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ impl<F: RichField + Extendable<D>, const D: usize> ExponentiationGate<F, D> {
|
||||
1 + i
|
||||
}
|
||||
|
||||
pub fn wire_output(&self) -> usize {
|
||||
pub const fn wire_output(&self) -> usize {
|
||||
1 + self.num_power_bits
|
||||
}
|
||||
|
||||
|
||||
@ -51,16 +51,16 @@ impl LookupGate {
|
||||
lut_hash: keccak(table_bytes).0,
|
||||
}
|
||||
}
|
||||
pub(crate) fn num_slots(config: &CircuitConfig) -> usize {
|
||||
pub(crate) const fn num_slots(config: &CircuitConfig) -> usize {
|
||||
let wires_per_lookup = 2;
|
||||
config.num_routed_wires / wires_per_lookup
|
||||
}
|
||||
|
||||
pub fn wire_ith_looking_inp(i: usize) -> usize {
|
||||
pub const fn wire_ith_looking_inp(i: usize) -> usize {
|
||||
2 * i
|
||||
}
|
||||
|
||||
pub fn wire_ith_looking_out(i: usize) -> usize {
|
||||
pub const fn wire_ith_looking_out(i: usize) -> usize {
|
||||
2 * i + 1
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,23 +56,23 @@ impl LookupTableGate {
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn num_slots(config: &CircuitConfig) -> usize {
|
||||
pub(crate) const fn num_slots(config: &CircuitConfig) -> usize {
|
||||
let wires_per_entry = 3;
|
||||
config.num_routed_wires / wires_per_entry
|
||||
}
|
||||
|
||||
/// Wire for the looked input.
|
||||
pub fn wire_ith_looked_inp(i: usize) -> usize {
|
||||
pub const fn wire_ith_looked_inp(i: usize) -> usize {
|
||||
3 * i
|
||||
}
|
||||
|
||||
// Wire for the looked output.
|
||||
pub fn wire_ith_looked_out(i: usize) -> usize {
|
||||
pub const fn wire_ith_looked_out(i: usize) -> usize {
|
||||
3 * i + 1
|
||||
}
|
||||
|
||||
/// Wire for the multiplicity. Set after the trace has been generated.
|
||||
pub fn wire_ith_multiplicity(i: usize) -> usize {
|
||||
pub const fn wire_ith_multiplicity(i: usize) -> usize {
|
||||
3 * i + 2
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,25 +25,25 @@ pub struct MulExtensionGate<const D: usize> {
|
||||
}
|
||||
|
||||
impl<const D: usize> MulExtensionGate<D> {
|
||||
pub fn new_from_config(config: &CircuitConfig) -> Self {
|
||||
pub const fn new_from_config(config: &CircuitConfig) -> Self {
|
||||
Self {
|
||||
num_ops: Self::num_ops(config),
|
||||
}
|
||||
}
|
||||
|
||||
/// Determine the maximum number of operations that can fit in one gate for the given config.
|
||||
pub(crate) fn num_ops(config: &CircuitConfig) -> usize {
|
||||
pub(crate) const fn num_ops(config: &CircuitConfig) -> usize {
|
||||
let wires_per_op = 3 * D;
|
||||
config.num_routed_wires / wires_per_op
|
||||
}
|
||||
|
||||
pub fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_multiplicand_0(i: usize) -> Range<usize> {
|
||||
3 * D * i..3 * D * i + D
|
||||
}
|
||||
pub fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_multiplicand_1(i: usize) -> Range<usize> {
|
||||
3 * D * i + D..3 * D * i + 2 * D
|
||||
}
|
||||
pub fn wires_ith_output(i: usize) -> Range<usize> {
|
||||
pub const fn wires_ith_output(i: usize) -> Range<usize> {
|
||||
3 * D * i + 2 * D..3 * D * i + 3 * D
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,17 +30,17 @@ use crate::util::serialization::{Buffer, IoResult, Read, Write};
|
||||
pub struct PoseidonGate<F: RichField + Extendable<D>, const D: usize>(PhantomData<F>);
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {
|
||||
pub fn new() -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Self(PhantomData)
|
||||
}
|
||||
|
||||
/// The wire index for the `i`th input to the permutation.
|
||||
pub fn wire_input(i: usize) -> usize {
|
||||
pub const fn wire_input(i: usize) -> usize {
|
||||
i
|
||||
}
|
||||
|
||||
/// The wire index for the `i`th output to the permutation.
|
||||
pub fn wire_output(i: usize) -> usize {
|
||||
pub const fn wire_output(i: usize) -> usize {
|
||||
SPONGE_WIDTH + i
|
||||
}
|
||||
|
||||
@ -90,7 +90,7 @@ impl<F: RichField + Extendable<D>, const D: usize> PoseidonGate<F, D> {
|
||||
}
|
||||
|
||||
/// End of wire indices, exclusive.
|
||||
fn end() -> usize {
|
||||
const fn end() -> usize {
|
||||
Self::START_FULL_1 + SPONGE_WIDTH * poseidon::HALF_N_FULL_ROUNDS
|
||||
}
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ use crate::util::serialization::{Buffer, IoResult, Read, Write};
|
||||
pub struct PoseidonMdsGate<F: RichField + Extendable<D> + Poseidon, const D: usize>(PhantomData<F>);
|
||||
|
||||
impl<F: RichField + Extendable<D> + Poseidon, const D: usize> PoseidonMdsGate<F, D> {
|
||||
pub fn new() -> Self {
|
||||
pub const fn new() -> Self {
|
||||
Self(PhantomData)
|
||||
}
|
||||
|
||||
|
||||
@ -22,7 +22,7 @@ use crate::util::serialization::{Buffer, IoResult};
|
||||
pub struct PublicInputGate;
|
||||
|
||||
impl PublicInputGate {
|
||||
pub fn wires_public_inputs_hash() -> Range<usize> {
|
||||
pub const fn wires_public_inputs_hash() -> Range<usize> {
|
||||
0..4
|
||||
}
|
||||
}
|
||||
|
||||
@ -41,7 +41,7 @@ pub struct RandomAccessGate<F: RichField + Extendable<D>, const D: usize> {
|
||||
}
|
||||
|
||||
impl<F: RichField + Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
||||
fn new(num_copies: usize, bits: usize, num_extra_constants: usize) -> Self {
|
||||
const fn new(num_copies: usize, bits: usize, num_extra_constants: usize) -> Self {
|
||||
Self {
|
||||
bits,
|
||||
num_copies,
|
||||
@ -71,7 +71,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
||||
}
|
||||
|
||||
/// Length of the list being accessed.
|
||||
fn vec_size(&self) -> usize {
|
||||
const fn vec_size(&self) -> usize {
|
||||
1 << self.bits
|
||||
}
|
||||
|
||||
@ -94,7 +94,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
||||
(2 + self.vec_size()) * copy + 2 + i
|
||||
}
|
||||
|
||||
fn start_extra_constants(&self) -> usize {
|
||||
const fn start_extra_constants(&self) -> usize {
|
||||
(2 + self.vec_size()) * self.num_copies
|
||||
}
|
||||
|
||||
@ -104,7 +104,7 @@ impl<F: RichField + Extendable<D>, const D: usize> RandomAccessGate<F, D> {
|
||||
}
|
||||
|
||||
/// All above wires are routed.
|
||||
pub fn num_routed_wires(&self) -> usize {
|
||||
pub const fn num_routed_wires(&self) -> usize {
|
||||
self.start_extra_constants() + self.num_extra_constants
|
||||
}
|
||||
|
||||
|
||||
@ -23,7 +23,7 @@ pub struct ReducingGate<const D: usize> {
|
||||
}
|
||||
|
||||
impl<const D: usize> ReducingGate<D> {
|
||||
pub fn new(num_coeffs: usize) -> Self {
|
||||
pub const fn new(num_coeffs: usize) -> Self {
|
||||
Self { num_coeffs }
|
||||
}
|
||||
|
||||
@ -31,23 +31,23 @@ impl<const D: usize> ReducingGate<D> {
|
||||
(num_routed_wires - 3 * D).min((num_wires - 2 * D) / (D + 1))
|
||||
}
|
||||
|
||||
pub fn wires_output() -> Range<usize> {
|
||||
pub const fn wires_output() -> Range<usize> {
|
||||
0..D
|
||||
}
|
||||
pub fn wires_alpha() -> Range<usize> {
|
||||
pub const fn wires_alpha() -> Range<usize> {
|
||||
D..2 * D
|
||||
}
|
||||
pub fn wires_old_acc() -> Range<usize> {
|
||||
pub const fn wires_old_acc() -> Range<usize> {
|
||||
2 * D..3 * D
|
||||
}
|
||||
const START_COEFFS: usize = 3 * D;
|
||||
pub fn wires_coeffs(&self) -> Range<usize> {
|
||||
pub const fn wires_coeffs(&self) -> Range<usize> {
|
||||
Self::START_COEFFS..Self::START_COEFFS + self.num_coeffs
|
||||
}
|
||||
fn start_accs(&self) -> usize {
|
||||
const fn start_accs(&self) -> usize {
|
||||
Self::START_COEFFS + self.num_coeffs
|
||||
}
|
||||
fn wires_accs(&self, i: usize) -> Range<usize> {
|
||||
const fn wires_accs(&self, i: usize) -> Range<usize> {
|
||||
if i == self.num_coeffs - 1 {
|
||||
// The last accumulator is the output.
|
||||
return Self::wires_output();
|
||||
|
||||
@ -23,7 +23,7 @@ pub struct ReducingExtensionGate<const D: usize> {
|
||||
}
|
||||
|
||||
impl<const D: usize> ReducingExtensionGate<D> {
|
||||
pub fn new(num_coeffs: usize) -> Self {
|
||||
pub const fn new(num_coeffs: usize) -> Self {
|
||||
Self { num_coeffs }
|
||||
}
|
||||
|
||||
@ -33,20 +33,20 @@ impl<const D: usize> ReducingExtensionGate<D> {
|
||||
((num_routed_wires - 3 * D) / D).min((num_wires - 2 * D) / (D * 2))
|
||||
}
|
||||
|
||||
pub fn wires_output() -> Range<usize> {
|
||||
pub const fn wires_output() -> Range<usize> {
|
||||
0..D
|
||||
}
|
||||
pub fn wires_alpha() -> Range<usize> {
|
||||
pub const fn wires_alpha() -> Range<usize> {
|
||||
D..2 * D
|
||||
}
|
||||
pub fn wires_old_acc() -> Range<usize> {
|
||||
pub const fn wires_old_acc() -> Range<usize> {
|
||||
2 * D..3 * D
|
||||
}
|
||||
const START_COEFFS: usize = 3 * D;
|
||||
pub fn wires_coeff(i: usize) -> Range<usize> {
|
||||
pub const fn wires_coeff(i: usize) -> Range<usize> {
|
||||
Self::START_COEFFS + i * D..Self::START_COEFFS + (i + 1) * D
|
||||
}
|
||||
fn start_accs(&self) -> usize {
|
||||
const fn start_accs(&self) -> usize {
|
||||
Self::START_COEFFS + self.num_coeffs * D
|
||||
}
|
||||
fn wires_accs(&self, i: usize) -> Range<usize> {
|
||||
|
||||
@ -36,7 +36,7 @@ pub const N_ROUNDS: usize = N_FULL_ROUNDS_TOTAL + N_PARTIAL_ROUNDS;
|
||||
const MAX_WIDTH: usize = 12; // we only have width 8 and 12, and 12 is bigger. :)
|
||||
|
||||
#[inline(always)]
|
||||
fn add_u160_u128((x_lo, x_hi): (u128, u32), y: u128) -> (u128, u32) {
|
||||
const fn add_u160_u128((x_lo, x_hi): (u128, u32), y: u128) -> (u128, u32) {
|
||||
let (res_lo, over) = x_lo.overflowing_add(y);
|
||||
let res_hi = x_hi + (over as u32);
|
||||
(res_lo, res_hi)
|
||||
|
||||
@ -315,7 +315,7 @@ mod poseidon12_mds {
|
||||
|
||||
/// Split 3 x 4 FFT-based MDS vector-multiplication with the Poseidon circulant MDS matrix.
|
||||
#[inline(always)]
|
||||
pub(crate) fn mds_multiply_freq(state: [u64; 12]) -> [u64; 12] {
|
||||
pub(crate) const fn mds_multiply_freq(state: [u64; 12]) -> [u64; 12] {
|
||||
let [s0, s1, s2, s3, s4, s5, s6, s7, s8, s9, s10, s11] = state;
|
||||
|
||||
let (u0, u1, u2) = fft4_real([s0, s3, s6, s9]);
|
||||
@ -343,7 +343,7 @@ mod poseidon12_mds {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn block1(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
|
||||
const fn block1(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
|
||||
let [x0, x1, x2] = x;
|
||||
let [y0, y1, y2] = y;
|
||||
let z0 = x0 * y0 + x1 * y2 + x2 * y1;
|
||||
@ -354,7 +354,7 @@ mod poseidon12_mds {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn block2(x: [(i64, i64); 3], y: [(i64, i64); 3]) -> [(i64, i64); 3] {
|
||||
const fn block2(x: [(i64, i64); 3], y: [(i64, i64); 3]) -> [(i64, i64); 3] {
|
||||
let [(x0r, x0i), (x1r, x1i), (x2r, x2i)] = x;
|
||||
let [(y0r, y0i), (y1r, y1i), (y2r, y2i)] = y;
|
||||
let x0s = x0r + x0i;
|
||||
@ -392,7 +392,7 @@ mod poseidon12_mds {
|
||||
}
|
||||
|
||||
#[inline(always)]
|
||||
fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
|
||||
const fn block3(x: [i64; 3], y: [i64; 3]) -> [i64; 3] {
|
||||
let [x0, x1, x2] = x;
|
||||
let [y0, y1, y2] = y;
|
||||
let z0 = x0 * y0 - x1 * y2 - x2 * y1;
|
||||
@ -404,20 +404,20 @@ mod poseidon12_mds {
|
||||
|
||||
/// Real 2-FFT over u64 integers.
|
||||
#[inline(always)]
|
||||
pub(crate) fn fft2_real(x: [u64; 2]) -> [i64; 2] {
|
||||
pub(crate) const fn fft2_real(x: [u64; 2]) -> [i64; 2] {
|
||||
[(x[0] as i64 + x[1] as i64), (x[0] as i64 - x[1] as i64)]
|
||||
}
|
||||
|
||||
/// Real 2-iFFT over u64 integers.
|
||||
/// Division by two to complete the inverse FFT is not performed here.
|
||||
#[inline(always)]
|
||||
pub(crate) fn ifft2_real_unreduced(y: [i64; 2]) -> [u64; 2] {
|
||||
pub(crate) const fn ifft2_real_unreduced(y: [i64; 2]) -> [u64; 2] {
|
||||
[(y[0] + y[1]) as u64, (y[0] - y[1]) as u64]
|
||||
}
|
||||
|
||||
/// Real 4-FFT over u64 integers.
|
||||
#[inline(always)]
|
||||
pub(crate) fn fft4_real(x: [u64; 4]) -> (i64, (i64, i64), i64) {
|
||||
pub(crate) const fn fft4_real(x: [u64; 4]) -> (i64, (i64, i64), i64) {
|
||||
let [z0, z2] = fft2_real([x[0], x[2]]);
|
||||
let [z1, z3] = fft2_real([x[1], x[3]]);
|
||||
let y0 = z0 + z1;
|
||||
@ -429,7 +429,7 @@ mod poseidon12_mds {
|
||||
/// Real 4-iFFT over u64 integers.
|
||||
/// Division by four to complete the inverse FFT is not performed here.
|
||||
#[inline(always)]
|
||||
pub(crate) fn ifft4_real_unreduced(y: (i64, (i64, i64), i64)) -> [u64; 4] {
|
||||
pub(crate) const fn ifft4_real_unreduced(y: (i64, (i64, i64), i64)) -> [u64; 4] {
|
||||
let z0 = y.0 + y.2;
|
||||
let z1 = y.0 - y.2;
|
||||
let z2 = y.1 .0;
|
||||
|
||||
@ -19,7 +19,7 @@ impl<const D: usize> Default for ExtensionTarget<D> {
|
||||
}
|
||||
|
||||
impl<const D: usize> ExtensionTarget<D> {
|
||||
pub fn to_target_array(&self) -> [Target; D] {
|
||||
pub const fn to_target_array(&self) -> [Target; D] {
|
||||
self.0
|
||||
}
|
||||
|
||||
@ -77,7 +77,7 @@ impl<const D: usize> TryFrom<Vec<Target>> for ExtensionTarget<D> {
|
||||
pub struct ExtensionAlgebraTarget<const D: usize>(pub [ExtensionTarget<D>; D]);
|
||||
|
||||
impl<const D: usize> ExtensionAlgebraTarget<D> {
|
||||
pub fn to_ext_target_array(&self) -> [ExtensionTarget<D>; D] {
|
||||
pub const fn to_ext_target_array(&self) -> [ExtensionTarget<D>; D] {
|
||||
self.0
|
||||
}
|
||||
}
|
||||
|
||||
@ -26,11 +26,11 @@ impl Default for Target {
|
||||
}
|
||||
|
||||
impl Target {
|
||||
pub fn wire(row: usize, column: usize) -> Self {
|
||||
pub const fn wire(row: usize, column: usize) -> Self {
|
||||
Self::Wire(Wire { row, column })
|
||||
}
|
||||
|
||||
pub fn is_routable(&self, config: &CircuitConfig) -> bool {
|
||||
pub const fn is_routable(&self, config: &CircuitConfig) -> bool {
|
||||
match self {
|
||||
Target::Wire(wire) => wire.is_routable(config),
|
||||
Target::VirtualTarget { .. } => true,
|
||||
@ -49,7 +49,7 @@ impl Target {
|
||||
}
|
||||
|
||||
/// Conversion to an `ExtensionTarget`.
|
||||
pub fn to_ext_target<const D: usize>(self, zero: Self) -> ExtensionTarget<D> {
|
||||
pub const fn to_ext_target<const D: usize>(self, zero: Self) -> ExtensionTarget<D> {
|
||||
let mut arr = [zero; D];
|
||||
arr[0] = self;
|
||||
ExtensionTarget(arr)
|
||||
@ -66,7 +66,7 @@ pub struct BoolTarget {
|
||||
}
|
||||
|
||||
impl BoolTarget {
|
||||
pub fn new_unsafe(target: Target) -> BoolTarget {
|
||||
pub const fn new_unsafe(target: Target) -> BoolTarget {
|
||||
BoolTarget {
|
||||
target,
|
||||
_private: (),
|
||||
|
||||
@ -15,7 +15,7 @@ pub struct Wire {
|
||||
}
|
||||
|
||||
impl Wire {
|
||||
pub fn is_routable(&self, config: &CircuitConfig) -> bool {
|
||||
pub const fn is_routable(&self, config: &CircuitConfig) -> bool {
|
||||
self.column < config.num_routed_wires
|
||||
}
|
||||
|
||||
|
||||
@ -704,7 +704,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
|
||||
/// The number of (base field) `arithmetic` operations that can be performed in a single gate.
|
||||
pub(crate) fn num_base_arithmetic_ops_per_gate(&self) -> usize {
|
||||
pub(crate) const fn num_base_arithmetic_ops_per_gate(&self) -> usize {
|
||||
if self.config.use_base_arithmetic_gate {
|
||||
ArithmeticGate::new_from_config(&self.config).num_ops
|
||||
} else {
|
||||
@ -713,7 +713,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CircuitBuilder<F, D> {
|
||||
}
|
||||
|
||||
/// The number of `arithmetic_extension` operations that can be performed in a single gate.
|
||||
pub(crate) fn num_ext_arithmetic_ops_per_gate(&self) -> usize {
|
||||
pub(crate) const fn num_ext_arithmetic_ops_per_gate(&self) -> usize {
|
||||
ArithmeticExtensionGate::<D>::new_from_config(&self.config).num_ops
|
||||
}
|
||||
|
||||
|
||||
@ -64,12 +64,12 @@ impl Default for CircuitConfig {
|
||||
}
|
||||
|
||||
impl CircuitConfig {
|
||||
pub fn num_advice_wires(&self) -> usize {
|
||||
pub const fn num_advice_wires(&self) -> usize {
|
||||
self.num_wires - self.num_routed_wires
|
||||
}
|
||||
|
||||
/// A typical recursion config, without zero-knowledge, targeting ~100 bit security.
|
||||
pub fn standard_recursion_config() -> Self {
|
||||
pub const fn standard_recursion_config() -> Self {
|
||||
Self {
|
||||
num_wires: 135,
|
||||
num_routed_wires: 80,
|
||||
@ -442,11 +442,11 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
|
||||
self.fri_params.degree_bits
|
||||
}
|
||||
|
||||
pub fn degree(&self) -> usize {
|
||||
pub const fn degree(&self) -> usize {
|
||||
1 << self.degree_bits()
|
||||
}
|
||||
|
||||
pub fn lde_size(&self) -> usize {
|
||||
pub const fn lde_size(&self) -> usize {
|
||||
self.fri_params.lde_size()
|
||||
}
|
||||
|
||||
@ -462,37 +462,37 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
|
||||
.expect("No gates?")
|
||||
}
|
||||
|
||||
pub fn quotient_degree(&self) -> usize {
|
||||
pub const fn quotient_degree(&self) -> usize {
|
||||
self.quotient_degree_factor * self.degree()
|
||||
}
|
||||
|
||||
/// Range of the constants polynomials in the `constants_sigmas_commitment`.
|
||||
pub fn constants_range(&self) -> Range<usize> {
|
||||
pub const fn constants_range(&self) -> Range<usize> {
|
||||
0..self.num_constants
|
||||
}
|
||||
|
||||
/// Range of the sigma polynomials in the `constants_sigmas_commitment`.
|
||||
pub fn sigmas_range(&self) -> Range<usize> {
|
||||
pub const fn sigmas_range(&self) -> Range<usize> {
|
||||
self.num_constants..self.num_constants + self.config.num_routed_wires
|
||||
}
|
||||
|
||||
/// Range of the `z`s polynomials in the `zs_partial_products_commitment`.
|
||||
pub fn zs_range(&self) -> Range<usize> {
|
||||
pub const fn zs_range(&self) -> Range<usize> {
|
||||
0..self.config.num_challenges
|
||||
}
|
||||
|
||||
/// Range of the partial products polynomials in the `zs_partial_products_lookup_commitment`.
|
||||
pub fn partial_products_range(&self) -> Range<usize> {
|
||||
pub const fn partial_products_range(&self) -> Range<usize> {
|
||||
self.config.num_challenges..(self.num_partial_products + 1) * self.config.num_challenges
|
||||
}
|
||||
|
||||
/// Range of lookup polynomials in the `zs_partial_products_lookup_commitment`.
|
||||
pub fn lookup_range(&self) -> RangeFrom<usize> {
|
||||
pub const fn lookup_range(&self) -> RangeFrom<usize> {
|
||||
self.num_zs_partial_products_polys()..
|
||||
}
|
||||
|
||||
/// Range of lookup polynomials needed for evaluation at `g * zeta`.
|
||||
pub fn next_lookup_range(&self, i: usize) -> Range<usize> {
|
||||
pub const fn next_lookup_range(&self, i: usize) -> Range<usize> {
|
||||
self.num_zs_partial_products_polys() + i * self.num_lookup_polys
|
||||
..self.num_zs_partial_products_polys() + i * self.num_lookup_polys + 2
|
||||
}
|
||||
@ -573,7 +573,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn num_preprocessed_polys(&self) -> usize {
|
||||
pub(crate) const fn num_preprocessed_polys(&self) -> usize {
|
||||
self.sigmas_range().end
|
||||
}
|
||||
|
||||
@ -589,12 +589,12 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn num_zs_partial_products_polys(&self) -> usize {
|
||||
pub(crate) const fn num_zs_partial_products_polys(&self) -> usize {
|
||||
self.config.num_challenges * (1 + self.num_partial_products)
|
||||
}
|
||||
|
||||
/// Returns the total number of lookup polynomials.
|
||||
pub(crate) fn num_all_lookup_polys(&self) -> usize {
|
||||
pub(crate) const fn num_all_lookup_polys(&self) -> usize {
|
||||
self.config.num_challenges * self.num_lookup_polys
|
||||
}
|
||||
fn fri_zs_polys(&self) -> Vec<FriPolynomialInfo> {
|
||||
@ -618,7 +618,7 @@ impl<F: RichField + Extendable<D>, const D: usize> CommonCircuitData<F, D> {
|
||||
..self.num_zs_partial_products_polys() + self.num_all_lookup_polys(),
|
||||
)
|
||||
}
|
||||
pub(crate) fn num_quotient_polys(&self) -> usize {
|
||||
pub(crate) const fn num_quotient_polys(&self) -> usize {
|
||||
self.config.num_challenges * self.quotient_degree_factor
|
||||
}
|
||||
|
||||
|
||||
@ -18,7 +18,7 @@ impl From<(Target, Target)> for CopyConstraint {
|
||||
}
|
||||
|
||||
impl CopyConstraint {
|
||||
pub fn new(pair: (Target, Target), name: String) -> Self {
|
||||
pub const fn new(pair: (Target, Target), name: String) -> Self {
|
||||
Self { pair, name }
|
||||
}
|
||||
}
|
||||
|
||||
@ -38,7 +38,7 @@ impl PlonkOracle {
|
||||
};
|
||||
}
|
||||
|
||||
pub fn salt_size(salted: bool) -> usize {
|
||||
pub const fn salt_size(salted: bool) -> usize {
|
||||
if salted {
|
||||
SALT_SIZE
|
||||
} else {
|
||||
|
||||
@ -80,11 +80,11 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
self.local_constants = &self.local_constants[num_selectors * self.len()..];
|
||||
}
|
||||
|
||||
pub fn len(&self) -> usize {
|
||||
pub const fn len(&self) -> usize {
|
||||
self.batch_size
|
||||
}
|
||||
|
||||
pub fn is_empty(&self) -> bool {
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
|
||||
@ -100,7 +100,7 @@ impl<'a, F: Field> EvaluationVarsBaseBatch<'a, F> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn iter(&self) -> EvaluationVarsBaseBatchIter<'a, F> {
|
||||
pub const fn iter(&self) -> EvaluationVarsBaseBatchIter<'a, F> {
|
||||
EvaluationVarsBaseBatchIter::new(*self)
|
||||
}
|
||||
|
||||
@ -136,7 +136,7 @@ pub struct EvaluationVarsBaseBatchIter<'a, F: Field> {
|
||||
}
|
||||
|
||||
impl<'a, F: Field> EvaluationVarsBaseBatchIter<'a, F> {
|
||||
pub fn new(vars_batch: EvaluationVarsBaseBatch<'a, F>) -> Self {
|
||||
pub const fn new(vars_batch: EvaluationVarsBaseBatch<'a, F>) -> Self {
|
||||
EvaluationVarsBaseBatchIter { i: 0, vars_batch }
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,7 @@ impl ContextTree {
|
||||
}
|
||||
|
||||
/// Whether this context is still in scope.
|
||||
fn is_open(&self) -> bool {
|
||||
const fn is_open(&self) -> bool {
|
||||
self.exit_gate_count.is_none()
|
||||
}
|
||||
|
||||
|
||||
@ -27,7 +27,7 @@ pub fn transpose<T: Send + Sync + Copy>(matrix: &[Vec<T>]) -> Vec<Vec<T>> {
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn reverse_bits(n: usize, num_bits: usize) -> usize {
|
||||
pub(crate) const fn reverse_bits(n: usize, num_bits: usize) -> usize {
|
||||
// NB: The only reason we need overflowing_shr() here as opposed
|
||||
// to plain '>>' is to accommodate the case n == num_bits == 0,
|
||||
// which would become `0 >> 64`. Rust thinks that any shift of 64
|
||||
|
||||
@ -28,7 +28,7 @@ pub struct ReducingFactor<F: Field> {
|
||||
}
|
||||
|
||||
impl<F: Field> ReducingFactor<F> {
|
||||
pub fn new(base: F) -> Self {
|
||||
pub const fn new(base: F) -> Self {
|
||||
Self { base, count: 0 }
|
||||
}
|
||||
|
||||
@ -117,7 +117,7 @@ pub struct ReducingFactorTarget<const D: usize> {
|
||||
}
|
||||
|
||||
impl<const D: usize> ReducingFactorTarget<D> {
|
||||
pub fn new(base: ExtensionTarget<D>) -> Self {
|
||||
pub const fn new(base: ExtensionTarget<D>) -> Self {
|
||||
Self { base, count: 0 }
|
||||
}
|
||||
|
||||
|
||||
@ -2173,19 +2173,19 @@ pub struct Buffer<'a> {
|
||||
impl<'a> Buffer<'a> {
|
||||
/// Builds a new [`Buffer`] over `buffer`.
|
||||
#[inline]
|
||||
pub fn new(bytes: &'a [u8]) -> Self {
|
||||
pub const fn new(bytes: &'a [u8]) -> Self {
|
||||
Self { bytes, pos: 0 }
|
||||
}
|
||||
|
||||
/// Returns the inner position.
|
||||
#[inline]
|
||||
pub fn pos(&self) -> usize {
|
||||
pub const fn pos(&self) -> usize {
|
||||
self.pos
|
||||
}
|
||||
|
||||
/// Returns the inner buffer.
|
||||
#[inline]
|
||||
pub fn bytes(&self) -> &'a [u8] {
|
||||
pub const fn bytes(&self) -> &'a [u8] {
|
||||
self.bytes
|
||||
}
|
||||
|
||||
|
||||
@ -84,7 +84,7 @@ impl<'a, P: PackedField> PackedStridedView<'a, P> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn get(&self, index: usize) -> Option<&'a P> {
|
||||
pub const fn get(&self, index: usize) -> Option<&'a P> {
|
||||
if index < self.length {
|
||||
// Cast scalar pointer to vector pointer.
|
||||
let res_ptr = unsafe { self.start_ptr.add(index * self.stride) }.cast();
|
||||
@ -109,7 +109,7 @@ impl<'a, P: PackedField> PackedStridedView<'a, P> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn iter(&self) -> PackedStridedViewIter<'a, P> {
|
||||
pub const fn iter(&self) -> PackedStridedViewIter<'a, P> {
|
||||
PackedStridedViewIter::new(
|
||||
self.start_ptr,
|
||||
// See comment at the top of the `impl`. Below will point more than one byte past the
|
||||
@ -120,12 +120,12 @@ impl<'a, P: PackedField> PackedStridedView<'a, P> {
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn len(&self) -> usize {
|
||||
pub const fn len(&self) -> usize {
|
||||
self.length
|
||||
}
|
||||
|
||||
#[inline]
|
||||
pub fn is_empty(&self) -> bool {
|
||||
pub const fn is_empty(&self) -> bool {
|
||||
self.len() == 0
|
||||
}
|
||||
}
|
||||
@ -183,7 +183,7 @@ pub struct PackedStridedViewIter<'a, P: PackedField> {
|
||||
}
|
||||
|
||||
impl<'a, P: PackedField> PackedStridedViewIter<'a, P> {
|
||||
pub(self) fn new(start: *const P::Scalar, end: *const P::Scalar, stride: usize) -> Self {
|
||||
pub(self) const fn new(start: *const P::Scalar, end: *const P::Scalar, stride: usize) -> Self {
|
||||
Self {
|
||||
start,
|
||||
end,
|
||||
|
||||
@ -54,7 +54,7 @@ impl TimingTree {
|
||||
|
||||
/// Whether this scope is still in scope.
|
||||
#[cfg(feature = "timing")]
|
||||
fn is_open(&self) -> bool {
|
||||
const fn is_open(&self) -> bool {
|
||||
self.exit_time.is_none()
|
||||
}
|
||||
|
||||
|
||||
@ -14,7 +14,7 @@ pub struct StarkConfig {
|
||||
impl StarkConfig {
|
||||
/// A typical configuration with a rate of 2, resulting in fast but large proofs.
|
||||
/// Targets ~100 bit conjectured security.
|
||||
pub fn standard_fast_config() -> Self {
|
||||
pub const fn standard_fast_config() -> Self {
|
||||
Self {
|
||||
security_bits: 100,
|
||||
num_challenges: 2,
|
||||
|
||||
@ -34,7 +34,7 @@ impl<F: RichField + Extendable<D>, const D: usize> FibonacciStark<F, D> {
|
||||
// `num_rows`-th Fibonacci number.
|
||||
const PI_INDEX_RES: usize = 2;
|
||||
|
||||
fn new(num_rows: usize) -> Self {
|
||||
const fn new(num_rows: usize) -> Self {
|
||||
Self {
|
||||
num_rows,
|
||||
_phantom: PhantomData,
|
||||
|
||||
@ -15,7 +15,7 @@ use crate::transpose_util::transpose_in_place_square;
|
||||
|
||||
mod transpose_util;
|
||||
|
||||
pub fn bits_u64(n: u64) -> usize {
|
||||
pub const fn bits_u64(n: u64) -> usize {
|
||||
(64 - n.leading_zeros()) as usize
|
||||
}
|
||||
|
||||
@ -25,7 +25,7 @@ pub const fn ceil_div_usize(a: usize, b: usize) -> usize {
|
||||
|
||||
/// Computes `ceil(log_2(n))`.
|
||||
#[must_use]
|
||||
pub fn log2_ceil(n: usize) -> usize {
|
||||
pub const fn log2_ceil(n: usize) -> usize {
|
||||
(usize::BITS - n.saturating_sub(1).leading_zeros()) as usize
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user