Scientific architecture · Smart contract lifecycle, gas and atomic rollback
Scientific concept map: Caller — Function and inputs; Execution — Contract instructions; Gas budget — Cost accounting; Failure / revert — Discard state writes; Receipt — Status and gas.
Scientific foundations and analytical reasoning
A state-changing contract transaction has a gas limit and effective price. Revert rolls back state but can consume gas.
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.
BC-M09 · Academic orientation
Scope and objectives
Scope of the experiment
Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.
The focus of this experiment is to trace smart-contract deployment, invocation and state transitions. Students then interpret gas, successful execution and reversion, and explain why deterministic execution does not guarantee contract correctness. 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 smart-contract deployment, invocation and state transitions.
Interpret gas, successful execution and reversion.
Explain why deterministic execution does not guarantee contract correctness.
Identify the configured inputs (Lifecycle state; Call type; Initial contract state; Requested increment; Gas limit) 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 smart-contract deployment, invocation and state transitions, interpret gas, successful execution and reversion, and explain why deterministic execution does not guarantee contract correctness.
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 explain why deterministic execution does not guarantee contract correctness. 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 Solidity, Remix and access control.
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 · Transaction gas and rollback
A smart contract transaction has a gas limit, which caps allowable execution work; gas used is the actual accounted work. The effective gas price determines the fee. A reverted execution can consume gas while rolling back contract state changes. Read-only calls and submitted transactions are different interfaces.
Worked example and engineering interpretation
A successful transaction using 21000 gas at 20 gwei costs 420000 gwei = 0.00042 ETH. A limit of 50000 gas does not imply paying for all 50000. Compare state and receipt for the successful and reverted teaching cases.
Engineering principles · additional worked teaching example
State-changing contract calls consume execution resources and may revert. A view call can be read locally without a transaction. Fee=gasUsed×effectiveGasPrice; 25000 gas at 12 gwei/gas costs 300000 gwei=0.0003 ETH.
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: Lifecycle state = deployed; Call type = write; Initial contract state = 10; Requested increment = 5; Gas limit = 50000; Configured execution gas = 42000; Effective gas price (gwei) = 20; Explicit execution revert = false. In the classroom model, Receipt = Success; Final state = 15; Gas charged = 42000; Fee = 840000 gwei. The explicit gas requirement is a teaching input. Actual gas is obtained from an EVM receipt. State machine with explicitly configured gas cost; not an EVM, network client or gas estimator.
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 · 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.
Step 1 of 5 · Calculated state 1
Calculated state 1
Stage
Source / compilation
Observation
deployed
Calculated state 2
Stage
Invocation
Observation
write
Calculated state 3
Stage
Execution budget
Observation
50000 / required 42000
Calculated state 4
Stage
Receipt
Observation
Success
Calculated state 5
Stage
State committed
Observation
Yes
Teaching example only; inspect live calculations or real practical evidence separately.
How to investigate Smart contracts, lifecycle and gas
Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.
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: Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.
Start deployed, write, state 10, increment 5, gas limit 50,000, required 42,000 and effective price 20 gwei. Verify state 15 and fee 840,000 gwei.
Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit.
Restore limit and force an explicit revert; compare receipt, state and charged gas.
Switch to read only (eth_call model): inspect returned value, no transaction fee and no state update.
Reference check: Read-only local call does not pay a transaction fee. Failed included transactions can consume gas without committing contract state.
Model boundary: Fixed illustrative gas costs, not measured EVM gas. Use actual receipts in Remix for precise costs.
Independent task and submission evidence
2. Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit. 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.
Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.
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 explanationsHow many Wei equal one ETH?
10^18 Wei.
What is a Gwei?
10^9 Wei.
Why meter computation?
It bounds execution resources and charges for included work.
Can a reverted transaction consume gas?
Yes. Failed execution may still consume gas, without committing reverted state.
What is the difference between gas limit and gas used?
The limit bounds execution resources; gas used is the actual metered consumption.
What is the fee formula used in this model?
Gas used multiplied by effective gas price in Wei per gas.
Does a local read require an included transaction?
No, a read may be evaluated locally with no paid transaction.
Why should actual gas be taken from a receipt?
The illustrative cost table is not an EVM execution measurement.
What fee does a local read-only call pay in this model?
No transaction fee.
How is a transaction fee computed from consumed gas and effective gas price?
Multiply gas used by effective gas price; convert the units consistently.
Can a failed included operation charge gas without updating state?
Yes. Reversion rolls back contract state, not all execution cost.
Why vary gas limit independently of price?
The limit bounds execution gas, whereas price determines cost per gas unit.
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 state 10, increment 5, gas used 42000 and price 20 gwei, compute final state and fee in success; compare reverted state.
Engineering method — State-changing contract calls consume execution resources and may revert. A view call can be read locally without a transaction. Fee=gasUsed×effectiveGasPrice; 25000 gas at 12 gwei/gas costs 300000 gwei=0.0003 ETH. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
02 · Compare or justify using evidence
Compare gas limit 50000 with 40000 under the same execution demand. Explain why a read call and transaction have different costs.
Engineering method — State-changing contract calls consume execution resources and may revert. A view call can be read locally without a transaction. Fee=gasUsed×effectiveGasPrice; 25000 gas at 12 gwei/gas costs 300000 gwei=0.0003 ETH. Apply this method to the assigned values independently; compare your reasoning with the relevant simulator or practical implementation.
03 · Cost calculation
Cost calculation · Independent work
A state write consumes 42000 gas at 15 gwei/gas. Compute fee in ETH. Why can a reverted transaction still cost gas?
Cost calculation — State-changing contract calls consume execution resources and may revert. A view call can be read locally without a transaction. Fee=gasUsed×effectiveGasPrice; 25000 gas at 12 gwei/gas costs 300000 gwei=0.0003 ETH. 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-M09-01
Use the reference configuration (Lifecycle state = deployed; Call type = write; Initial contract state = 10; Requested increment = 5; Gas limit = 50000; Configured execution gas = 42000; Effective gas price (gwei) = 20; Explicit execution revert = false), but change Lifecycle state = source only. The model reports Receipt = Not submitted. Explain the governing rule and assumptions that make this output plausible; identify an independent verification method.
Intermediate · Interpret a state transition
Independent theoretical exercise · BC-M09-02
The reference model reports Receipt: Success. Under Lifecycle state = source only it reports Not submitted. 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 · BC-M09-03
For Initial contract state = 12, the model supplies this excerpt from Execution lifecycle:
Stage · Observation
Source / compilation · deployed
Invocation · write
Execution budget · 50000 / required 42000
Receipt · Success
State committed · Yes
Count rows whose Observation value is exactly “deployed”, and identify the displayed row numbers. Explain what the count describes.
Advanced · Reverse reasoning
Independent theoretical exercise · BC-M09-04
An observation is Final state = 17. Candidate A uses Lifecycle state = deployed; Call type = write; Initial contract state = 10; Requested increment = 5; Gas limit = 50000; Configured execution gas = 42000; Effective gas price (gwei) = 20; Explicit execution revert = false. Candidate B changes the listed settings (Initial contract state = 12) 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-M09-05
A student configures Requested increment = 7 while preserving all other reference settings, but copies the reference report of Final state = 15. Evaluate whether the report is justified. Identify the first configuration/output check to perform.
Challenging · Design a controlled verification
Independent theoretical exercise · BC-M09-06
Design a controlled comparison for Smart contracts, lifecycle and gas using reference Lifecycle state = deployed; Call type = write; Initial contract state = 10; Requested increment = 5; Gas limit = 50000; Configured execution gas = 42000; Effective gas price (gwei) = 20; Explicit execution revert = false and test Lifecycle state = source only. Specify the changed setting(s), measured metric Receipt, controls, repetitions, an acceptance check and what evidence can distinguish an actual implementation from the model.
Step-by-step experimental procedure
Explain how compilation/deployment differs from invocation, and quantify gas costs and atomic rollback.
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.
Lifecycle statedeployed
Call typewrite
Initial contract state10
Requested increment5
Gas limit50000
Configured execution gas42000
Effective gas price (gwei)20
Explicit execution revertNo
2 · Perform the investigation in order
Start deployed, write, state 10, increment 5, gas limit 50,000, required 42,000 and effective price 20 gwei. Verify state 15 and fee 840,000 gwei.
Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit.
Restore limit and force an explicit revert; compare receipt, state and charged gas.
Switch to read only (eth_call model): inspect returned value, no transaction fee and no state update.
Set lifecycle to compiled but not deployed. Explain why bytecode and ABI are not yet a callable on-chain instance.
Use the preserved Remix exercise for actual compilation, deployment, transactions and receipts. Compare actual gas rather than treating the configured execution gas as a measurement.
3 · Compare controlled trials
Trial
Independent change
Expected check
Observation
Successful write
Use reference inputs above
Receipt: Success; Final state: 15; Gas charged: 42000
Record actual result
Out of gas
Gas limit = 30000
Receipt: Out of gas; Final state: 10; Gas charged: 30000
Record actual result
Explicit revert
Explicit execution revert = Yes
Receipt: Reverted; Final state: 10
Record actual result
Read only
Call type = read
Gas charged: 0; Final state: 10
Record actual result
Not deployed
Lifecycle state = compiled
Receipt: Not submitted
Record actual result
4 · Analyze and report
Explain transaction fee versus gas units and why state rollback does not refund all gas. Discuss how partitioning execution/state can affect scalability.
Required evidence: Lifecycle trace, state before/after, fee arithmetic and actual Remix receipts if available.
Model boundary: State machine with explicitly configured gas cost; not an EVM, network client or gas estimator.
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
Successful write
Use reference inputs above
Record actual outcome and units
Out of gas
Gas limit = 30000
Record actual outcome and units
Explicit revert
Explicit execution revert = Yes
Record actual outcome and units
Read only
Call type = read
Record 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.
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: Fixed illustrative gas costs, not measured EVM gas. Use actual receipts in Remix for precise costs. Default computational cells passed isolated local Python execution; physical equipment and live services require separate verification.
01Instructions · Markdown
# BC-M09 · Smart contracts, lifecycle and gas
**PSUT IoT Engineering Studio — Dr. Mohammad Alja’afreh**
## 1. Scientific objective
Explain how compilation/deployment differs from invocation, and quantify gas costs and atomic rollback.
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
Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.
**Reference procedure (use the matching simulator/WSL tool where named, not an unrelated service):**
1. Start deployed, write, state 10, increment 5, gas limit 50,000, required 42,000 and effective price 20 gwei. Verify state 15 and fee 840,000 gwei.
2. Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit.
3. Restore limit and force an explicit revert; compare receipt, state and charged gas.
4. Switch to read only (eth_call model): inspect returned value, no transaction fee and no state update.
5. Set lifecycle to compiled but not deployed. Explain why bytecode and ABI are not yet a callable on-chain instance.
**Evidence:** Read-only local call does not pay a transaction fee. Failed included transactions can consume gas without committing contract state.
**Boundary:** Fixed illustrative gas costs, not measured EVM gas. Use actual receipts in Remix for precise costs.
03Instructions · Markdown
## 2. Reference configuration and investigation
1. Start deployed, write, state 10, increment 5, gas limit 50,000, required 42,000 and effective price 20 gwei. Verify state 15 and fee 840,000 gwei.
2. Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit.
3. Restore limit and force an explicit revert; compare receipt, state and charged gas.
4. Switch to read only (eth_call model): inspect returned value, no transaction fee and no state update.
5. Set lifecycle to compiled but not deployed. Explain why bytecode and ABI are not yet a callable on-chain instance.
6. Use the preserved Remix exercise for actual compilation, deployment, transactions and receipts. Compare actual gas rather than treating the configured execution gas as a measurement.
Run cells in order; do not substitute model results for physical measurements.
04Instructions · Markdown
## 3. Model execution gas and state rollback.
05Python · executable cell
PYTHON · Code cell
# =====================================================================
# BC-M09 | Code cell 01 | Smart contracts, lifecycle and gas
# Purpose: 3. Model execution gas and state rollback.
# 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 run; keep its logic separate from the trial.
def run(limit,required=42000,price=20):
ok=limit>=required
return (15 if ok else 10,min(limit,required)*price,ok)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert run(50000)==(15,840000,True)
# Check the expected invariant so a mismatch fails visibly instead of appearing successful.
assert run(30000)==(10,600000,False)
## 4. Compare fee at alternate effective prices (gwei).
07Python · executable cell
PYTHON · Code cell
# =====================================================================
# BC-M09 | Code cell 02 | Smart contracts, lifecycle and gas
# Purpose: 4. Compare fee at alternate effective prices (gwei).
# Inputs: the explicit fixture/settings below and any preceding cell state.
# Output: inspect printed values, returned records or assertions; record evidence.
# =====================================================================
# Repeat the same operation for each configured input so observations are comparable.
for p in (10,20,40):print(p,run(50000,price=p))
## 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. Reduce gas limit to 30,000 while keeping required work fixed. Verify out-of-gas receipt, unchanged state and gas charged at the limit. 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.
How many Wei equal one ETH?
10^18 Wei.
What is a Gwei?
10^9 Wei.
Why meter computation?
It bounds execution resources and charges for included work.
Can a reverted transaction consume gas?
Yes. Failed execution may still consume gas, without committing reverted state.
Applied task
Reduce the limit below the model gas requirement. Observe no state change and charged gas.
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-M09 · Smart contracts, lifecycle and gas. My task: Distinguish reads, transactions, gas budget and lifecycle. Calculate fees in Wei/Gwei/ETH with a user-declared gas price.. Acceptance: Read-only local call does not pay a transaction fee. Failed included transactions can consume gas without committing contract state.. Model boundary: Fixed illustrative gas costs, not measured EVM gas. Use actual receipts in Remix for precise costs.. 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