Skip to main content
PSUT / IoTEngineering learning studio
WORKSPACE
Offline-first portalDr. Mohammad Alja’afreh
Distributed Ledger StudioBlockchain for IoTExperimentsWorkspaces
ENGINEERING WORKSPACE
Home/Engineering Workspaces/B11 · Merkle batch commitments
IoTPSUT IoT Engineering StudioPrincess Sumaya University for Technology · Dr. Mohammad Alja’afreh
Blockchain for IoT · advanced laboratory
Blockchain for IoT

Merkle batch commitments

Ask Dr. Mohammad · B11 →

Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

Design experiment & verify evidence →
B11 · Laboratory mentorAsk about the current experiment, its algorithms or Python notebook.
Ask Dr. MohammadAdaptive practice
Learning workflow · Advanced blockchainB11 · Merkle batch commitments

Related course access: IoT Security and Privacy — same laboratory, notebook and completion record.

B11 · Academic orientation

Scope and objectives

Scope of the experiment

Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

The focus of this experiment is to construct batch Merkle commitments and inclusion proofs. Students then calculate sibling paths and verify ordered root reconstruction, and compare proof size and record batching under stated assumptions. The Concepts view explains the operation before the practical work; the Simulation view is used to examine reference and changed inputs, not to substitute for actual measurements.

Learning objectives

  • Construct batch Merkle commitments and inclusion proofs.
  • Calculate sibling paths and verify ordered root reconstruction.
  • Compare proof size and record batching under stated assumptions.
  • Identify the configured inputs (Leaf index; Input) and record the corresponding observed outputs with units where applicable.
  • Compare the reference calculation or decision with an independent implementation or authorized observation; state any discrepancy and the applicable model boundary.

Expected learning outcomes

On completion, students can construct batch Merkle commitments and inclusion proofs, calculate sibling paths and verify ordered root reconstruction, and compare proof size and record batching under stated assumptions.

Required deliverables

Submit the derivation or state trace for the named operation, the exact reference and changed configurations, the associated simulator or practical evidence, and a short validation statement addressing compare proof size and record batching under stated assumptions. Separate predicted values from observations.

Prerequisite knowledge and related learning

Review the following catalogue prerequisites before starting. After completion, continue to IoT gateway serialization & integrity.

Environment and experimental methodology

The listed browser model and experiment-specific local Python, Solidity or EVM workflow, where provided. Do not treat a model as a deployed ledger.

Begin with a manual prediction, record the baseline, change one independent condition at a time, and compare the resulting trace or measurements with the original prediction. Record observations and uncertainty separately from reference values. Follow the experiment’s specific procedure, safety limits, and acceptance checks.

B11 · learning outcome

Understand the experiment

Scientific architecture · Merkle batch commitments

Merkle batch integrity — Four telemetry reports / ordered leaves; Hash each report / H0…H3; Pair hashes / H01, H23; Root / H(H01; ; H23); Proof / sibling path against trusted root
Scientific concept map: Telemetry batch — Multiple records; Leaf digest — Canonical bytes; Merkle tree — Pairwise hashes; Root — Store commitment; Proof — Verify one record.

Scientific foundations and analytical reasoning

Batch commitments use ordered Merkle trees; a proof establishes inclusion against a fixed root, not truth of the measured reading.

Before operating the equipment or executing the program, derive the expected outcome using the required theoretical work in Experiment. Use the diagram to identify the variables and system boundaries.

Scientific theory · Batch Merkle commitments

Ordered leaf hashes commit a batch of readings. Parent hashes combine left and right children using an agreed encoding and odd-leaf policy. Proof size grows with tree depth rather than batch size in a balanced tree. The verifier must trust the published root and reconstruct the correct sibling order.

Worked example and engineering interpretation

For eight leaves, a balanced inclusion proof has three sibling hashes. A different reading or reversed sibling orientation generally yields a different root. Proof success confirms inclusion of the committed bytes, not sensor truth or availability of the full batch.

Engineering principles · additional worked teaching example

Batch commitments compress many leaf hashes into one root. Proof size grows logarithmically for a full binary tree; leaves must be serialized and ordered consistently.

