Skip to content
FellowTraveler edited this page May 3, 2012 · 37 revisions

The concept of “smart contracts” originated with Nick Szabo: Nick Szabo's smart contracts Also: Money example in E language


That being said, OT has its own, entirely different implementation…
In the Open-Transactions universe, a “smart contract” has these properties:

  • A smart contract can be activated, after which point it takes on a “life of its own”, in the sense that it will process regularly over time according to its own internal terms and logic, until it expires or is deactivated. In this sense, it is like any other recurring OT transaction such as market trades and payment plans.
  • Smart contracts are most distinguished by the fact that they can have scriptable clauses. (Normally on OT, a typical contract only contains data tags, and human-readable clauses. Only the smart contracts “can come to life” with their own custom-scripted clauses.)
  • Smart contracts can have multiple parties, each with their own agents and asset accounts.
  • Only a select few functions are made available from within the script code of a smart contract, and all funds transfers go through this tightly-controlled interface, with notices and receipts sent to all relevant parties.
  • The script code is unable to manipulate any assets excepting those explicitly declared beforehand on the smart contract, and verified as valid property of a legitimate party to the contract. And when funds are moved, it’s to a contract-specific name, not an account ID. For example, you wouldn’t transfer funds from account pckjsdf9872345kj34kjhsf, but rather, by that account’s name as declared in the contract, such as alice_petty_cash or bobs_acct. (This means that it’s impossible to even reference any account other than those declared on the smart contract by name, since the functions provided operate based on those names.)
  • Not only can the smart contract move_funds() between these declared accounts, as its script logic dictates, but it can also stash_funds() directly inside the contract itself! For example, during an escrow, funds might be stashed inside the smart contract for 14 or 30 days, and then transferred to one party or another.
  • Scripted clauses can also be configured to trigger on certain events. For example, do you need a script to fire right when the smart contract first activates? No problem! Just attach it to the OnActivate() hook. Do you have a script that needs to fire every single day for a month? No problem, just put your logic on the OnProcess() hook! (And set a 1-day sleep between processing.) FYI, you can set multiple clauses to fire based on a single hook. For example, the main_bylaw might have a clause that triggers on the onActivate() hook, but the secondary_bylaws might also have a clause that triggers on that same hook.
  • You can also define variables in your smart contract, which persist through its entire lifetime. As the smart contract—including its internal state—continues to process over time, receipts will drop into the relevant parties’ inboxes, exactly the same as already happens with market trades and payment plans. A copy of the original signed smart contract is attached with every receipt, along with an updated, server-signed copy showing the current state. (The server will keep these receipts in the relevant user’s inbox, as proof of the transactions and current state, until that user signs off on the latest balance, enabling the server to then discard any old receipts.)
  • Once the contract expires (or is deactivated) then a finalReceipt is dropped into all relevant inboxes, after which no other receipts are possible for that smart contract. As with market offers and payment plans, users must close all receipts related to that contract, in order to close the finalReceipt.
  • Smart contract variables can be defined as “Constant” (value cannot change), “Persistent” (value can change, and will persist between script runs), and “Important” (value is persistent, AND any changes in the value will result in server notices being sent to the parties.)
  • Let’s say a party needs to DIRECTLY trigger one of the clauses on the contract. For example, perhaps an escrow user wishes to activate a clause in order to DISPUTE THE OUTCOME, or perhaps an arbitrator wishes to activate a clause in order to RENDER A JUDGMENT. OT’s smart contracts can do precisely these sorts of things, limited only by your imagination (and my pre-alpha code.) See the new API call: OT_API_triggerClause
    These sorts of actions are, of course, subject to the logic in the contract. (Perhaps the contract disallows Alice from executing certain clauses. YOU decide.)
  • Once voting groups are someday eventually added to OT, they will also be able to act as parties to agreements, and they will be able to take a vote in order to change their own bylaws! (Each smart contract contains a list of bylaws, and each bylaw contains a list of scripted clauses and variables.)
  • You can also define CALLBACK SCRIPTS: These scripts fire automatically whenever OT needs an answer to some important question. Such as:

- “Is Alice allowed to cancel this agreement?” (Your script returns true or false.)

- “Is Bob allowed to trigger the DISPUTE clause?” (Your script returns true or false.)

