Learning outcome: Use msg.sender, mappings, custom errors and events to enforce administrative authorization.
Use fictional values only. Browser models work offline; actual Solidity compilation and Remix VM require the external Remix IDE and initial compiler download. No real funds or private credentials.
Predict: Write down the expected positive and negative outcomes in the notebook before proceeding.
Related course access:IoT Security and Privacy — same laboratory, notebook and completion record.
B05 · Academic orientation
Scope and objectives
Scope of the experiment
Use msg.sender, mappings, custom errors and events to enforce administrative authorization.
The focus of this experiment is to trace device registration, identity checks and role authorization. Students then predict authorized and unauthorized contract calls, and verify registry state and rejection evidence. 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
Trace device registration, identity checks and role authorization.
Predict authorized and unauthorized contract calls.
Verify registry state and rejection evidence.
Identify the configured inputs (Caller; Requested action; Initial sensor active; Fictional device ID) 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 trace device registration, identity checks and role authorization, predict authorized and unauthorized contract calls, and verify registry state and rejection evidence.
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 verify registry state and rejection evidence. Separate predicted values from observations.
Prerequisite knowledge and related learning
Review the following catalogue prerequisites before starting. After completion, continue to B06 · Telemetry commitments and replay resistance.
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.
Scientific concept map: Owner account — Register device; Device registry — Active mapping; Caller — Role identity; Authorization — Allowed function; Storage — State change or revert.
Scientific foundations and analytical reasoning
Contract authorization derives from caller identity and explicit policy. Mapping state and event logs reflect successful transactions.
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 · On-chain registry authorization
A device registry maps identifiers to owners or authorized roles. Caller identity is derived from the transaction context, not a user-provided claim. State transitions must enforce enrollment, update and revocation policy. An event can aid audit but does not replace verifying stored state.
Worked example and engineering interpretation
If owner A registers device 7, unauthorized B must not be able to change that registry entry. A successful owner-authorized update changes the stored mapping and may emit an event. Test unauthorized and duplicate registration independently in the provided local contract.
Engineering principles · additional worked teaching example
Registry authorization is distinct from device active status. A registered device can be revoked; its identifier remains a record but its future submissions must fail active-status check.
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 B05 · IoT device registry and access control
Use msg.sender, mappings, custom errors and events to enforce administrative authorization.
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: Use msg.sender, mappings, custom errors and events to enforce administrative authorization.
Start inactive, choose owner register, inspect state and event.
Choose viewer register and verify NotOwner with unchanged state.
Set initial active true and revoke as owner. Confirm disabled state.
Use viewer lookup and compare with the rejected viewer write.
Reference check: Owner call updates mapping and emits DeviceStatus; outsider call reverts and leaves state unchanged. Save the actual Remix transaction receipts separately.
Model boundary: Browser is a state-machine model, not a Solidity compiler or EVM. Solidity 0.8 uses checked arithmetic by default; do not use selfdestruct as a general upgrade mechanism.
Independent task and submission evidence
2. Choose viewer register and verify NotOwner with unchanged state. 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.
Trial
Changed setting
Fixed settings
Predicted result
Actual observation / units
Evidence / uncertainty
A: baseline
Reference
Record
Predict
Record
Record
B: one change
Record
Same as A
Predict
Record
Record
A: repeat
Restore
Same as A
Predict
Record
Record
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.
Worked engineering reasoning and boundary conditions
Engineering reference configuration: Caller = owner; Requested action = register; Initial sensor active = false; Fictional device ID = sensor. In the classroom model, Decision = Accepted; Sensor active = Yes. A rejected write leaves the registry unchanged. Owner-based state-machine fixture; not actual Solidity execution.
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.
Concept animation · operation pathway
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.
Step 1 of 4 · Access check
Access check
Access check
Owner
Before
Access check
Owner
Before
No
After
Access check
Owner
Before
No
After
Yes
Event
Access check
Owner
Before
No
After
Yes
Event
DeviceStatus
Teaching example only; inspect live calculations or real practical evidence separately.
Recall the concept before revealing its explanation.
0 / 3 revealed
B05 · 01 / 08Why use msg.sender?Reveal explanation
Engineering explanation
It identifies the immediate caller; tx.origin is inappropriate for this access policy.
B05 · 02 / 08What is a revert?Reveal explanation
Engineering explanation
It discards state changes from the failed execution; a submitted failed transaction may consume gas.
B05 · 03 / 08Does an Ethereum address prove a real sensor identity?Reveal explanation
Engineering explanation
No. Secure device provisioning and off-chain identity binding are separate requirements.
B05 · 04 / 08What makes a role check useful in a registry?Reveal explanation
Engineering reasoning
It restricts modification of device state to permitted principals.
B05 · 05 / 08Why read registry state after a rejected action?Reveal explanation
Engineering reasoning
The denial should leave persistent state unchanged; error text alone does not demonstrate that property.
B05 · 06 / 08A device registry enforces administrator permissions. Select every technically valid statement.
A. Check msg.sender against the authorization rule.
B. Test an unauthorized caller as a negative control.
C. An emitted event substitutes for access control.
D. Every caller is necessarily the contract owner.Reveal explanation
Applied scenario
Correct: A. Check msg.sender against the authorization rule.; B. Test an unauthorized caller as a negative control.
B05 · 07 / 08How do you carry out 5. Revoke correctly?Reveal explanation
Implementation recall
Return to account 0 and call setDevice(account 1,false).
B05 · 08 / 08For B05 · IoT device registry and access control, which actual output or state confirms the prescribed practical run succeeded, and what does it not establish?Reveal explanation
Evidence & acceptance
Compile DeviceRegistry.sol using B04 settings. Deploy from account 0, save account 1 address. Verify owner/account 0 and active(account 1)=false. From account 0 setDevice(account 1,true); read true and event. Switch account 2, attempt setDevice(account 1,false), require NotOwner revert and unchanged true. Return account 0, revoke and verify false. A network/compilation error is not a valid negative control.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research
Distributed digital twin · topology, protocol & battery researchLoading experiment-specific apparatus…Previous model / additional reference tools
Simulation task
Use msg.sender, mappings, custom errors and events to enforce administrative authorization.
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 workbenchB05 · Existing model
Interactive simulation
The model is an independent teaching abstraction, not Solidity execution or Ethereum consensus. SHA-256 uses actual browser cryptography when available.
Browser ledger / digest abstraction; not EVM transaction execution.
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.
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.
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.
Run & verify — acceptance checklist
Build verification: Authorization model tested; actual Solidity compilation/EVM pending.
Compile DeviceRegistry.sol using B04 settings. Deploy from account 0, save account 1 address. Verify owner/account 0 and active(account 1)=false. From account 0 setDevice(account 1,true); read true and event. Switch account 2, attempt setDevice(account 1,false), require NotOwner revert and unchanged true. Return account 0, revoke and verify false. A network/compilation error is not a valid negative control.
Record the actual output, source (mock/model or physical), and any error. A missing tool, timeout or untested external service is not a pass.
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
Construct owner/nonowner registration decisions for inactive and active sensor entries using the lab policy.
Engineering method — Registry authorization is distinct from device active status. A registered device can be revoked; its identifier remains a record but its future submissions must fail active-status check. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Compare or justify using evidence
Trace register→duplicate register→revoke and explain which transitions should leave unchanged state on failure.
Engineering method — Registry authorization is distinct from device active status. A registered device can be revoked; its identifier remains a record but its future submissions must fail active-status check. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Access control
Access control · Independent work
Owner registers A, outsider requests revoke A, owner revokes A, then A submits telemetry. Trace active status and allowed operations.
Access control — Registry authorization is distinct from device active status. A registered device can be revoked; its identifier remains a record but its future submissions must fail active-status check. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
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 · B05-01
Use the reference configuration (Caller = owner; Requested action = register; Initial sensor active = false; Fictional device ID = sensor), but change Caller = sensor. The model reports Decision = NotOwner. Explain the governing rule and assumptions that make this output plausible; identify an independent verification method.
Intermediate · Interpret a state transition
Independent theoretical exercise · B05-02
The reference model reports Decision: Accepted. Under Caller = sensor it reports NotOwner. 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 · B05-03
For Requested action = revoke, the model supplies this excerpt from Registry transition:
Device · Caller · Action · Before · After · Event
sensor · owner · revoke · No · No · DeviceStatus(false)
Count rows whose Caller value is exactly “owner”, and identify the displayed row numbers. Explain what the count describes.
Advanced · Reverse reasoning
Independent theoretical exercise · B05-04
An observation is Sensor active = No. Candidate A uses Caller = owner; Requested action = register; Initial sensor active = false; Fictional device ID = sensor. Candidate B changes the listed settings (Requested action = revoke) 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 · B05-05
A student configures Caller = viewer while preserving all other reference settings, but copies the reference report of Decision = Accepted. Evaluate whether the report is justified. Identify the first configuration/output check to perform.
Challenging · Design a controlled verification
Independent theoretical exercise · B05-06
Design a controlled comparison for B05 · IoT device registry and access control using reference Caller = owner; Requested action = register; Initial sensor active = false; Fictional device ID = sensor and test Caller = sensor. Specify the changed setting(s), measured metric Decision, controls, repetitions, an acceptance check and what evidence can distinguish an actual implementation from the model.
Step-by-step experimental procedure
Verify the owner-only device registry and separate read permission from write permission.
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.
Callerowner
Requested actionregister
Initial sensor activeNo
Fictional device IDsensor
2 · Perform the investigation in order
Start inactive, choose owner register, inspect state and event.
Choose viewer register and verify NotOwner with unchanged state.
Set initial active true and revoke as owner. Confirm disabled state.
Use viewer lookup and compare with the rejected viewer write.
Deploy the bundled DeviceRegistry contract locally in Remix and reproduce registration, lookup, unauthorized call and revocation.
3 · Compare controlled trials
Trial
Independent change
Expected check
Observation
Owner registers
Use reference inputs above
Decision: Accepted; Sensor active: Yes
Record actual result
Viewer attempts register
Caller = viewer
Decision: NotOwner; Sensor active: No
Record actual result
Owner revokes
Requested action = revoke; Initial sensor active = Yes
Explain how logical registry membership differs from device authentication.
Required evidence: Registry state, role decisions and actual local contract evidence.
Model boundary: Owner-based state-machine fixture; not actual Solidity execution.
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.
Trial
Independent change
Dependent observation
Owner registers
Use reference inputs above
Record actual outcome and units
Viewer attempts register
Caller = viewer
Record actual outcome and units
Owner revokes
Requested action = revoke; Initial sensor active = Yes
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.
Compare each observation with its expected result. If a check fails, identify whether the issue is the environment, contract selection, caller identity, sequence, byte encoding or model setup. Do not infer success from a timeout or a missing receipt. In Remix inspect the compiler errors and revert message; do not bypass the negative control.
Reset the browser model for a fresh run. Resetting Remix VM removes its deployed state. Keep screenshots and receipts before reset. For actual EVM execution, save compiler/fork/settings and transaction receipts. Explain limitations and propose one additional independent test.
Download this notebook and open Google Colab. Select File → Upload notebook and choose the downloaded .ipynb.
Read the Markdown instructions before each executable cell. Use a Python runtime, run cells from top to bottom, and resolve imports if necessary.
Perform the baseline and controlled changes. Save the notebook with actual outputs and your written interpretation.
Execution scope: Browser is a state-machine model, not a Solidity compiler or EVM. Solidity 0.8 uses checked arithmetic by default; do not use selfdestruct as a general upgrade mechanism. Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# B05 · B05 · IoT device registry and access control
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## 1. Scientific objective
Verify the owner-only device registry and separate read permission from write permission.
Complete the analytical worksheet in the portal first. Record your predictions before running this notebook. This notebook is a bounded local computational investigation; use the portal’s separate WSL, hardware or Remix procedure for real interfaces.
02Instructions · Markdown
## Experiment-specific preparation
Use msg.sender, mappings, custom errors and events to enforce administrative authorization.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. Start inactive, choose owner register, inspect state and event.
2. Choose viewer register and verify NotOwner with unchanged state.
3. Set initial active true and revoke as owner. Confirm disabled state.
4. Use viewer lookup and compare with the rejected viewer write.
5. Deploy the bundled DeviceRegistry contract locally in Remix and reproduce registration, lookup, unauthorized call and revocation.
**Evidence:** Owner call updates mapping and emits DeviceStatus; outsider call reverts and leaves state unchanged. Save the actual Remix transaction receipts separately.
**Boundary:** Browser is a state-machine model, not a Solidity compiler or EVM. Solidity 0.8 uses checked arithmetic by default; do not use selfdestruct as a general upgrade mechanism.
03Instructions · Markdown
## 2. Reference configuration and investigation
1. Start inactive, choose owner register, inspect state and event.
2. Choose viewer register and verify NotOwner with unchanged state.
3. Set initial active true and revoke as owner. Confirm disabled state.
4. Use viewer lookup and compare with the rejected viewer write.
5. Deploy the bundled DeviceRegistry contract locally in Remix and reproduce registration, lookup, unauthorized call and revocation.
Run cells in order; do not substitute model results for physical measurements.
04Instructions · Markdown
## 3. Model owner/operator access decisions.
05Python · executable cell
PYTHON · Code cell
# =====================================================================
# B05 | Code cell 01 | B05 · IoT device registry and access control
# Purpose: 3. Model owner/operator access decisions.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Define the reusable operation register; keep its logic separate from the trial.
def register(caller,active):
if caller!="owner":return active,"NotOwner"
return True,"Registered"
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert register("owner",False)==(True,"Registered")
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert register("viewer",False)==(False,"NotOwner")
## 4. Model delegation and revocation; verify state is unchanged on denial.
07Python · executable cell
PYTHON · Code cell
# =====================================================================
# B05 | Code cell 02 | B05 · IoT device registry and access control
# Purpose: 4. Model delegation and revocation; verify state is unchanged on denial.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Set operators for the next computation or reference condition.
operators=set()
# Define the reusable operation delegate; keep its logic separate from the trial.
def delegate(caller,person,allowed):
if caller!="owner":return False
if allowed:operators.add(person)
else:operators.discard(person)
return True
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert delegate("owner","operator",True)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert not delegate("viewer","guest",True)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert delegate("owner","operator",False) and not operators
## Experimental analysis and submission
1. Record the reference input, predicted output and actual result.
2. Modify one independent variable and run the relevant cells again.
3. Explain the result using the theory and identify model limitations.
4. Save the notebook with outputs and retain the separate theoretical worksheet.
**Your derivation and conclusion:**
(Complete independently.)
09Instructions · 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. Choose viewer register and verify NotOwner with unchanged state. 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.