• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ergoplatform / sigma-rust / 8953175335

04 May 2024 08:51PM UTC coverage: 80.473% (+0.1%) from 80.331%
8953175335

Pull #736

github

web-flow
Merge 0fdf2d258 into 57a105462
Pull Request #736: Transaction Validation

165 of 228 new or added lines in 15 files covered. (72.37%)

8 existing lines in 2 files now uncovered.

10723 of 13325 relevant lines covered (80.47%)

3.29 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

33.33
/ergo-lib/src/chain/transaction/storage_rent.rs
1
use ergotree_interpreter::{eval::context::Context, sigma_protocol::prover::ProofBytes};
2
use ergotree_ir::{
3
    chain::ergo_box::RegisterId, mir::constant::TryExtractInto, serialization::SigmaSerializable,
4
};
5

6
use crate::chain::ergo_state_context::ErgoStateContext;
7

8
use super::Input;
9

10
/// The minimum time before a box can be spent via storage rent mechanism
11
pub const STORAGE_PERIOD: u32 = 1051200;
12
/// What index in ContextExtension the index of output is stored.
13
pub const STORAGE_EXTENSION_INDEX: u8 = i8::MAX as u8;
14

15
// Attempt to spend a box with storage rent. Returns None if any of the required conditions is not met
16
pub(crate) fn try_spend_storage_rent(
1✔
17
    input_box: &Input,
18
    state_context: &ErgoStateContext,
19
    context: &Context,
20
) -> Option<()> {
21
    if context
2✔
22
        .pre_header
23
        .height
24
        .checked_sub(context.self_box.creation_height)?
1✔
25
        >= STORAGE_PERIOD
26
        && matches!(input_box.spending_proof.proof, ProofBytes::Empty)
1✔
27
    {
28
        let output_idx: i16 = context
1✔
29
            .extension
30
            .values
31
            .get(&STORAGE_EXTENSION_INDEX)?
32
            .v
33
            .clone()
34
            .try_extract_into()
35
            .ok()?;
NEW
36
        let output_candidate = context.outputs.get(output_idx as usize)?;
×
37

38
        let storage_fee = output_candidate.sigma_serialize_bytes().ok()?.len() as u64
1✔
NEW
39
            * state_context.parameters.storage_fee_factor() as u64;
×
40
        // If the box's value is less than the required storage fee, the box can be spent without any further restrictions
NEW
41
        if context.self_box.value.as_u64() <= &storage_fee {
×
NEW
42
            return Some(());
×
43
        }
NEW
44
        if output_candidate.creation_height != state_context.pre_header.height
×
NEW
45
            || *output_candidate.value.as_u64() < context.self_box.value.as_u64() - storage_fee
×
46
        {
NEW
47
            return None;
×
48
        }
49
        // Require that all registers except value (R0) and creation info (R3) be preserved
NEW
50
        let registers_preserved =
×
51
            (0..=9u8)
52
                .map(RegisterId::try_from)
53
                .map(Result::unwrap)
NEW
54
                .all(|id| {
×
NEW
55
                    id == RegisterId::R0
×
NEW
56
                        || id == RegisterId::R3
×
NEW
57
                        || context.self_box.get_register(id) == output_candidate.get_register(id)
×
58
                });
NEW
59
        if registers_preserved {
×
NEW
60
            return Some(());
×
61
        }
62
    }
63
    None
1✔
64
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2025 Coveralls, Inc