From theory to experiment

Predict the reference result before operating the workbench; check the actual intermediate state, units and constraints. The existing simulation, implementation and procedure below are distinct sources of evidence.

How to investigate Merkle batch commitments

Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

Analytical investigation means collecting an observation, identifying the mechanism, using a calculation or state trace to explain it, and checking your conclusion against evidence. Controlled comparison means changing one independent variable, holding the remaining relevant conditions constant, and measuring a dependent variable against a baseline. Experimental validation means comparing a predicted result to a reproducible observation or assertion; agreement inside a model does not certify hardware. Evidence-based reasoning connects a specific observation to a theoretical rule and states uncertainty, not merely an opinion. Performance characterization records a named metric and its units across conditions; sensitivity analysis changes one parameter across several values. A threat assessment links an asset, threat, consequence and evidence to a mitigation.

Experiment-specific guided practice

Objective: Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

  1. Save baseline, select leaf index 0–3 and inspect sibling hashes and root. Apply altered record; expect proof rejection. Restore original and verify again.
  2. Copy the 64-character trusted root shown in the workbench and prefix it with 0x. Open BatchAnchor.sol in Remix using the shared compiler settings. Deploy from account 0. Copy account 1 device address and call setDevice(account 1,true).
  3. Switch to account 1; call commit(1, 0x<root>) using the copied root. Expected latestBatch(account 1)=1 and latestRoot(account 1) equals supplied root. Repeat batch 1: expected InvalidBatch; try batch 2 with 32 zero bytes: EmptyRoot. Switch to account 2: commit(2,root) must revert Unauthorized.
  4. Record the root read from the contract independently. Compare with the browser trusted root. Do not claim that on-chain code verified the off-chain proof.

Reference check: Four leaves require 7 digests and 2 proof siblings; eight require 15 digests and 3 siblings. Modified candidate fails against the original root.

Model boundary: Domain-separated UTF-8 encoding matches the existing teaching labs; not Bitcoin double-SHA256 byte serialization or Ethereum Keccak. Inclusion does not establish finality or source truth.

Independent task and submission evidence

2. Copy the 64-character trusted root shown in the workbench and prefix it with 0x. Open BatchAnchor.sol in Remix using the shared compiler settings. Deploy from account 0. Copy account 1 device address and call setDevice(account 1,true). Record the named input, prediction, actual output and one limitation; restore the original condition and repeat.

Before execution write the independent variable and its levels, dependent observation with units where applicable, baseline, controlled variables, measurement method and expected result. For a state machine use state/event/output rather than inventing a numeric metric. Record failures and repeat the baseline. A weak conclusion is “it works”; a supported conclusion names the changed setting, observed value/state, corresponding rule and one limitation.

TrialChanged settingFixed settingsPredicted resultActual observation / unitsEvidence / uncertainty
A: baselineReferenceRecordPredictRecordRecord
B: one changeRecordSame as APredictRecordRecord
A: repeatRestoreSame as APredictRecordRecord

Completion: submit the filled table, relevant simulator screenshot or terminal/notebook output, reasoning with units/assumptions, and one limitation. Preserve the independent assessment questions; this guide does not fill their answers.

Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

Domain-separated SHA-256 over UTF-8 strings and hex-encoded child digests. The proof is off-chain and differs from OpenZeppelin Keccak-based conventions. Only a root is stored on-chain.

Worked engineering reasoning and boundary conditions

Engineering reference configuration: Leaf index = 0; Input = none. In the classroom model, Proof = Valid; Leaf index = 0; Root bytes = 32; Sibling hashes = 2. The root is trusted independently. This domain-separated SHA-256 tree uses UTF-8 strings and hex-encoded child digests, not Ethereum Keccak or OpenZeppelin MerkleProof format. Domain-separated SHA-256 over UTF-8 strings and hex-encoded child digests. The proof is off-chain and differs from OpenZeppelin Keccak-based conventions. Only a root is stored on-chain.

Use the diagram to follow the calculation or state progression. Keep the teaching configuration separate from the independent exercise values; compare observations with the actual model and implementation.