As long as you provide the script, YOUR logic can be there 24 hours a day, making decisions for your best interests, while you’re off sipping cocktails and getting arrested at Occupy Protests.


A SIMPLE EXAMPLE - “Two-way trade”

Here’s a sample “OnActivate()” clause from my very first (test) smartcontract, which implements a two-way-trade (where Bob doesn’t get his clams unless Alice also gets her gold at the same time).

Notice the entire functionality, while bare-bones, is implemented in this single OnActivate() clause, with deactivate_contract() being called at the bottom.


// These are the amounts being paid by both parties.
// These amounts are for different currency types...
// ...Alice is trading 140 XYZs for Bob's 100 ABCs.
//
var alice_pays     = "140"
var bob_pays       = "100"

// Stash is a function that only works inside smart contracts. It takes
// the funds from the denoted account and stashes them INSIDE the smart
// contract, into "first_stash" and "second_stash".
//
// (Only after BOTH stashes are successful, do we then unstash the funds
// to the OTHER user. i.e. Alice gets Bob's funds and Bob gets Alice's funds.
//
// NOTICE: You cannot use actual account IDs while inside a scripted clause.
// Instead, you can only refer to accounts by NAME (the name that was chosen
// for that account when the smart contract was written.) OT will resolve the
// name to the appropriate ID, based on the contents of the signed contract.
// This way, it would be useless to come up with some sneaky trick for slipping
// unexpected IDs into a contract while it's running -- since it doesn't operate
// based on the IDs! (Of course, the normal API operates based on IDs, but the
// smart contracts must operate from within their "sandbox.")
//
var bStAli  = stash_funds(alice_first_acct, "first_stash",  alice_pays)
var bStBob  = stash_funds(bob_second_acct,  "second_stash", bob_pays)

if (!bStAli || !bStBob)  // FAILURE
{
// Somehow, one of the stashes failed (technically impossible,
// unless one or both of them didn't have the necessary funds...)
// Therefore, we give the parties their money back.
//
   // IF Alice's stash was successful, then unstash back to her.
   if (bStAli) 
   {
     var b01 = unstash_funds(alice_first_acct,"first_stash",alice_pays)
   }
   if (bStBob) // IF Bob's stash was successful, then unstash back to him.
   {
     var b02 = unstash_funds(bob_second_acct,"second_stash",bob_pays)
   }
}
else  // Success stashing funds from both parties! 
{
   // Now let's unstash across, to the receiving parties...

   var b11 = unstash_funds(bob_first_acct, "first_stash", alice_pays)
   var b12 = unstash_funds(alice_second_acct,"second_stash", bob_pays)

   // bSuccess is a variable in the smart contract itself. That is, it's declared in the XML
   // of the contract, not inside this script proper--yet it's still accessible from in here.

        bSuccess = true
 }

 // Our work is done, so let's shut down the contract.
 // Receipts were already sent to the parties' inboxes when
 // the money was moved. Now this deactivate will cause a finalReceipt
 // to go to all the parties.
//
 deactivate_contract()

Of course, that isn’t the entire smart contract, but just the onActivate() clause. Here’s what the entire smart contract might look like:

(Subject to change, of course. This is very new code.)

-----BEGIN SIGNED SMARTCONTRACT-----
Hash: SAMY

<smartContract
 version="1.0"
 serverID="tmHvLZxb13hW6OyH1oHKTmKd7fTMRsUfzqPE6KCwSjl"
 activatorUserID=""
 activatorAcctID=""
 lastSenderUserID=""
 lastSenderAcctID=""
 lastRecipientUserID=""
 lastRecipientAcctID=""
 transactionNum="0"
 creationDate="1323862266"
 validFrom="1323862228"
 validTo="0"
 nextProcessDate="0" >

<scriptableContract>

<party name="party_alice"
 ownerType="nym"
 ownerID="T1Q3wZWgeTUoaUvn9m1lzIK5tn5wITlzxzrGNI8qtaV"
 openingTransNo="37"
 signedCopyProvided="true"
 authorizingAgent="agent_alice"
 numAgents="1"
 numAccounts="2" >

