One Year Anniversary release

SmartPy.io
3 min readMar 5, 2020

One year after announcing SmartPy and SmartPy.io, it is our great pleasure to announce our new release. It coincides with the great Carthage activation on the Tezos mainnet for no reason.

As always, we first activated it on https://SmartPy.io/dev.
We’ll propagate it on https://SmartPy.io/demo in the next days if everything goes as smoothly as hoped and expected.

Compared to our last big release in January, https://medium.com/@SmartPy_io/new-release-for-smartpy-and-smartpy-io-89d11dc5146a, no big changes at the surface of SmartPy, we expect close to zero changes for existing SmartPy scripts; but, many new constructions, better explorer and a lot of work under the hood.

SmartPy Documentation

We updated our documentation: https://SmartPy.io/dev/reference.html.
It’s simply better compared to what we had before and we encourage all SmartPy developers to have a look at it. We also added links to SmartPy templates and Nomadic Labs’s awesome Michelson documentation.

Private Entry Points

This version introduces a new experimental feature called private entry points. These are entry points that you define in your contract, that you can call in tests but they are not generated in Michelson.

These are useful in tests for constructions such as:

    @sp.private_entry_point
def edit_storage(self, params):
sp.verify(params.a > 12) # verify some invariant
self.data.set(params) # replace the complete storage

Custom Type Layouts

Another experimental and yet very useful feature is the ability to define custom layouts for records. The rational is that SmartPy maps records to trees of pairs in Michelson and these trees may require to be set precisely, typically for inter-contract communication such as with Asset Standards or such.

This is done by calling sp.set_record_layout.

For example,

sp.set_record_layout(params, ("a", ("b", "c")))

verifies that params has a record type with fields “a”, “b”, “c” and further ensures that those fields are paired according to the layout ("a", ("b", "c")).

Type Inference

SmartPy uses a type inference algorithm to keep the programming experience pleasurable while ensuring that everything goes smoothly afterward.

We have improved our algorithm in some subtle directions which enables us to nicely type sp.ediv and other heavily overloaded constructions.

Lambdas

New work on integrating lambdas inside SmartPy led to new nice constructions.

In a contract, we can now write

    @sp.global_lambda
def square_root(x):
sp.verify(x >= 0)
y = sp.local('y', x)
sp.while y.value * y.value > x:
y.value = (x // y.value + y.value) // 2
sp.verify((y.value * y.value <= x)
& (x < (y.value + 1) * (y.value + 1)))
return y.value

This will simply define a global function that can be call from entry points when necessary. This is a special case of a more general construction but clearly the most important one.

Local lambdas can also be created by simply doing, for example:

f = sp.build_lambda(lambda x: x + 3)

A lambda can then be used by simply calling it f(x). The Michelson APPLY notion has an exact SmartPy formulation. When f is a lambda on a pair, f.apply(x) partially applies f to x.

Contract Explorer

Our contract explorer https://smartpy.io/dev/explore.html has also seen several important improvements: it is really fast, operations (thanks to TzStats api) are better reported, Michelson code is nicely typed and shown for SmartPy and non-SmartPy contracts alike, etc.

Command Line Interface

The command line interface has been updated as well for the dev version.

To install from dev, please see the documentation and type:

sh <(curl -s https://SmartPy.io/SmartPyBasicDev/SmartPy.sh) local-install-dev ~

Former Versions

We do not expect anyone to need these former versions.

The former dev version is here: https://SmartPy.io/prev.dev.20200305.

The former dev CLI is here:

sh <(curl -s https://SmartPy.io/SmartPyBasicDev/SmartPy.sh) local-install-custom SmartPyBasicPrevDev20200305 ~

Data Type Layout

(this is an new edit from March 17)

Record and variant types are mapped to pair and or trees in Michelson. A mapping is built automatically by SmartPy (balanced binary tree).

Two important elements for this version:

  • This mapping changed with this version. The new version is much better than what it used to be but it can be disconcerting.
  • There is now a way to explicitely determine the obtained geometry called layout. It is explained and demo’ed in the SmartPy reference manual https://smartpy.io/dev/reference.html#_records_and_variants.

--

--

SmartPy.io

An intuitive and effective smart contracts language and development platform for Tezos. In Python.