Mathematical representation and interpretation

Merkle parent construction

The child digests are concatenated in the defined order using the same byte representation; membership depends on the independently trusted root.

\[h_{i,j}=H(h_i\parallel h_j)\]

Concept animation · independent state notebook

Explore the teaching example independently of the simulator. Each step reveals an operation, data relationship or calculated state. The Simulation view has separate editable inputs.

Merkle batch commitments: independent state notebook1234Calculated state 1ItemTrusted rootValuee5c213efe56d0ecf42e58f5a26899359b34d2bb4cc…Explanation

Step 1 of 4 · Calculated state 1

Calculated state 1

Item
Trusted root
Value
e5c213efe56d0ecf42e58f5a26899359b34d2bb4ccc6be4d4fbc9618abc82300
Explanation

Teaching example only; inspect live calculations or real practical evidence separately.

Recall the concept before revealing its explanation.

0 / 3 revealed
B11 · 01 / 08Why use a trusted root?Reveal explanation
Engineering explanation

An altered dataset could otherwise be hashed into a new internally consistent tree.

B11 · 02 / 08How many siblings for four leaves?Reveal explanation
Engineering explanation

Two ordered sibling hashes.

B11 · 03 / 08Does a root prove sensor truth?Reveal explanation
Engineering explanation

No; it commits to bytes under a chosen encoding.

B11 · 04 / 08Why reconstruct a Merkle proof from the supplied leaf bytes?Reveal explanation
Engineering reasoning

The digest must correspond to the exact committed serialization, and ordered siblings reconstruct the root.

B11 · 05 / 08Why try every leaf index in a four-leaf tree?Reveal explanation
Engineering reasoning

It exercises left/right proof positions, not just a single favorable path.

B11 · 06 / 08Four sensor commitments form a Merkle batch. Select every technically valid statement. A. Verify ordered sibling hashes. B. Use a root obtained from the trusted commitment. C. An arbitrary candidate root establishes membership. D. A single altered leaf cannot affect the computed root.Reveal explanation
Applied scenario

Correct: A. Verify ordered sibling hashes.; B. Use a root obtained from the trusted commitment.

B11 · 07 / 08In Merkle batch commitments, which reference and changed settings are prescribed for Input?Reveal explanation
Controlled configuration

Input: none → alter; hold the remaining settings fixed.

B11 · 08 / 08What expected result distinguishes the reference and changed trials in Merkle batch commitments?Reveal explanation
Expected observation

All four original leaves verify; an altered leaf is rejected.

Loading experiment-specific apparatus…
Previous model / additional reference tools

Loading executable simulation…

Simulation task

Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

Explore the model using its own controls. Record a prediction before changing a condition. Compare the reference with a changed condition, then use the Experiment tab for the procedure, acceptance criteria and notebook. Model outputs and physical observations must remain separate.

Interactive engineering workbenchB11 · Existing model
Interactive workbench

Predict, configure and observe

B11 · Model-linked instrumentation

Visual observation lens

Back to controls ↑

Readout from the original computational model; not physical measurements.

Loading instrument…

Awaiting model display.

Experimental instrumentation · A/B

Compare two model conditions

Capture a baseline, change one experimental condition, run the model if required and capture the comparison. Snapshots contain visible controls and display text, not physical sensor readings. Review before exporting.

Open simulation view
Baseline A
Not captured
Comparison B
Not captured

Capture a baseline to begin.

Evidence portfolio →
V19.0 · Contextual AI workspace

Ask your engineering assistants

B11 · current context

Ask Dr. Mohammad locally, or prepare an experiment-aware prompt for ChatGPT, Gemini or Claude. The external providers open in their own tabs; nothing is automatically submitted.

Dr. Mohammad · offline
Dr. Mohammad

Offline curriculum-grounded assistance.

Open local tutor
Merkle batch commitments

Public course objective, displayed commands, source excerpts and procedure. Private assessment content is not collected.

Prepare a contextual AI prompt

0 characters

