Omegyu vs. Solidity
Solidity contracts and tools can call Omegyu contracts through the Solidity ABI. Behind that interface, Omegyu lets you write a function once for many types and express constraints on its inputs.
You don’t need a wrapper to call an Omegyu contract from Solidity. Export a method through the Solidity ABI and a caller uses the usual Solidity interface and the deployed address. The difference is in what the contract author can express, not in how callers have to encode the call.
To write one yourself, start with your first contract: compare two complete Counters, deploy with 10, then change what one increment does.
Call an Omegyu contract from Solidity
Here is a Solidity caller for Counter, whose implementation is written in Omegyu:
interface ICounter {
function count() external view returns (uint256);
}
contract Reader {
function read(ICounter counter) external view returns (uint256) {
return counter.count();
}
}Pass Counter’s deployed address to read. Solidity sends the four-byte selector 0x06661abd for count() and decodes the reply as a uint256. A client library can make the same call using the generated Counter.abi.json. In the other direction, an Omegyu contract can call a Solidity contract through a matching ABI declaration.
Compatibility is per exported method. Counter exposes one read handler as count() on the Solidity ABI and read on its native interface. Its addAll method is native-only: writing a Solidity interface with that name would not make it callable through the ABI. Follow both routes to the handler.
What changes behind that familiar interface? Consider two operations on a batch.
One definition for many element types
Suppose a batch may be empty. You want its first element if there is one, and a default otherwise. The operation never inspects the element. Why should it care whether the batch contains counts or flags?
let firstOr : forall {a : Type} -> a -> List a -> a
= \fallback xs -> std:Optional.default fallback (std:List.head xs)
in { count = firstOr 0 [ 7, 8 ], flag = firstOr True ([] : List Bool) }Normal form
{ count = 7, flag = True }a is a parameter of your function, not a particular data type. At the first call it stands for Natural; at the second it stands for Bool. In each call the default, the elements and the result must agree on that type. You don't cast the result back from bytes.
Solidity has arrays and mappings parameterized by types, but its function declarations have no user-defined type parameters. You can put the operation in a library and overload its name. Solc checks which concrete signature fits each call; the library still needs a definition for each element type it supports:
library Batch {
function firstOr(uint256 fallbackValue, uint256[] memory xs) internal pure returns (uint256) {
return xs.length == 0 ? fallbackValue : xs[0];
}
function firstOr(bool fallbackValue, bool[] memory xs) internal pure returns (bool) {
return xs.length == 0 ? fallbackValue : xs[0];
}
}The integer overload uses Solidity’s bounded uint256; this example compares reuse, not overflow behaviour.
Make the empty case impossible for the caller
Now change the requirement: the batch must contain a flag. There should be no default. With a Solidity bool[], check xs.length != 0 on entry, or index xs[0] and let the bounds check revert on an empty array. If the protocol always sends exactly two flags, bool[2] expresses that size directly. Neither signature accepts every non-empty length and only those lengths at compile time.
In Omegyu a vector has a length in its type. Say the length is n + 1, where n may be any natural number:
let V = std:Vec
let firstFlag : forall (n : Natural) -> V.Vec Bool (n + 1) -> Bool
= \n flags -> V.head flags
in firstFlag 1 (V.cons False (V.cons True V.nil))Normal form
FalseHere n is 1, so the argument must have two flags. Even firstFlag 0 still needs one flag: V.nil has length zero and cannot be passed. The generic parameter in firstOr told us what an element was. The dependent type in firstFlag also tells us that there is one. The definition of head can take the first field of a pair without an empty branch.
An external caller can still send an empty ABI array or malformed bytes. Decode and validate that input; reject the empty case or handle it separately. Only after constructing the non-empty value can internal code rely on its type. This is not a claim that the EVM validates an Omegyu theorem. Theory explains why evidence can travel with a value.
What changes when you write a contract?
Can this method write?
Solidity: Mark it view and solc rejects writes.
Omegyu: A view handler receives read operations, but no write operation.
Where does a field live?
Solidity: Declaration order determines how fields pack into slots.
Omegyu: Derive a layout from the state type or supply one with evidence that it fits.
How do callers reach a method?
Solidity: For an ABI function call, the first four bytes identify the function; the encoded arguments follow.
Omegyu: Expose a native route, a Solidity ABI route, or both.
How do I establish a law?
Solidity: State an assertion; use tests or tools such as the SMTChecker to check it.
Omegyu: Write a proof alongside the function. The kernel checks it under the assumptions in its type.
In Pool, the SwapKeepsK type states that the swap formula does not decrease the product of the reserves. In that type, u is a natural number, so its successor is a positive input-side reserve. The proof takes the arithmetic laws in NatFacts as an argument. This is a theorem about the formula on natural numbers, not a proof of the deployed bytecode. See what is checked, tested and assumed.
What does it cost?
Deployment and calls cost different amounts. The runtime size is 815 bytes for Omegyu’s Counter and 419 bytes for Solidity compiled via IR. Yet in the Counter benchmark, the first ABI increment uses 22,233 versus 22,328 execution gas, excluding intrinsic transaction gas: both change a cold storage slot from zero to nonzero.
See the measurements and methodology for code sizes, deployment gas and per-call results. The tables distinguish matching ABI calls from approximate Solidity equivalents; neither is a general gas guarantee.