<agent name="agent_alice"
 doesAgentRepresentHimself="true"
 isAgentAnIndividual="true"
 nymID="T1Q3wZWgeTUoaUvn9m1lzIK5tn5wITlzxzrGNI8qtaV"
 roleID=""
 groupName="" />

<assetAccount name="alice_first_acct"
 acctID="2K3LoD1UxsJLO0FAfng0fgqnxnXScO8rM2eO5tdDTOE"
 assetTypeID="mNS1ODAXQoSXpWJfC5awE9zAXCm9aVfiE0WQGsIOw4B"
 agentName="agent_alice"
 closingTransNo="36" />

<assetAccount name="alice_second_acct"
 acctID="A6CcGwNiTtEPQnv7HLUcmf0QFaCGy862pb1SJ3zVqIU"
 assetTypeID="SjSYAUzN1RLjGre0kqDJynFos1MRYzrxOOenHY0Lpjd"
 agentName="agent_alice"
 closingTransNo="35" />

<mySignedCopy>
eJytVsuyokgQ3fsDszXcGt2CbzvmdgQiKj4ABZ+bGyWUUAoUVvEQvmM+eArw9rV7
bvREd7Qb4VRm1snMU1RW/vnrU/4bShNZqeryRJFGVX0prA1RVYy1IBrFcmUKqPOl
qgvLQ6XyN/UACUXshwSYYaUaQ0IR9l9q/GeuVqlSSBgij15qoTeNF8f7iW85u66a
Tnk8nRve3OqdjeWabs7ZTZO6czHRLy7zY7FQDEJMNrR0f8YE0wwfmAtoqEPfgs+G
7+APlmtoogBBP/zB+Bv+ZM/y8Wm+JfaVyHup5dmYBIIcGIEQsgxbzVa/22y2e2wp
Bi6yxgR773iz/4YbuPT34T3UCDYhpWUIrlb9mtfQJCgIwcmFb4XM0YAVNq36wGOG
xfMri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whh7aCZleOtr5B01OgNnRvoZM0wOHhJiFVJaK+WTkeTYh7t
9u2hakM9Gc6cwwjU1b7c0r3lIp2H18qUh3yvqZ5GS7U+rs+UULnNZ8c232zJy+vw
fBtlVtzn6QvTZdm5vLMOU9ajrybB/utbcwtV50b/7fdD24WCi6ePpwtQHsQFE9JD
ZTRkc12tWsDfRpPGk10Z7XneY8jzxPg8Khbzo2Bs1lI5NG7LwfBLVWUf4arxPl3R
Kve516mI2POYor9UnTAMvjQaNgqd6PTZxF5jDF0XJ8wlhi4kjTzAp+cAjQRdUYVF
EIYRkba9OE41p5mQlZUe45AY/pQL5w3tgi1qKzJRHGl9H9rOAS1321nUbp2ycO91
vIrk2vz67nKX7hpFbdFZBI7JT6d+hnbrqDWI/RPPdQBFCn/H4nW+OZJshMlyQEBT
O5gdULG1hXZxfFc8LMYc6nnb7C7N7Fl0ObiSc2jIe+pOHCEcuTSqL+LrS1k8SRn9
tHT/Ap89zUk=
</mySignedCopy>

</party>

<party name="party_bob"
 ownerType="nym"
 ownerID="1mxwHcQvxSgqWqy2e28ZREeuVVfgs0kxE41FN10TnS3"
 openingTransNo="67"
 signedCopyProvided="true"
 authorizingAgent="agent_bob"
 numAgents="1"
 numAccounts="2" >

<agent name="agent_bob"
 doesAgentRepresentHimself="true"
 isAgentAnIndividual="true"
 nymID="1mxwHcQvxSgqWqy2e28ZREeuVVfgs0kxE41FN10TnS3"
 roleID=""
 groupName="" />

<assetAccount name="bob_first_acct"
 acctID="w06QIURsSDV7sdWWvyPSxRaiv4T2MUQbJyWmIKxSmuL"
 assetTypeID="mNS1ODAXQoSXpWJfC5awE9zAXCm9aVfiE0WQGsIOw4B"
 agentName="agent_bob"
 closingTransNo="66" />

