What a Smart Contract Is and How It Executes
A smart contract is code deployed at an address and run by every node. What determinism, immutability and verified source mean for a wallet screen.
A smart contract is a program that lives at a blockchain address. It has its own storage, its own balance of whatever assets the chain supports, and a set of functions that anyone can call by sending a transaction to that address. When a transaction reaches it, every node that validates the block runs the same code against the same inputs and must arrive at the same result. If the results differ, the block is invalid. That shared execution is the whole mechanism: the contract is not a service run by a company, it is a rule set that the network enforces by consensus.
The term covers more than tokens. A contract can hold funds in escrow, record ownership, enforce a vesting schedule, route a trade across several pools, or act as the entry point for a protocol made of dozens of other contracts. What they share is that their behaviour is fixed by bytecode, and the bytecode is what the network runs.
Code deployed at an address, not a file on a server
A contract is created by a deployment transaction. The transaction carries bytecode, the network executes a constructor, and the resulting code is stored at a new address derived from the sender and the nonce. From then on, the address has code. Calling a function means sending a transaction (or, for read-only functions, making a call) to that address with data that identifies which function to run and with what arguments.
That data is the calldata. The first four bytes are a selector, a hash-derived identifier for the function signature; the rest is the encoded arguments. This is why a wallet can show a contract interaction as a named function rather than a wall of hex, and why a mismatch between the name shown and the selector actually present matters. Tools exist to decode the calldata against a signature:
cast decode-calldata "approve(address,uint256)" 0x095ea7b3000000000000000000000000...
The output lists the function and each argument as decoded values. If the decoded arguments do not match what the interface described, the transaction is not the one the interface implied. The same reference documents selector lookup:
cast 4byte 0x095ea7b3
The output gives the function signature registered for that selector. A selector can in principle map to more than one signature, so treat the result as a strong hint, not proof, and confirm against the contract’s own source. Source: https://getfoundry.sh/cast/reference/decode-calldata (Foundry Book: cast decode-calldata); Source: https://getfoundry.sh/cast/reference/4byte (Foundry Book: cast 4byte).
Why every node reaches the same answer
Determinism is the property that makes a contract usable as an agreement. The code cannot read a clock, call an API, or consult a random number the way an ordinary program can, because those inputs would differ between nodes. Everything a contract acts on must come from the chain itself: its own storage, the transaction’s data, the block’s context, and the results of calls to other contracts. Where outside information is needed, an oracle contract writes it on-chain first, and the contract reads the recorded value.
This is also why execution costs gas. Each operation has a price so that nodes can bound the work a transaction may demand. A transaction that runs out of gas reverts: its state changes are discarded, but the gas spent is not returned. A revert is not a partial failure to be retried automatically; it is a defined outcome, and the contract’s code decides when to produce one.
Immutability, and the proxy pattern that bends it
Once deployed, a contract’s code cannot be edited. The bytecode at an address stays what it was. This is the property people mean when they say code is law: no administrator can rewrite the rules after the fact, and a function that releases funds on a condition will release them whenever that condition is met, whether or not anyone approves.
Many projects want to fix bugs or add features, so they deploy an upgradeable pattern. A proxy contract sits at a stable address and holds the storage; it forwards each call to an implementation contract whose address it records. Changing the implementation address changes the behaviour while the address users interact with stays the same. The storage layout must be preserved across upgrades, which is a source of subtle and serious bugs.
For a user, the practical consequence is that “the contract address” may not be the code that runs. An explorer will usually label a proxy and link to the current implementation. When reviewing what a contract does, check both: the proxy’s storage and admin functions, and the implementation’s logic. An upgradeable contract is only as trustworthy as whoever holds the upgrade authority, and that authority is often a multisig or a single key.
Reading verified source on an explorer
Explorers let a deployer publish source code and compiler settings so that the explorer can recompile and confirm the deployed bytecode matches. This is what “verified contract source” means: a match between published source and on-chain bytecode. It does not mean the code is correct, safe, or endorsed by the explorer. It means the readable code is the code that runs.
A short reading routine covers most of what a user needs:
- Confirm the address is the one the interface or documentation names, character by character, not by the token name shown.
- Check whether the contract is a proxy and, if so, read the implementation.
- Look at the write functions. Which ones move funds, change ownership, pause transfers, or set fees?
- Look at who can call the privileged functions. A function restricted to an owner or admin is a point of trust, and the identity of that owner matters.
- Check whether the source is verified at all. Unverified bytecode can still be interacted with, but nothing about its behaviour is readable.
A bug is a door anyone can open
On a public chain, every function is callable by anyone who can pay gas. There is no login, no allowlist unless the code enforces one, and no way to hide a function from the network. If a contract has a flaw that lets a caller withdraw more than they deposited, or re-enter a function before its state is updated, or pass a value that overflows a check, any address that notices can exploit it. Exploits are frequently executed by automated contracts within the same block that makes the flaw profitable.
This cuts both ways. The same openness that lets an attacker call a flawed function lets anyone verify that a function behaves as claimed. It also means that a contract holding user funds is a standing invitation to examine it. The absence of an incident so far is not evidence of correctness; it may only mean nobody has found the flaw yet.
An audit is a review, not a guarantee
A security audit is a time-boxed review by people who read code and look for ways to break it. A good audit produces findings, some of which are fixed before deployment. It does not prove the absence of bugs. Auditors work within a scope and a schedule, they can miss interactions between contracts, and they cannot foresee every economic condition the contract will face. An audit report describes what was examined and what was found; it is not a certification that funds are safe.
Treat an audit as one input among several: who wrote the code, how long it has run, how much value it holds, whether it can be upgraded and by whom, and whether the privileged functions are constrained. None of these is decisive alone.
Where a wallet signature meets contract logic
Most contract interactions a user encounters arrive as a signature request. Two requests deserve particular care. A token approval grants a contract permission to move a token on the user’s behalf, and the amount may be unlimited; the approval persists until it is revoked. Blind signing is approving a transaction whose contents the wallet cannot decode or display, which means the user is authorising calldata they have not read. Both are covered in their own guides: token approvals and blind signing.
A contract cannot take funds that were never approved and cannot act outside the rules in its code. The risk in a signature request is usually not that the contract will break its own rules, but that the rules permit more than the user understood, or that the request is for a different contract than the one the interface described.
What a smart contract cannot do
A contract cannot keep a secret. Its storage is public, and any value written to it can be read by anyone. It cannot act on its own; it runs only when a transaction calls it. It cannot undo a transaction that has been finalised, and it cannot recover assets sent to it unless its code provides a path to do so. It cannot verify anything about the world outside the chain except through data that another contract has already written on-chain. And it cannot be assumed safe because it is popular, audited, or old. Each of those is a reason to look, not a substitute for looking.
Common questions
What is a smart contract in simple terms?
It is a program deployed to a blockchain address. It has its own storage and balance, and its functions run when a transaction calls them. Every node executes the same code and must agree on the result, which is what makes the outcome enforceable without a company in the middle.
Can a smart contract be changed after it is deployed?
The code at an address cannot be edited. Many projects use a proxy: a stable address forwards calls to an implementation contract whose address can be changed. That makes behaviour upgradeable, and it puts trust in whoever controls the upgrade. Check whether the contract you are using is a proxy and who can change its implementation.
What does verified contract source mean?
It means the explorer recompiled published source code and confirmed it matches the bytecode at that address. It confirms the readable code is the code that runs. It says nothing about whether the code is correct or safe.
Does an audit mean a smart contract is safe?
No. An audit is a review within a scope and a schedule, and it can miss bugs and interactions. It is one input among several, alongside who wrote the code, how long it has run, what privileges exist, and whether it can be upgraded.
Why can anyone exploit a bug in a smart contract?
Every function on a public chain is callable by any address that can pay gas, and the code cannot be hidden. A flaw that lets a caller take more than they should is available to whoever finds it first, often through automated contracts.
Read next
- What DeFi Is: Smart Contracts That Call Each Other DeFi is a set of smart contracts for lending, trading and stablecoins that call each other. How the pieces fit, and where composability turns into risk.
- What a DAO Is: Governance, Voting, and Execution A DAO is a smart-contract-governed organisation. How governance tokens, on-chain and off-chain voting, multisigs, timelocks and treasuries actually work.
- Liquidity Pools: How They Work Learn how liquidity pools power decentralized exchanges, how fees are earned, and the risks like impermanent loss.
- Smart Contract Wallets: A Wallet That Is a Program Recovery without a seed phrase, spending limits and batched approvals, against deployment cost, per-chain addresses and dependence on the contract's code.
- Check a Transaction Before You Sign It Learn to read a signature request, verify a contract address, and understand approvals and permits before you sign. Essential security steps for crypto users.