Common secret and email patterns are redacted on preparation; this is not a comprehensive privacy filter. Review the entire editable prompt, including student work and unpublished research, before sharing. The providers apply their own accounts, privacy settings and limits.

Prepare → review → copy & open your selected provider → paste and submit there.

Independent theoretical exercises

Before the simulation or practical, solve both experiment-specific tasks. List the given inputs, show the intermediate calculation or state trace, identify the expected observation, and state a limitation. Show formulas and intermediate calculations where relevant, or draw the requested state/sequence diagram. These are independent classroom fixtures; where they differ from the reference configuration below, do not treat them as measured values. Compare your predictions with the corresponding experiment afterwards.

01 · Predict and derive using the given inputs

Draw a four-record tree, calculate sibling indices and orientation for leaf index 3, and count proof hashes.

02 · Compare or justify using evidence

Explain effect of altering a record and recomputing an untrusted root; specify which trusted value is needed for verification.

03 · Proof calculation

Proof calculation · Independent work

For 16 leaves and 32-byte hashes, calculate sibling count and raw sibling bytes for an inclusion proof; compare 4 leaves.

Work is saved locally when browser storage is available. Export it for submission; no remote upload or automatic grade is assigned.

Expanded independent theoretical exercise bank

Progress from calculation and interpretation to diagnosis and controlled engineering design. Complete the questions without opening the simulation first; show intermediate steps.

Intermediate · Explain a changed-input result

Independent theoretical exercise · B11-01

Use the reference configuration (Leaf index = 0; Input = none), but change Leaf index = 1. The model reports Leaf index = 1. Explain the governing rule and assumptions that make this output plausible; identify an independent verification method.

Intermediate · Interpret a state transition

Independent theoretical exercise · B11-02

The reference model reports Leaf index: 0. Under Leaf index = 1 it reports 1. Explain which configured condition changed and what the two outputs establish, and what they do not establish.

Intermediate · Interpret a technical trace

Independent theoretical exercise · B11-03

For Input = alter, the model supplies this excerpt from Calculated trace: Item · Value · Explanation Trusted root · e5c213efe56d0ecf42e58f5a26899359b34d2bb4ccc6be4d4fbc9618abc82300 · Supplied record · {"device":"node-1","sequence":1,"temperature_centi":7900} · Sibling 1 · 58067ea82e071f4f1103c11af143eab4d604f0e2314bef28d4284830d2c836eb · right Sibling 2 · 201e6230069fcd852791aab00029f23d8a68cdf751af3c0f9968d9dfeab1fb0d · right Count rows whose Value value is exactly “e5c213efe56d0ecf42e58f5a26899359b34d2bb4ccc6be4d4fbc9618abc82300”, and identify the displayed row numbers. Explain what the count describes.

Advanced · Reverse reasoning

Independent theoretical exercise · B11-04

An observation is Proof = Rejected. Candidate A uses Leaf index = 0; Input = none. Candidate B changes the listed settings (Input = alter) and keeps the remaining settings fixed. Which is consistent with the observation? If both can explain it, say what additional evidence is required.

Advanced · Diagnose a reported mismatch

Independent theoretical exercise · B11-05

A student configures Input = alter while preserving all other reference settings, but copies the reference report of Proof = Valid. Evaluate whether the report is justified. Identify the first configuration/output check to perform.

Challenging · Design a controlled verification

Independent theoretical exercise · B11-06

Design a controlled comparison for Merkle batch commitments using reference Leaf index = 0; Input = none and test Leaf index = 1. Specify the changed setting(s), measured metric Leaf index, controls, repetitions, an acceptance check and what evidence can distinguish an actual implementation from the model.

Step-by-step experimental procedure

Construct a four-record Merkle tree and verify ordered membership against an independently trusted root.

1 · Reference workbench configuration

Use the named reference workbench and its reference inputs. Additional live instruments may have different controls; use the matching instrument. Record virtual and practical results separately.

Leaf index0
Inputnone