<assetAccount name="bob_second_acct"
 acctID="vuXpQt8h6CRGcz6G5zMOXqQeIRpsOq05VLuJ5IAFS5R"
 assetTypeID="SjSYAUzN1RLjGre0kqDJynFos1MRYzrxOOenHY0Lpjd"
 agentName="agent_bob"
 closingTransNo="65" />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1"
 numCallbacks="0"
 language="chai" >

<variable name="bSuccess"
 value="false"
 type="bool"
 access="persistent" />

<clause name="activate_clause">
eJx9kj1uwzAMhacuOgXjyQaC/BRdO6QH6JLuhizLCAHFDkQ6RdDkwL1FKclGXAeI
oIV61PceBanfl7P2oB0aW570hSCsd8i2b5tMBanqqruQpI1ISdvzzmE4JNZ0KJu+
rSlPsAY9camN4SVkqYhN2RImdsXI+eiqOSc4kzVdWw8YyIZyBI3ZCqWwgXwx5Lle
YZGQhfpREjqISStCGc8AovNmK659+zT///jT8EK5TQyi49zg9cFgPthsrPtUEX9T
1pFNg0Ti9jFyuPLkwWeRE+UxV2p7kmz64MJZr+HrgASydYCirpwFbIEPFuioPYPc
Zq8NryD/7Bhqa5z2tpYmwtoOEA4QMh5PEv1iWX4BOgeSwBJhYDa+O8I3SmMLyKtk
H1e172ObDMO+F+JNtNqKJZ4123IMkBfqDzdv81s=
</clause>

<hook name="cron_activate"
 clause="activate_clause" />

</bylaw>

</scriptableContract>

<accountList type="stash" count="0" >

</accountList>

</smartContract>

-----BEGIN SMARTCONTRACT SIGNATURE-----
Version: Open Transactions 0.75
Comment: http://github.com/FellowTraveler/Open-Transactions/wiki

CoABiNsgHCRFOVBFgU80CqPUnMYpb+IMLmBWMroLSVEkHBuUojcIcAGXMBqKxy96
tjBD0GLb9TINu9ehVKGyyqcNKcxb5QlQQbKpkFiEELAB2mhtJsTQlsPZaa6e+KWg
0OhmgwbNVHohbKUwyJAgrPN8FHlguw2uW+dJ/3gX5huctLA=
-----END SMARTCONTRACT SIGNATURE-----

Many have asked about my choice of script interpreter. FYI, I’m currently using ChaiScript, which was chosen for being cross-platform, clean, easy-to-use, and integrates well with C++.

However, the design of OT is very modular, such that it is very easy to replace the script language. OT is coded to the abstract interface OTScript, and the actual Chai integration is done in a subclass called OTScriptChai. All you have to do, to replace the script language, is just make your own subclass of OTScript. To do that, copy the OTScriptChai class, and make your own version such as OTScriptLua or OTAngelScript or OTScriptE, or whatever floats your boat.

In fact, each Bylaw stores the name of its script language, so you could technically have 3 or 4 completely different script interpreters running against the same smart contract! (I do NOT recommend this.)

FYI, the reason I didn’t go with Lua, for those who are asking, is because I heard it has security problems. Google it.

Bottom line: the point of OT is to be able to easily swap in/out different storage, different network transport, and yes, a different script interpreter. This way OT can best adjust to everyone’s needs, and focus more purely on its financial crypto aspects, abstracting all else away for others to worry about. The best choice for a reference implementation such as OT is something simple, clean and cross-platform (like chaiscript.)


For those curious about why I didn’t use the E capabilities language (Nick Szabo), some points:

  • I think they have an entire engine built up to make the E language even possible, which may not be fully “OT compatible”. In fact, I don’t know what all they have, but it might replace OT entirely!
  • I also didn’t see a C++ library for E, because I did try to find a lib for download/experimentation…
  • However there is, interestingly, an E library in Common Lisp! Therefore I think anyone reading this should contact Bill St. Clair and encourage him to build E into his brilliant Truledger, which is also implemented in LISP.
  • Open-Transactions is extremely modular and if you want to make your own subclass of OTScript that actually uses E somehow, then I encourage you to fork the code and give it a shot!
  • One thing I will acknowledge: Szabo’s work is really impressive stuff!

Here are those links again:
Nick Szabo's smart contracts Also: Money example in E language

Clone this wiki locally