axiom_eth/solidity/types.rs
1//TODO: Replace arrays and gate with &impl
2use crate::Field;
3use crate::{keccak::types::KeccakVarLenQuery, rlc::types::ConcatVarFixedArrayTrace};
4use halo2_base::{
5 safe_types::{SafeBytes32, VarLenBytesVec},
6 AssignedValue,
7};
8
9/// Witness for the computation of a nested mapping
10#[derive(Debug, Clone)]
11pub struct NestedMappingWitness<F: Field> {
12 pub witness: Vec<MappingWitness<F>>,
13 pub slot: SafeBytes32<F>,
14 pub nestings: AssignedValue<F>,
15}
16
17/// Witness for the computation of a mapping with a variable length (Non-Value) key.
18#[derive(Debug, Clone)]
19pub struct VarMappingWitness<F: Field> {
20 pub mapping_slot: SafeBytes32<F>,
21 pub key: VarLenBytesVec<F>,
22 /// The output of this hash is the storage slot for the mapping key
23 pub hash_query: KeccakVarLenQuery<F>,
24}
25
26pub type VarMappingTrace<F> = ConcatVarFixedArrayTrace<F>;
27
28#[allow(clippy::large_enum_variant)]
29#[derive(Debug, Clone)]
30pub enum MappingWitness<F: Field> {
31 /// The storage slot corresponding to mapping key of value type
32 Value(SafeBytes32<F>),
33 /// Witness for mapping key of non-value type
34 NonValue(VarMappingWitness<F>),
35}
36
37impl<F: Field> MappingWitness<F> {
38 pub fn slot(&self) -> SafeBytes32<F> {
39 match self {
40 MappingWitness::Value(slot) => slot.clone(),
41 MappingWitness::NonValue(witness) => witness.hash_query.output_bytes.clone(),
42 }
43 }
44}
45
46/// Return after phase1 of mapping computation. None if the mapping key is of Value type.
47pub type MappingTrace<F> = Option<VarMappingTrace<F>>;
48
49/// Enum whose variants which represents different primitive types of Solidity types that can be represented in circuit.
50/// Each variant wraps a `Vec<AssignedValue<F>>` representing the bytes of primitive type.
51///
52/// Fixed Length Types (Value):
53/// --------------------------
54/// * `UInt256`: 32 bytes
55/// Fixed length primitive types are represented by a fixed length `Vec<AssignedValue<F>>` converted to a `SafeBytes32<F>`.
56/// SafeTypes range check that each AssignedValue<F> of the vector is within byte range 0-255 and the vector has length 32.
57///
58/// Variable Length Types (NonValue):
59/// ---------------------------------
60/// * `NonValue`: Variable length byte array
61#[derive(Debug, Clone)]
62pub enum SolidityType<F: Field> {
63 Value(SafeBytes32<F>),
64 NonValue(VarLenBytesVec<F>),
65}