EXCOIN / SMART CONTRACTS

Smart contracts with verifiable rules

Code that can execute a valuable operation without further approval calls for precise rules and realistic testing. Design begins with ownership, state and recovery.

01 / ENGINEERINGCS · EN · ES
01 / 08

When a rule belongs on-chain

A smart contract makes sense for a rule that independent participants need to verify for themselves. It may control a transfer, an entitlement or the state of a shared process. If a single operator can change every input and output, deploying a contract alone may not materially change trust. First identify participants, rights, commercial events and the facts that must later be provable. Compare the idea with an ordinary application that has a sound audit trail.

Not every rule belongs in an immutable environment. Frequently changing prices, language and exceptions may need management outside the contract, with an explicit approval process. Data from the outside world needs a trusted source; a contract cannot independently prove it correct just by recording it. A good design therefore keeps the boundary between chain and application narrow, understandable and justified by a concrete requirement.

02 / 08

Specification before code

The first deliverable is a state model: which operation may follow another, who may trigger it and what must happen when it is rejected. A value transfer may need to describe balances, reservations, cancellation, time limits and a counterparty that fails to cooperate. For roles, record who grants them and who can revoke authority. Add a transition table and examples of invalid calls to the prose specification. This reveals whether the proposed interface actually represents the business process.

Invariants are properties that must remain true after every operation: for example, a defined relationship between recorded value and transfers or the impossibility of an unauthorised role becoming an administrator. Writing them down improves tests and can support more formal verification. If the team cannot explain an invariant to the product owner, its implementation should not disappear into technical detail.

03 / 08

Access, governance and emergency powers

Anyone with network access may attempt to call a public function. Every state change needs explicit access checks, input validation and a response to unexpected call order. Privileged actions such as parameter changes, upgrades and pauses need a separate governance plan. Decide whether multiple signatures, a time delay or separated roles are appropriate. More signatures alone do little if one person controls all of them or there is no recovery procedure for a lost key.

An emergency pause may contain a defect but also grants its operators significant power. Users should understand what can be stopped, what remains accessible and how service resumes. Consider a failure to reach the people with authority: who decides on repair and how will they communicate? Governance is part of the product and should be visible before deployment.

04 / 08

Interactions and common security failures

Risk often sits at boundaries: one contract calls another, consumes a price from outside or allows an unexpected sequence of functions. State update order, external calls, arithmetic, return value checks and business logic all matter. A scanner cannot understand the full commercial intent. OWASP's public risk overview can structure discussion of weaknesses but cannot replace analysis of the specific money flow and access model.

For each flow, describe an attacker, their capabilities and motivation. Could they influence transaction order, supply delayed data, split an operation into several calls or misuse an administrator key? Testing should include assumptions about integrations and the interface. A correct contract cannot rescue an application that asks a user to sign a different action from the one the screen describes.

05 / 08

Test properties, not only examples

Basic tests cover the ordinary path, rejected input and value limits. Property based tests can add more value by trying many operation orders, boundary values and combinations of roles. When rules change, retain a regression suite linked to invariants. A test network helps rehearse actual signing and deployment, but it does not reproduce every economic incentive or production operating condition.

For a high risk contract, more formal methods can be considered for specific properties. Ethereum documentation explains formal verification as proving required behavior against a defined specification. A proof remains only as useful as its assumptions. Allow time for independent review, correction of findings and a second check before deployment. EXCOIN does not claim to be an independent auditor of its own work.

06 / 08

Upgrades and migration

The ability to change logic after deployment is a technical and organisational choice. An immutable contract limits administrator power but makes defects difficult to repair. An upgrade mechanism eases change while adding a privilege and the possibility of a bad state transition. Explain who proposes, approves and verifies changes and what happens to existing commitments. Users should know whether rules they accept today can be changed later by someone else.

A migration plan should cover data compatibility, old addresses, operations still in progress, accessible history and a way back if the step fails. Simulate the migration with representative state before a live change. External systems that consume events need to recognise a version change. Upgrade documentation is operational protection for users and connected applications, not an administrative afterthought.

07 / 08

Deployment, monitoring and response

Before deployment, check the exact source, configuration, network, administrator addresses and signing procedure. Record the resulting address and verified code so later reviewers can establish what is actually running. Monitor critical events outside the chain as well: role changes, unusual volume, pauses and failed integration indexers. An alert is useful only if someone knows what action follows it.

An incident plan defines who may pause a function, how users will be informed, what can be safely restored and when an external expert joins. After launch, keep track of new findings in libraries and dependencies. If operation needs regular intervention, include it in budget and responsibilities. It is misleading to call a contract maintenance free merely because its bytecode remains on a chain.

08 / 08

A useful brief and deliverable

For an initial assessment, describe participants, value or rights handled by the contract, sources of external facts, expected volume and the worst acceptable failure. Say whether rules should be changeable and who should govern that change. You need not prescribe a chain or library. A supplier should first test whether part of the process can remain off-chain more safely.

A clear deliverable includes a specification of states and roles, source code, tests, deployment procedure, assumptions, operating guide and a record of open risks. If an external audit is required, name its independent author and scope; the word secure does not substitute for it. Before acceptance, decide who holds keys, monitors operation and has authority in an emergency.

How do you know a contract is ready to deploy? Passing automated tests alone is insufficient. The owner of the rules must understand what will be hard to reverse, which exceptions remain off-chain and who holds administrative powers. The technical team should provide evidence of tests, review findings, corrections and the exact code version. Operators must know how to respond to an alert and rehearse loss of access. If one of those answers is missing, delay deployment rather than moving the uncertainty into a system where a mistake can harm real users.

Publishing source code by itself does not guarantee trust. Public code can be inspected, but people also need to know that it matches the deployed version, understand privileged roles and see the real operation before signing it. These checks connect technical, product and operating decisions.

Sources

Discuss a project