Akin to most modern blockchains, Coreum will be able to store and execute Smart Contracts.
In essence, Smart Contracts are computer programs stored on a blockchain, which may be instantiated and executed to perform custom functions. That is to say, these functions are not included in the code of the blockchain itself, but are defined in a manner which enables the blockchain to execute them.
CosmWasm is the platform Coreum uses to handle WASM Smart Contracts.
It forms an important pillar of the Cosmos SDK, and has a number of advantages such as the ability to interact with Smart Contracts on different blockchains using the Inter-Blockchain Communication (IBC) protocol. This enables Smart Contracts stored on Coreum to enhance not only the functionality of Coreum itself, but all other blockchains in the Cosmos ecosystem that are compatible with CosmWasm Smart Contracts.
CosmWasm Smart Contracts produce and consume messages. These messages follow what is commonly referred to as the actor model, which means that they behave in a 'fire and forget' manner.
In effect, these messages are designed to be synchronous in nature, this avoiding race-conditions and pitfalls of awaiting promises. Other advantages of this model are:
- Increased Security - Since Smart Contracts are unable to call each other, it avoids re-entrance attacks. Messages may be passed between contracts, but they cannot directly call one another.
- Inter-Blockchain Messaging - Messages can be sent across blockchains through the IBC.
- Ease of Serialisation - Messages can be easily serialized to a number of different formats for easy integration with off-chain systems.
The lifecycle of a Smart Contract can be split into three distinct phases:
Contract Creation / Upload
Once the code for a Smart Contract is compiled into WASM binaries, they are optimised and uploaded to the blockchain. However, neither state nor a contract addresses exist at this stage.
The contract may then be instantiated with through a code reference as well as some initial state. This creates the address which identifies the contract. For reference, if this were an ERC20 Token Contract on an Ethereum Virtual Machine (EVM) blockchain, this is the stage at which information like the token name, symbol, etc. can be set.
Each actor has exclusive access to its own internal state. This may support different calls, but they are all unprivileged; usage of previously instantiated contracts depends on the contract design.
Coreum makes use of a custom module for the purpose of processing WASM related messages in order to upload, instantiate, and execute Smart Contracts.
Although Smart Contracts may be written in a number of different languages as stated above, Rust remains the language of choice. This is due to Rust's characteristic memory model, which promotes the creation of memory-safe, fast, and lightweight byte code that is ideal for on-chain storage.