A contract write must pass checks before persistent state is changed
Scientific architecture · Solidity access, arithmetic, ABI and oracle behavior
Scientific concept map: Solidity interface — Function selector; Caller and arguments — ABI encoding; Modifier — Role / state guard; Contract storage — Mapping and variables; Event — Receipt and logs.
Scientific foundations and analytical reasoning
Solidity authorization and checked arithmetic govern state transitions; oracle freshness is an application rule. External calls can transfer control.
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.
Related course access:IoT Security and Privacy — same laboratory, notebook and completion record.
BC-M10 · Academic orientation
Scope and objectives
Scope of the experiment
Trace owner checks, mapping writes and emitted events. Compile and deploy a real small Solidity registry using Remix VM.
The focus of this experiment is to trace Solidity types, visibility and access-control checks. Students then predict state changes for authorized and unauthorized calls, and verify local Remix transactions and inspect revert 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 Solidity types, visibility and access-control checks.
Predict state changes for authorized and unauthorized calls.
Verify local Remix transactions and inspect revert evidence.
Identify the configured inputs (Function / experiment; msg.sender; Stored uint8; Increment / requested withdrawal; Oracle data age (s)) 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 Solidity types, visibility and access-control checks, predict state changes for authorized and unauthorized calls, and verify local Remix transactions and inspect revert 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 local Remix transactions and inspect revert evidence. Separate predicted values from observations.
Prerequisite knowledge and related learning
Review the foundational terminology in Concepts and confirm readiness using the existing setup instructions. After completion, continue to Blockchain for IoT: food cold-chain traceability.
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.
Scientific theory · Solidity semantics and access control
Solidity contract storage persists across successful transactions; memory and calldata have different lifetimes and mutability. ABI encodes calls and return values. Modifiers enforce caller or state predicates, while events provide logs. Oracle freshness must be explicitly checked; external calls create additional control-flow boundaries.
Worked example and engineering interpretation
An owner-only setter must reject a non-owner without changing storage. A fresh authenticated sensor value can pass a defined timestamp rule, while a stale one must not. In Remix's local VM, inspect the actual compiler result, receipt, storage and event rather than infer execution from the source.
Engineering principles · additional worked teaching example
Solidity state persists across transactions; msg.sender identifies the immediate caller. In Solidity 0.8 checked arithmetic, uint8 ranges 0…255; adding 10 to 250 reverts unless explicitly unchecked. Reverts roll back state.
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.
Worked engineering reasoning and boundary conditions
Engineering reference configuration: Function / experiment = increment; msg.sender = owner; Stored uint8 = 20; Increment / requested withdrawal = 10; Oracle data age (s) = 20; Maximum oracle age (s) = 60; Arithmetic policy = checked; Withdrawal ordering = checks-effects-interactions; External callback attempted = true. In the classroom model, Execution = Committed; State = 30; Event = ValueUpdated(30); Callback result = Not applicable. This represents the selected contract behavior explicitly. Compile and execute the actual Solidity source in Remix to verify bytecode and receipts. Typed state-machine model, not Solidity compilation or EVM execution. The withdrawal ordering is a defensive conceptual model, not an exploit or a live contract.
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 · Modifier
Modifier
Modifier
Pass
Typed calculation / oracle
Modifier
Pass
Typed calculation / oracle
Evaluated
Storage
Modifier
Pass
Typed calculation / oracle
Evaluated
Storage
30
Event
Modifier
Pass
Typed calculation / oracle
Evaluated
Storage
30
Event
ValueUpdated(30)
Teaching example only; inspect live calculations or real practical evidence separately.
How to investigate Solidity, Remix and access control
Trace owner checks, mapping writes and emitted events. Compile and deploy a real small Solidity registry using Remix VM.
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: Trace owner checks, mapping writes and emitted events. Compile and deploy a real small Solidity registry using Remix VM.
Run increment with owner, stored uint8 20, increment 10 and checked arithmetic. Inspect the function signature, input arguments, new value and event.
Choose guest; the only-owner fixture rejects before arithmetic and no event is emitted.
Set value 250 and increment 10. Compare checked revert with unchecked wrap to 4. Identify why uint8 cannot represent 260.
Select setOracle and set age 90 against maximum 60; the stale data must not update state. Restore a fresh reading.
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 guest; the only-owner fixture rejects before arithmetic and no event is emitted. 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.
Trace owner checks, mapping writes and emitted events. Compile and deploy a real small Solidity registry using Remix VM.
Learning goals
Explain the mechanism using the actual intermediate states in this experiment.
Predict and verify the reference and modified conditions described below.
Interpret the acceptance criteria and identify the limits of the model.
Module flashcards · 12 questions
Browse all 12 questions and explanationsWhat is msg.sender?
The immediate caller of the Solidity execution context.
What does a mapping represent?
Key-to-value storage with default values.
What is emitted on successful setDevice?
A DeviceStatus event.
What is the distinction between ABI and bytecode?
The ABI describes interfaces; bytecode is executable EVM code.
What is a function modifier used for?
Reusing a precondition such as access control before function execution.
What should a non-owner registry write do?
Revert without updating state or committing a success event.
Why use Remix VM?
To compile and execute contracts in a local simulated blockchain environment without real Ether.
What is the checks-effects-interactions pattern?
Validate conditions, update state, then perform external calls to reduce reentrancy risk.
What changes after the owner calls setDevice successfully?
The device mapping is updated and DeviceStatus is emitted.
What should remain unchanged when an outsider calls setDevice?
The contract state, because the access check reverts the call.
Which caller identity is checked by the contract?
msg.sender.
What evidence distinguishes an actual Remix VM execution from the browser model?
A transaction receipt and observed contract state from Remix VM.
Loading experiment-specific apparatus…Previous model / additional reference tools
Loading computational workbench…
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
For uint8=250, increment 10, compare checked and wrapping arithmetic. Evaluate an age 61 s against max age 60 s.
Engineering method — Solidity state persists across transactions; msg.sender identifies the immediate caller. In Solidity 0.8 checked arithmetic, uint8 ranges 0…255; adding 10 to 250 reverts unless explicitly unchecked. Reverts roll back state. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Compare or justify using evidence
Draw checks–effects–interactions for a fictional withdrawal and explain how authorization and state update ordering protect invariants.
Engineering method — Solidity state persists across transactions; msg.sender identifies the immediate caller. In Solidity 0.8 checked arithmetic, uint8 ranges 0…255; adding 10 to 250 reverts unless explicitly unchecked. Reverts roll back state. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Boundary debugging
Boundary debugging · Independent work
Owner can increment a uint8 counter initially 245. Predict increment by 10, then by 1, then an outsider increment by 1. State compiler assumption.
Boundary debugging — Solidity state persists across transactions; msg.sender identifies the immediate caller. In Solidity 0.8 checked arithmetic, uint8 ranges 0…255; adding 10 to 250 reverts unless explicitly unchecked. Reverts roll back state. 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 · BC-M10-01
Use the reference configuration (Function / experiment = increment; msg.sender = owner; Stored uint8 = 20; Increment / requested withdrawal = 10; Oracle data age (s) = 20; Maximum oracle age (s) = 60; Arithmetic policy = checked; Withdrawal ordering = checks-effects-interactions; External callback attempted = true), but change Function / experiment = setOracle. The model reports State = 10. Explain the governing rule and assumptions that make this output plausible; identify an independent verification method.
Intermediate · Quantitative comparison
Independent theoretical exercise · BC-M10-02
Two model observations of State are 30 (reference) and 10 (changed condition). Compute signed change and, when the reference is nonzero, percentage change. Explain why units matter.
Intermediate · Interpret a technical trace
Independent theoretical exercise · BC-M10-03
For Stored uint8 = 22, the model supplies this excerpt from Contract function inspector:
Field · Value
Function signature · increment(uint8)
Visibility / mutability · external nonpayable (model)
Argument · 10
Caller · owner
Access modifier · Yes
Count rows whose Value value is exactly “increment(uint8)”, and identify the displayed row numbers. Explain what the count describes.
Advanced · Reverse reasoning
Independent theoretical exercise · BC-M10-04
An observation is State = 32. Candidate A uses Function / experiment = increment; msg.sender = owner; Stored uint8 = 20; Increment / requested withdrawal = 10; Oracle data age (s) = 20; Maximum oracle age (s) = 60; Arithmetic policy = checked; Withdrawal ordering = checks-effects-interactions; External callback attempted = true. Candidate B changes the listed settings (Stored uint8 = 22) 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 · BC-M10-05
A student configures Increment / requested withdrawal = 12 while preserving all other reference settings, but copies the reference report of State = 30. Evaluate whether the report is justified. Identify the first configuration/output check to perform.
Challenging · Design a controlled verification
Independent theoretical exercise · BC-M10-06
Design a controlled comparison for Solidity, Remix and access control using reference Function / experiment = increment; msg.sender = owner; Stored uint8 = 20; Increment / requested withdrawal = 10; Oracle data age (s) = 20; Maximum oracle age (s) = 60; Arithmetic policy = checked; Withdrawal ordering = checks-effects-interactions; External callback attempted = true and test Function / experiment = setOracle. Specify the changed setting(s), measured metric State, controls, repetitions, an acceptance check and what evidence can distinguish an actual implementation from the model.
Step-by-step experimental procedure
Explain Solidity value types, access modifiers, view/write calls, event behavior, oracle checks and a defensive interaction-ordering model.
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.
Function / experimentincrement
msg.senderowner
Stored uint820
Increment / requested withdrawal10
Oracle data age (s)20
Maximum oracle age (s)60
Arithmetic policychecked
Withdrawal orderingchecks-effects-interactions
External callback attemptedYes
2 · Perform the investigation in order
Run increment with owner, stored uint8 20, increment 10 and checked arithmetic. Inspect the function signature, input arguments, new value and event.
Choose guest; the only-owner fixture rejects before arithmetic and no event is emitted.
Set value 250 and increment 10. Compare checked revert with unchecked wrap to 4. Identify why uint8 cannot represent 260.
Select setOracle and set age 90 against maximum 60; the stale data must not update state. Restore a fresh reading.
Select read; verify no state change. Compare view invocation with a transaction.
Select withdraw and compare the defensive checks-effects-interactions ordering with interaction-first in this isolated model. Explain why updating state and guarding callbacks before external interaction matters.
Open the bundled Solidity/Remix examples; compile, inspect ABI and bytecode, deploy in Remix VM, then compare actual call and event results.
Function / experiment = setOracle; Oracle data age (s) = 90
Execution: Reverted
Record actual result
Safe withdrawal
Function / experiment = withdraw
Callback result: Denied by updated balance/guard
Record actual result
4 · Analyze and report
Relate the selected function, modifier, typed arithmetic and events to the source contract. Discuss oracle trust and contract security without assuming blockchain immutability makes code safe.
Required evidence: Function/argument trace, checked and unchecked results, stale-oracle result and actual Remix evidence.
Model boundary: Typed state-machine model, not Solidity compilation or EVM execution. The withdrawal ordering is a defensive conceptual model, not an exploit or a live contract.
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.
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…
Engineering notebook
SOLIDITY · Source code
// SPDX-License-Identifier: MIT
pragma solidity0.8.28;/// @notice Fictional device identities; do not register personal data.
contractDeviceRegistry{addresspublic immutable owner;mapping(address=>bool)public active;eventDeviceStatus(addressindexed device,boolenabled);
error NotOwner();
error InvalidDevice();constructor(){ owner =msg.sender;}functionsetDevice(addressdevice,boolenabled)external{if(msg.sender!= owner) revert NotOwner();if(device ==address(0)) revert InvalidDevice();
active[device]= enabled;
emit DeviceStatus(device, enabled);}}
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
# BC-M10 · Solidity, Remix and access control
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## 1. Scientific objective
Explain Solidity value types, access modifiers, view/write calls, event behavior, oracle checks and a defensive interaction-ordering model.
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
Trace owner checks, mapping writes and emitted events. Compile and deploy a real small Solidity registry using Remix VM.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. Run increment with owner, stored uint8 20, increment 10 and checked arithmetic. Inspect the function signature, input arguments, new value and event.
2. Choose guest; the only-owner fixture rejects before arithmetic and no event is emitted.
3. Set value 250 and increment 10. Compare checked revert with unchecked wrap to 4. Identify why uint8 cannot represent 260.
4. Select setOracle and set age 90 against maximum 60; the stale data must not update state. Restore a fresh reading.
5. Select read; verify no state change. Compare view invocation with a transaction.
**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. Run increment with owner, stored uint8 20, increment 10 and checked arithmetic. Inspect the function signature, input arguments, new value and event.
2. Choose guest; the only-owner fixture rejects before arithmetic and no event is emitted.
3. Set value 250 and increment 10. Compare checked revert with unchecked wrap to 4. Identify why uint8 cannot represent 260.
4. Select setOracle and set age 90 against maximum 60; the stale data must not update state. Restore a fresh reading.
5. Select read; verify no state change. Compare view invocation with a transaction.
6. Select withdraw and compare the defensive checks-effects-interactions ordering with interaction-first in this isolated model. Explain why updating state and guarding callbacks before external interaction matters.
7. Open the bundled Solidity/Remix examples; compile, inspect ABI and bytecode, deploy in Remix VM, then compare actual call and event results.
Run cells in order; do not substitute model results for physical measurements.
04Instructions · Markdown
## 3. Trace an owner-only checked uint8 state write.
05Python · executable cell
PYTHON · Code cell
# =====================================================================
# BC-M10 | Code cell 01 | Solidity, Remix and access control
# Purpose: 3. Trace an owner-only checked uint8 state write.
# 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 increment; keep its logic separate from the trial.
def increment(caller,old,n):
if caller!="owner":return old,"unauthorized"
if old+n>255:return old,"overflow"
return old+n,"event"
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert increment("owner",20,10)==(30,"event")
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert increment("guest",20,10)==(20,"unauthorized")
## 4. Test checked overflow, then verify actual Solidity in Remix.
07Python · executable cell
PYTHON · Code cell
# =====================================================================
# BC-M10 | Code cell 02 | Solidity, Remix and access control
# Purpose: 4. Test checked overflow, then verify actual Solidity in Remix.
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert increment("owner",250,10)==(250,"overflow")
print(increment("owner",250,10))
## 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 guest; the only-owner fixture rejects before arithmetic and no event is emitted. 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.
Formative assessment
Explain the following without looking at the simulation output, then reveal the reference response.
What is msg.sender?
The immediate caller of the Solidity execution context.
What does a mapping represent?
Key-to-value storage with default values.
What is emitted on successful setDevice?
A DeviceStatus event.
What is the distinction between ABI and bytecode?
The ABI describes interfaces; bytecode is executable EVM code.
Applied task
Repeat as outsider; verify unchanged mapping and no successful event.
Submit your reference and modified observations with a justification.
The original tutor and adaptive examination retain their existing 102-lab catalogue. Use the module-specific study questions above and copy this contextual prompt into your chosen AI assistant if needed.
Explain the engineering mechanism in BC-M10 · Solidity, Remix and access control. My task: Trace owner checks, mapping writes and emitted events. Compile and deploy a real small Solidity registry using Remix VM.. Acceptance: 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.. Ask me for my actual observations and distinguish model predictions from real measurements.
Shared research workbenches · network designer & advanced studiesConcurrent-device simulation & Monte Carlo research