INNER CODE UNIT · Rust
push
risc0/risc0-ethereum · crates/aggregation/src/lib.rs:204
pub fn push(&mut self, value: impl Borrow<Digest>) -> Result<(), Error> {
self.push_peak(Peak {
digest: hash_leaf(value.borrow()),
max_depth: 0,
})
}
fn push_peak(&mut self, new_peak: Peak) -> Result<(), Error> {
// If the peak has a max-depth of 255, then the mountain range is finalized and no new
// peaks can be pushed to it. Note that this state can only be achieved by calling
// `finalize` since it is computationally infeasible to push 2^256 nodes onto the MMR,
// although it is theoretically consistent that if an MMR reached a state of being a
// single peak with max depth value of 255, it would be naturally finalized.
if self.is_finalized() {
return Err(Error::FinalizedError);
}
match self.0.last() {
// If the MerkleMountainRange is empty, push the new peak.