2 · Perform the investigation in order

  1. Save baseline, select leaf index 0–3 and inspect sibling hashes and root. Apply altered record; expect proof rejection. Restore original and verify again.
  2. Copy the 64-character trusted root shown in the workbench and prefix it with 0x. Open BatchAnchor.sol in Remix using the shared compiler settings. Deploy from account 0. Copy account 1 device address and call setDevice(account 1,true).
  3. Switch to account 1; call commit(1, 0x<root>) using the copied root. Expected latestBatch(account 1)=1 and latestRoot(account 1) equals supplied root. Repeat batch 1: expected InvalidBatch; try batch 2 with 32 zero bytes: EmptyRoot. Switch to account 2: commit(2,root) must revert Unauthorized.
  4. Record the root read from the contract independently. Compare with the browser trusted root. Do not claim that on-chain code verified the off-chain proof.

3 · Compare controlled trials

TrialIndependent changeExpected checkObservation
ReferenceUse reference inputs aboveAll four original leaves verify; an altered leaf is rejected.Record actual result
Controlled changeInput = alterAll four original leaves verify; an altered leaf is rejected.Record actual result

4 · Analyze and report

Domain-separated SHA-256 over UTF-8 strings and hex-encoded child digests. The proof is off-chain and differs from OpenZeppelin Keccak-based conventions. Only a root is stored on-chain.

Required evidence: Record the merkle batch commitments comparison and justify the changed outcome from the calculated trace.

Model boundary: Domain-separated SHA-256 over UTF-8 strings and hex-encoded child digests. The proof is off-chain and differs from OpenZeppelin Keccak-based conventions. Only a root is stored on-chain.

Controlled investigation · reproducible evidence

Method. Use the existing reference workbench configuration and the named controlled changes below. A controlled variable stays fixed while the independent variable is intentionally changed; the dependent variable is the resulting observed output. First predict each trial from the Concepts page. Run the baseline, then change only the specified setting and record the outcome. For deterministic traces one execution per case and a repeated verification are sufficient; for timing or stochastic measurements repeat at least five times, recording each run, median and range. Reset to the reference state between independent comparisons.

TrialIndependent changeDependent observation
ReferenceUse reference inputs aboveRecord actual outcome and units
Controlled changeInput = alterRecord actual outcome and units

Evidence: attach the completed comparison table, one trace or screenshot per condition, and actual practical terminal/hardware evidence where applicable. Explain any prediction mismatch and distinguish modeled behavior from measured results.

Loading laboratory-specific procedure…

Python / Google Colab notebook

Original module reference toolkit; genuine SHA-256 and bounded search. Validated locally in a fresh Jupyter kernel. Download, then upload to Google Colab.

Download NotebookOpen Google ColabAll Python notebooks

Complete practical procedure & acceptance

✓ Expected baseline and controlled change: All four original leaves verify; an altered leaf is rejected.

  1. Save baseline, select leaf index 0–3 and inspect sibling hashes and root. Apply altered record; expect proof rejection. Restore original and verify again.
  2. Copy the 64-character trusted root shown in the workbench and prefix it with 0x. Open BatchAnchor.sol in Remix with compiler 0.8.28, Shanghai target, optimization disabled, Remix VM and VALUE 0. Deploy from account 0. Copy account 1 device address and call setDevice(account 1,true).
  3. Switch to account 1; call commit(1, 0x<root>) using the copied root. Expected latestBatch(account 1)=1 and latestRoot(account 1) equals supplied root. Repeat batch 1: expected InvalidBatch; try batch 2 with 32 zero bytes: EmptyRoot. Switch to account 2: commit(2,root) must revert Unauthorized.
  4. Record the root read from the contract independently. Compare with the browser trusted root. Do not claim that on-chain code verified the off-chain proof.
  5. Export observed evidence, restore baseline and record limitations. Do not treat browser-model output as actual hardware or EVM evidence.

Experimental notebook

Record your own results. Values are not prefilled or independently verified.

Solidity source

Download BatchAnchor.sol · Open Remix IDE

