New Version of Summoner Contract Language

BytomDAO
BytomDAO
Published in
3 min readOct 28, 2021

Following the upgrade of the Bytom 2.0 mainnet in August, Bytom once again ushered in a major upgrade, and the new Summoner Contract Language was officially released.

The new version of the Summoner Language has a lot of highlights, is very friendly to developers, and helps to further expand the ecosystem of Bytom.

1. Brand-new grammar system, similar to Go language design

Compared with the Equity language, the new Summoner grammar is closer to the current high-level computer language, and the grammar is also designed with reference to the Go language, which is friendly to developers, easy to read and understand, and quick to get started.

For example, compare the same single-sign verification contract below

Equity version
contract LockWithPublicKey(publicKey: PublicKey) locks valueAmount of valueAsset {
clause unlockWithSig(sig: Signature) {
verify checkTxSig(publicKey, sig)
unlock valueAmount of valueAsset
}
}
Summoner version
var publicKey pubkey = "e9108d3ca8049800727f6a3505b3a2710dc579405dde03c250f16d9a7e1e6e78"

func unlockWithSig(signnature sig) {
verify(check_tx_sig(publicKey, signnature))
}

For people with programming experience, the Summoner version will be known at a glance, while the Equity version requires a certain amount of learning.

2. The first world state based on UTXO model

Bytom2.0 expands the underlying BUTXO model, opens up a new space to store global data, allows the contract to obtain the world state, so as to support more complex business needs.

The structure of the new UTXO is shown in the figure below:

3. The introduction of global variables

By introducing global variables, multiple methods can share parameters, and it is also convenient to transfer data between methods. At the same time, it can also allow the contract to obtain the world state and support state transitions, thereby increasing the flexibility and complexity of the contract.

Global variables can be declared as follows:

4. New Build-in method

Summoner has been equiped with commonly used Build-in methods to increase the reusability of the code, reduce the burden on developers, and just call them directly. The Build-in method is as follows:

sha3(s) Return to the SHA3-256 hash operation result of the byte type string parameter s.
sha256(s) Return to the SHA-256 hash operation result of the byte string parameter s.
abs(n) Return to the absolute value of the number n.
min(x, y) Return to the smallest of the two values ​​x and y.
max(x, y) Return to the largest of the two values ​​x and y.
checkTxSig(key, sig) Verify that the signature of the transaction is correct based on a PublicKey and a Signature.
below(height) Determine whether the current block height is lower than the parameter height, if yes, return true, otherwise return to false.
above(height) Determine whether the current block height is higher than the parameter height, if yes, return true, otherwise return to false.
lock(amount,asset,program) Lock the amount of 'asset type' assets to the specified recipient (program type)
verify(expression) Verify whether the result of the expression is true. The result of the expression must be of type bool. When the result of the expression must be true, the verification is successful.

5. Bytom 2.0 enters a new stage

The release of the new smart contract language and compiler means that Bytom has entered a new stage. The new contract will greatly promote Bytom’s ecological promotion and application landing. At the same time, the contract language of computer-like programming language will greatly expand the number of developers, even if you have not used other contract languages, you can get started quickly.

In the future, advanced functions such as structure support, library file support, etc. will be added to take the contract to a higher level.

For more contract technical content, please refer to the Developer Center:

https://developer.bytom.io/zh/guide/04_smart_contract_overview.html

--

--