mirror of
https://github.com/sigp/lighthouse.git
synced 2026-03-23 14:54:45 +00:00
Use checked arithmetic in types and state proc (#1009)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
use eth2_hashing::{hash, hash32_concat, ZERO_HASHES};
|
||||
use ethereum_types::H256;
|
||||
use lazy_static::lazy_static;
|
||||
use safe_arith::ArithError;
|
||||
|
||||
const MAX_TREE_DEPTH: usize = 32;
|
||||
const EMPTY_SLICE: &[H256] = &[];
|
||||
@@ -38,6 +39,8 @@ pub enum MerkleTreeError {
|
||||
Invalid,
|
||||
// Incorrect Depth provided
|
||||
DepthTooSmall,
|
||||
// Overflow occurred
|
||||
ArithError,
|
||||
}
|
||||
|
||||
impl MerkleTree {
|
||||
@@ -232,6 +235,12 @@ fn merkle_root_from_branch(leaf: H256, branch: &[H256], depth: usize, index: usi
|
||||
H256::from_slice(&merkle_root)
|
||||
}
|
||||
|
||||
impl From<ArithError> for MerkleTreeError {
|
||||
fn from(_: ArithError) -> Self {
|
||||
MerkleTreeError::ArithError
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user