SOLIDITY · Source code
// SPDX-License-Identifier: MIT
pragma solidity 0.8.28;
/// @notice Owner-authorized, per-device batch commitments. Verify membership off-chain.
contract BatchAnchor {
    address public immutable owner;
    mapping(address => bool) public active;
    mapping(address => uint64) public latestBatch;
    mapping(address => bytes32) public latestRoot;
    error NotOwner(); error InvalidDevice(); error Unauthorized(); error InvalidBatch(); error EmptyRoot();
    event BatchCommitted(address indexed device, uint64 indexed batch, bytes32 root);
    constructor() { owner = msg.sender; }
    function setDevice(address device, bool enabled) external {
        if (msg.sender != owner) revert NotOwner();
        if (device == address(0)) revert InvalidDevice();
        active[device] = enabled;
    }
    function commit(uint64 batch, bytes32 root) external {
        if (!active[msg.sender]) revert Unauthorized();
        if (batch <= latestBatch[msg.sender]) revert InvalidBatch();
        if (root == bytes32(0)) revert EmptyRoot();
        latestBatch[msg.sender] = batch; latestRoot[msg.sender] = root;
        emit BatchCommitted(msg.sender, batch, root);
    }
}

Record & discuss

Notebook exports use related core lab B02; the supplementary ID is retained in the evidence. Technical reference.

Learning progress

Mark complete only after documenting your observations. This is not a verified result or official grade.

View prerequisites and related learning

Python / Google Colab laboratory

B11 · 8 notebook cells · 2 executable Python cells

Complete the theoretical investigation first. Run the cells in order, record actual outputs and compare against your prediction.

How to execute

  1. Download this notebook and open Google Colab. Select File → Upload notebook and choose the downloaded .ipynb.
  2. Read the Markdown instructions before each executable cell. Use a Python runtime, run cells from top to bottom, and resolve imports if necessary.
  3. Perform the baseline and controlled changes. Save the notebook with actual outputs and your written interpretation.

Execution scope: Domain-separated UTF-8 encoding matches the existing teaching labs; not Bitcoin double-SHA256 byte serialization or Ethereum Keccak. Inclusion does not establish finality or source truth. Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.

01Instructions · Markdown
# b11 · Merkle batch commitments **PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh** ## Introduction Construct a four-record Merkle tree and verify ordered membership against an independently trusted root. ## How to run 1. Download this notebook from the laboratory page. Open Google Colab → File → Upload notebook. 2. Select a Python CPU runtime. Run cells from top to bottom using Shift+Enter, or Runtime → Run all. 3. Read the printed observations and assertions. Change one parameter at a time and rerun the relevant cell. 4. Save your own outputs and compare them to the portal Experiment tab. **Execution boundary:** Original module reference toolkit; genuine SHA-256 and bounded search. Do not run the hardware or service commands in Colab. No real credentials are needed. The notebook is self-contained.
02Instructions · Markdown
## Experiment-specific preparation Construct a four-record Merkle tree and verify ordered membership against an independently trusted root. **Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):** 1. Save baseline, select leaf index 0–3 and inspect sibling hashes and root. Apply altered record; expect proof rejection. Restore original and verify again. 2. Copy the 64-character trusted root shown in the workbench and prefix it with 0x. Open BatchAnchor.sol in Remix using the shared compiler settings. Deploy from account 0. Copy account 1 device address and call setDevice(account 1,true). 3. Switch to account 1; call commit(1, 0x<root>) using the copied root. Expected latestBatch(account 1)=1 and latestRoot(account 1) equals supplied root. Repeat batch 1: expected InvalidBatch; try batch 2 with 32 zero bytes: EmptyRoot. Switch to account 2: commit(2,root) must revert Unauthorized. 4. Record the root read from the contract independently. Compare with the browser trusted root. Do not claim that on-chain code verified the off-chain proof. **Evidence:** Four leaves require 7 digests and 2 proof siblings; eight require 15 digests and 3 siblings. Modified candidate fails against the original root. **Boundary:** Domain-separated UTF-8 encoding matches the existing teaching labs; not Bitcoin double-SHA256 byte serialization or Ethereum Keccak. Inclusion does not establish finality or source truth.
03Instructions · Markdown
## 1. Objectives and reference condition - Reproduce the specific computational mechanism in this laboratory. - Inspect the output, compare the reference condition with a changed or rejected condition where implemented, and explain any discrepancy. - Distinguish actual local Python execution from mock, physical and external-service observations. ## 2. Environment check
04Python · executable cell
PYTHON · Code cell
# =====================================================================
# B11 | Code cell 01 | Merkle batch commitments
# Purpose: 1. Objectives and reference condition - Reproduce the specific computational mechanism in this laboratory. - Inspect the output, compare the reference condition with a changed or rejected condition where implem
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
import sys
print("Python",sys.version.split()[0])
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert sys.version_info >= (3,10)
Ask Dr. Mohammad about this cell
05Instructions · Markdown
## 3. Implementation Read the comments and variable definitions before execution. Assertions must pass; inspect values, not just completion.
06Python · executable cell
PYTHON · Code cell
# =====================================================================
# B11 | Code cell 02 | Merkle batch commitments
# Purpose: implement only the mechanism named in this laboratory.
# Inputs: the explicit fictional fixture and reference parameters below.
# Output: printed observations and assertions for the controlled trial.
# =====================================================================
import hashlib,json
def serialize(obj):
    return json.dumps(obj, ensure_ascii=False, separators=(',', ':'))

