This is a solidity implementation of Cross Framework.
Currently, it provides the following features:
- the registry feature that allows developers to register their contracts
- the coordinator feature of the simple commit protocol
- the participant features for the simple-commit and two-phase commit protocols
- it's implemented on top of yui-ibc-solidity
The coordinator feature of the two-phase commit will be provided in the future.
For an ERC20 atomic swap demo, please refer to ethereum-cross-demo
// IContractModule defines the expected interface of a contract module on Cross Framework
interface IContractModule {
// onContractCommitImmediately is a callback function that is called on the participant chain to execute the transaction logic immediately
// This function is intended to be used only in the simple-commit protocol
function onContractCommitImmediately(CrossContext calldata context, bytes calldata callInfo)
external
returns (bytes memory);
// onContractPrepare is a callback function that is called at the prepare(2pc) phase
function onContractPrepare(CrossContext calldata context, bytes calldata callInfo) external returns (bytes memory);
// onCommit is a callback function that is called at the commit(2pc) phase
// It is expected that it commits the changes in the contract module
// IMPORTANT: This function MUST NOT revert.
function onCommit(CrossContext calldata context) external;
// onAbort is a callback function that is called at the commit(2pc) phase
// It is expected that it aborts the changes in the contract module
// IMPORTANT: This function MUST NOT revert.
function onAbort(CrossContext calldata context) external;
}-
For the current simple-commit coordinator flow, the coordinator-side participant uses
onContractPrepareto execute and lock state changes, and later finalizes them withonCommitoronAbortbased on the acknowledgement from the counterparty. -
The counterparty participant executes the incoming call and finalizes immediately via
onContractCommitImmediately. -
IMPORTANT:
onCommitandonAbortMUST NOT revert.
Here is an example of deploying with the module CrossSimpleModule that implements the simple commit.
To generate encoders and decoders in solidity from proto files, you need to use the code generator solidity-protobuf.
Currently, this version is required.
Install Slither and use it for static analysis.
pip3 install slither-analyzer
make slither
Lint the source code using solhint
npm ci
npm run lint:sol