mod.rs
 1  // Copyright (c) 2025-2026 ACDC Network
 2  // This file is part of the alphavm library.
 3  //
 4  // Alpha Chain | Delta Chain Protocol
 5  // International Monetary Graphite.
 6  //
 7  // Derived from Aleo (https://aleo.org) and ProvableHQ (https://provable.com).
 8  // They built world-class ZK infrastructure. We installed the EASY button.
 9  // Their cryptography: elegant. Our modifications: bureaucracy-compatible.
10  // Original brilliance: theirs. Robert's Rules: ours. Bugs: definitely ours.
11  //
12  // Original Aleo/ProvableHQ code subject to Apache 2.0 https://www.apache.org/licenses/LICENSE-2.0
13  // All modifications and new work: CC0 1.0 Universal Public Domain Dedication.
14  // No rights reserved. No permission required. No warranty. No refunds.
15  //
16  // https://creativecommons.org/publicdomain/zero/1.0/
17  // SPDX-License-Identifier: CC0-1.0
18  
19  mod sponge;
20  pub(super) use sponge::*;
21  
22  mod state;
23  pub(super) use state::*;
24  
25  use alphavm_console_types::{prelude::*, Field};
26  
27  use smallvec::SmallVec;
28  
29  /// The interface for a cryptographic sponge.
30  /// A sponge can `absorb` or take in inputs and later `squeeze` or output bytes or field elements.
31  /// The outputs are dependent on previous `absorb` and `squeeze` calls.
32  pub trait AlgebraicSponge<E: Environment, const RATE: usize, const CAPACITY: usize>: Clone + Debug {
33      /// Parameters used by the sponge.
34      type Parameters;
35  
36      /// Initialize a new instance of the sponge.
37      fn new(params: &Self::Parameters) -> Self;
38  
39      /// Absorb an input into the sponge.
40      fn absorb(&mut self, input: &[Field<E>]);
41  
42      /// Squeeze `num_elements` field elements from the sponge.
43      fn squeeze(&mut self, num_elements: u16) -> SmallVec<[Field<E>; 10]>;
44  }
45  
46  /// The mode structure for duplex sponges.
47  #[derive(PartialEq, Eq, Clone, Debug)]
48  pub enum DuplexSpongeMode {
49      /// The sponge is currently absorbing data.
50      Absorbing {
51          /// The next position of the state to be XOR-ed when absorbing.
52          next_absorb_index: usize,
53      },
54      /// The sponge is currently squeezing data out.
55      Squeezing {
56          /// The next position of the state to be outputted when squeezing.
57          next_squeeze_index: usize,
58      },
59  }