Back to Syllabus
Chapter 07Advanced Silicon - Verified

Invariant Smart Contracts & Web3

Write reentrancy-free, gasless smart contracts with enforced value conservation invariants.

This lesson uses the verified core subset and links to a checked-in regression program. Its output is covered by the repository test harness. This does not imply support for features outside the lesson; see known limitations.

What you'll learn

✓Eliminate Solidity reentrancy bugs with state mutexes
✓Enforce invariant(total_before == total_after)
✓Create deterministic state containers
✓Verify mathematical conservation on silicon VM

Beyond Solidity: Invariant Smart Contracts

AAYU solves Solidity's notorious reentrancy vulnerabilities at the architectural level using std/chain.aayu and std/contracts.aayu.

aayu
import "std/chain.aayu"

let contract = create_contract_state("AAYU Silicon Coin (ASC)", 1000000, {
    "0xAlice": 100000,
    "0xBob": 25000
})

contract = execute_safe_transfer(contract, "0xAlice", "0xBob", 15000)
print("Alice Balance: " + contract["balances"]["0xAlice"])
print("Bob Balance:   " + contract["balances"]["0xBob"])

Run 'bin/aayu.exe run examples/creative_silicon_demo.aayu' to verify.

Try It Yourself! 🚀

Attempt an illegal transfer where the amount exceeds Alice's balance. Confirm that the contract safely aborts with an insufficient balance error without altering state.