def sha(text):
    return hashlib.sha256(text.encode('utf-8')).hexdigest()

def tree(values):
    if len(values) not in (4,8): raise ValueError('Use 4 or 8 leaves')
    levels = [[sha('leaf:' + serialize(v)) for v in values]]
    while len(levels[-1]) > 1:
        a=levels[-1]; levels.append([sha('node:' + a[i] + a[i+1]) for i in range(0,len(a),2)])
    return levels

def prove(levels,index,candidate):
    current=sha('leaf:'+serialize(candidate)); steps=[dict(input='leaf:'+serialize(candidate),digest=current)]
    for row in levels[:-1]:
        sibling=row[index^1]; text='node:'+(sibling+current if index&1 else current+sibling);current=sha(text)
        steps.append(dict(input=text,digest=current,sibling=sibling,side='left' if index&1 else 'right'));index//=2
    return dict(valid=current==levels[-1][0],steps=steps,computedRoot=current,trustedRoot=levels[-1][0])
values=[f'sensor-{i+1}:temp={25+i}' for i in range(8)]
levels=tree(values);proof=prove(levels,0,values[0]);tampered=prove(levels,0,'changed')
print('root',levels[-1][0],'proof',proof,'tampered valid',tampered['valid'])
assert proof['valid'] and not tampered['valid']
for count in (4,8):
    batch=values[:count];print('batch',count,'root',tree(batch)[-1][0],'proof depth',len(tree(batch))-1)
Ask Dr. Mohammad about this cell
07Instructions · Markdown
## 4. Results and analysis Record the actual output and whether the assertions pass. Identify a parameter to vary, state your prediction, repeat the reference calculation, then explain the changed result. | Trial | Configuration | Observation | Interpretation | |---|---|---|---| | A | Reference | | | | B | One controlled change | | | | C | Reference repeat | | | **Limitations:** Original module reference toolkit; genuine SHA-256 and bounded search. Notebook success does not certify external equipment or services.
08Instructions · Markdown
## Guided reasoning and evidence A controlled comparison changes one independent input while keeping the other relevant inputs fixed; the dependent variable is the recorded output. Use this lab’s reference condition above. **Independent task:** 2. Copy the 64-character trusted root shown in the workbench and prefix it with 0x. Open BatchAnchor.sol in Remix using the shared compiler settings. Deploy from account 0. Copy account 1 device address and call setDevice(account 1,true). Record the named input, prediction, actual output and one limitation; restore the original condition and repeat. | Trial | Input/configuration | Prediction | Observation | Evidence / limitation | |---|---|---|---|---| | A | Reference | | | | | B | Changed input | | | | | A repeat | Reference | | | | A conclusion is supported only when it cites the recorded values or observed states and explains them with the experiment theory.
Shared research workbenches · network designer & advanced studies
Concurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery research