Splitting the verify function

As smart contracts become more complicated, the risk of missing some important control grows. To reduce this risk, the smart contract verification is split up into sub-verify functions which each deal with one of the types of constraints defined in CDL Smart Contract view.

The exception to this is that the blue Flow constraints are not implemented in the Contract and are more like notes on what the Flows should be doing.

AgreementContract.kt:

    override fun verify(tx: LedgerTransaction) {

        verifyPathConstraints(tx, AgreementState::class.java)
        verifyUniversalConstraints(tx)
        verifyStatusConstraints(tx)
        verifyLinearIDConstraints(tx)
        verifySigningConstraints(tx)
        verifyCommandConstraints(tx)
    }

Later, you may notice that by splitting the verification into the sub-verify functions there is some duplication, eg multiple switch (when in Kotlin) statements on command.value. The principle is that it is better to have some duplication if it allows better clarity and structure of the smart contract because this reduces the risk of making mistakes.

For all the sub-verify functions passed in the LedgerTransaction, this is so each sub-verify has access to the whole resolved transaction. For verifyPathConstraints() you also need to pass in the class of the AgreementState.

The following sections consider the implementation of each constraint in turn.

Was this page helpful?

Thanks for your feedback!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.

We're sorry this page wasn't helpful. Let us know how we can make it better!

Chat with us

Chat with us on our #docs channel on slack. You can also join a lot of other slack channels there and have access to 1-on-1 communication with members of the R3 team and the online community.

Create an issue

Create a new GitHub issue in this repository - submit technical feedback, draw attention to a potential documentation bug, or share ideas for improvement and general feedback.

Propose documentation improvements directly

Help us to improve the docs by contributing directly. It's simple - just fork this repository and raise a PR of your own - R3's Technical Writers will review it and apply the relevant suggestions.