create account

Why I like Wren for Smart Contracts by dantheman

View this thread on: hive.blogpeakd.comecency.com
· @dantheman ·
$82.95
Why I like Wren for Smart Contracts
<div class="pull-left">

https://www.allaboutbirds.org/guide/PHOTO/LARGE/carolina_wren_glamor.jpg
</div>

After my recent post about Smart Contracts several people made comments about my choice of language.  Wren is an incredibly immature toy-language that is hardly battle tested and little known.  Just this week I had to submit a pull request to fix a critical bug that prevented it from being usable.

In theory *any* language could be used because of the ground breaking advancement of eliminating the need to deterministically calculate “gas”.  There are JavaScript interpreters, Lua, and Python options.  


## Sandboxing is Hard

When picking a language to use the number one consideration is ease of sandboxing. This means that the compiled code can be kept within certain CPU and memory constraints.  The next constraint is ease of interfacing with C++ / ChainBase code.

Prior to finding Wren is discovered a fast embedded JavaScript engine, [Duktape](http://duktape.org/), that I thought was promising.  I spent significant time attempting to implement proper sandboxing within Duktape with little success.  

JavaScript is a great language, but it is not designed for speed even though modern JavaScript engines are amazing!  To get amazing speed from JavaScript requires incredibly complex Just-in-Time compilation.

The truth is that most languages do not support sandboxing very well at all.  Their implementations are very complex and they attempt to do far more than is necessary.  For years I have looked for a good way to sandbox JavaScript.  Typical approaches to sandboxing involve spawning threads at a minimum and subprocesses for very robust solutions.  These sandboxes are expensive to set up and tear down and make communication with blockchain state expensive. 

A blockchain environment is challenging because the amount of code that executes in the sandbox is very small!  A typical contract will run in a fraction of a millisecond, but most traditional sandboxing approaches with existing libraries have significant setup / teardown costs.  

Wren, even in its current immature state, has proven to be incredibly fast and efficient without having to resort to Just in Time compilation.  I am certain that the Wren language could be made orders of magnitude faster with a native compiler. It would be faster than Lua or JavaScript JIT because of the language design.    

## A Language I can Customize 

Wren isn’t a final language, it is a starting point.  It is a small well organized code base that can be readily adapted to suite the needs of a blockchain.  In fact, I would probably strip out many Wren features (such as Fibers) in order to make it even simpler. 

Attempting to modify the high-performance Lua, JavaScript, and Python libraries would be far more challenging and error prone.

## A C++-like Language  

I would go so far as to say that the ultimate language would be a simple subset of C/C++.  A C/C++ scripting language could be easily converted to native code while having the benefits of an easily sandboxed interpreter.  Untrusted scripts would be run by the interpreter, but developers could easily convert any popular script with a trusted native alternative.  


## Addressing @anonymint’s concerns

When Steem was under DOS attack the hacker was broadcasting as many transactions as he could. All of the transactions were valid and included in the blockchain. The DOS was defended by the blockchain protocol, not the network protocol.  

@anonymint seems to think I have misunderstood something about how GAS works in ethereum.  Here is what I “know” from a first principles perspective.  If people only pay for what they use and are refunded what they don’t use then all nodes need to agree on the refund.  

If the author of the transaction specified the “exact” amount of GAS required then the validator could simply use that number, but we know that it is impossible for the transaction creator to know in advance how much GAS their transaction will consume.  (Other users could change the state between transaction signing and applying the transaction in the block).

### Regarding The Proof of Work on Transactions

I would estimate the time complexity to require the sender to spend 10x the CPU time doing POW as the validator does executing the script *on the same hardware*.    The typical script should take no more than 1ms to run, so the typical POW should take no more than 10ms on a standard desktop computer and it wouldn’t increase in difficulty over time.

While an ASIC or GPU would enable the attacker to generate more transactions, it would be pointless.  The goal of the POW is to make the attacker spend more time and money than the server.  An ASIC or GPU may be able to do those calculations faster than the server can execute the script, but the attacker was still forced to use significantly more resources for the same attack.

It could be argued that POW on transactions is not necessary at all because the protocol already rate limits attackers on CPU time, bandwidth, and storage.  The purpose of proof-of-work is to protect an individual node from a malicious peer.  Each node can easily identify connections (and blockchain accounts) that are producing more transactions than can be included.  

In fact, 99% of the time the bandwidth rate limiting will cause a transaction to fail before the CPU intensive script gets called.  Proof-of-work ends up being an objective means of “requesting” wall-clock time for your script and determining the resultant pay for the block producer who includes your script.
## Conclusion

The approach I propose for Smart Contracts can eventually support many different languages in parallel.  The choice of language has more to do with getting a minimal viable product to market in a timely manner than anything else.  Other languages will come in time if the platform proves successful.

I firmly believe that developers can easily adapt to any C/C++ like language and that smart contracts should be relatively simple pieces of code that shouldn’t be reusing large libraries of existing code even if those libraries existed.  If you are not using existing libraries of code, then language of choice matters little so long as it is similar enough to other languages.
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , and 522 others
properties (23)
authordantheman
permlinkwhy-i-like-wren-for-smart-contracts
categoryblockchain
json_metadata{"tags":["blockchain","smartcontract","ethereum","wren"],"users":["anonymint"],"image":["https://www.allaboutbirds.org/guide/PHOTO/LARGE/carolina_wren_glamor.jpg"],"links":["http://duktape.org/"]}
created2016-10-30 06:47:33
last_update2016-10-30 06:47:33
depth0
children14
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value81.744 HBD
curator_payout_value1.208 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length6,290
author_reputation240,292,002,602,347
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,650,555
net_rshares94,149,051,824,010
author_curate_reward""
vote details (586)
@clayop ·
Great post as always @dantheman
How much will it be difficult to convert solidity apps into Wren? Will the benefits, such as scalability and performances, be significantly greater than the costs of convertingor rewriting codes?
properties (22)
authorclayop
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20161031t052006499z
categoryblockchain
json_metadata{"tags":["blockchain"],"users":["dantheman"]}
created2016-10-31 05:20:06
last_update2016-10-31 05:20:06
depth1
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length227
author_reputation270,845,899,918,618
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,656,459
net_rshares0
@cryptomancer · (edited)
I'm curious what you think of Ethereum's Solidity language.  How does it compare to Wren?  I haven't read your previous post so apologies if you've already talked about this.  I'm a big fan of Ethereum and the potential that smart contracts have for decentralized apps.  Are you considering integrating smart contracts into the Steem blockchain?

EDIT:  just read your earlier article.  I didn't realize the EVM was so inefficient.  Glad to see you are thinking about and experimenting with these things!  Vitalik has been doing an excellent job of steering Ethereum forward so far; I'm confident he and the Ethereum Foundation will be up to finding solutions to the technical challenges that remain.  Imagine what the two of you could accomplish, working together?
properties (22)
authorcryptomancer
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20161030t082959964z
categoryblockchain
json_metadata{"tags":["blockchain"]}
created2016-10-30 08:30:00
last_update2016-10-30 09:00:27
depth1
children1
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length765
author_reputation27,907,760,743,718
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,650,832
net_rshares0
@vato · (edited)
$0.06
>"Imagine what the two of you could accomplish, working together?"

They've already tried that...
https://pbs.twimg.com/media/CdXlpvgWwAADD0O.jpg
https://steemit.com/blockchain/@pheonike/blockchain-history
👍  , , ,
properties (23)
authorvato
permlinkre-cryptomancer-re-dantheman-why-i-like-wren-for-smart-contracts-20161030t113519383z
categoryblockchain
json_metadata{"tags":["blockchain"],"image":["https://pbs.twimg.com/media/CdXlpvgWwAADD0O.jpg"],"links":["https://steemit.com/blockchain/@pheonike/blockchain-history"]}
created2016-10-30 11:35:21
last_update2016-10-30 11:36:03
depth2
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.046 HBD
curator_payout_value0.015 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length205
author_reputation3,378,892,006,080
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,651,465
net_rshares1,344,763,182,607
author_curate_reward""
vote details (4)
@linkback-bot-v0 ·
This post has been linked to from another place on Steem.


  - [Advanced Steem Metrics Report for 30th October 2016](https://steemit.com/steemit/@ontofractal/advanced-steem-metrics-report-for-30th-october-2016) by @ontofractal




Learn more about and upvote to support [**linkback bot v0.5**](https://steemit.com/steemit/@ontofractal/steem-linkback-bot-v0-5-the-reddit-awareness-release). Flag this comment if you don't want the bot to continue posting linkbacks for your posts.

Built by @ontofractal
properties (22)
authorlinkback-bot-v0
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-linkbacks
categoryblockchain
json_metadata{}
created2016-10-31 16:24:30
last_update2016-10-31 16:24:30
depth1
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length504
author_reputation1,915,954,976,722
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,659,493
net_rshares0
@michaelstobiersk ·
☆☆☆☆☆
properties (22)
authormichaelstobiersk
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20161030t065517794z
categoryblockchain
json_metadata{"tags":["blockchain"]}
created2016-10-30 06:55:21
last_update2016-10-30 06:55:21
depth1
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length5
author_reputation28,639,834,562,096
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,650,581
net_rshares0
@mranderson ·
What about rust for C like language? Eth Parity written rust is by far the highest performing platform.  Plus rust is also what the SAFEnetwork is being written in.
properties (22)
authormranderson
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20170429t151502948z
categoryblockchain
json_metadata{"tags":["blockchain"],"app":"steemit/0.1"}
created2017-04-29 15:15:09
last_update2017-04-29 15:15:09
depth1
children0
last_payout2017-05-06 15:15:09
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length164
author_reputation4,004,740,218,138
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id3,153,107
net_rshares0
@skeptic ·
hey dan why are you flagging me?
I am making a post about all this that went down yesterday, I would like to thank you for proving all I have said as correct and joining the people on my post known as flaggots.

<a href="https://imgflip.com/i/1afmdw"><img src="https://i.imgflip.com/1afmdw.jpg" title="made at imgflip.com"/></a>
👍  , , , , , , ,
👎  ,
properties (23)
authorskeptic
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20161030t192836607z
categoryblockchain
json_metadata{"tags":["blockchain"],"image":["https://i.imgflip.com/1afmdw.jpg"],"links":["https://imgflip.com/i/1afmdw"]}
created2016-10-30 19:28:39
last_update2016-10-30 19:28:39
depth1
children4
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length328
author_reputation3,757,645,024,158
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,653,804
net_rshares-371,505,035,951
author_curate_reward""
vote details (10)
@chryspano ·
Stay on topic and stop wasting Dan's time with nonsense,  if you want to whine do it in your own posts(you have so many of them)
properties (22)
authorchryspano
permlinkre-skeptic-re-dantheman-why-i-like-wren-for-smart-contracts-20161031t101511976z
categoryblockchain
json_metadata{"tags":["blockchain"]}
created2016-10-31 10:15:12
last_update2016-10-31 10:15:12
depth2
children1
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length128
author_reputation1,737,163,852,522
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,657,500
net_rshares0
@skeptic ·
have fun watching steemit die because of flaggots like you.
I have stayed on topic.
Have fun watching your ship sink because of your own actions.
LMFAO!

P.S.
<a href="https://imgflip.com/i/1af36e"><img src="https://i.imgflip.com/1af36e.jpg" title="made at imgflip.com"/></a>
properties (22)
authorskeptic
permlinkre-chryspano-re-skeptic-re-dantheman-why-i-like-wren-for-smart-contracts-20161104t234025448z
categoryblockchain
json_metadata{"tags":["blockchain"],"image":["https://i.imgflip.com/1af36e.jpg"],"links":["https://imgflip.com/i/1af36e"]}
created2016-11-04 23:40:36
last_update2016-11-04 23:40:36
depth3
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length275
author_reputation3,757,645,024,158
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,689,167
net_rshares0
@dantheman ·
I flagged you for your crude language and hostile tone.   I just realized you were using the word Flaggot and not Faggot... in any case it was disrespectful and inappropriate.
properties (22)
authordantheman
permlinkre-skeptic-re-dantheman-why-i-like-wren-for-smart-contracts-20161030t213714633z
categoryblockchain
json_metadata{"tags":["blockchain"]}
created2016-10-30 21:37:15
last_update2016-10-30 21:37:15
depth2
children1
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length175
author_reputation240,292,002,602,347
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,654,531
net_rshares0
@skeptic ·
https://steemit.com/flaggot/@skeptic/more-proof-steemit-is-pro-censorship
👍  
properties (23)
authorskeptic
permlinkre-dantheman-re-skeptic-re-dantheman-why-i-like-wren-for-smart-contracts-20161031t002809639z
categoryblockchain
json_metadata{"tags":["blockchain"],"links":["https://steemit.com/flaggot/@skeptic/more-proof-steemit-is-pro-censorship"]}
created2016-10-31 00:28:12
last_update2016-10-31 00:28:12
depth3
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length73
author_reputation3,757,645,024,158
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,655,295
net_rshares45,429,439,398
author_curate_reward""
vote details (1)
@solarguy ·
speak English!!!  &#128514; &#128518; &#10024;
properties (22)
authorsolarguy
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20161030t065708960z
categoryblockchain
json_metadata{"tags":["blockchain"]}
created2016-10-30 07:00:00
last_update2016-10-30 07:00:00
depth1
children1
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length46
author_reputation63,279,952,248,302
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,650,585
net_rshares0
@acidyo ·
This was my reaction when first reading about blockchain stuff. :D
properties (22)
authoracidyo
permlinkre-solarguy-re-dantheman-why-i-like-wren-for-smart-contracts-20161030t082555172z
categoryblockchain
json_metadata{"tags":["blockchain"]}
created2016-10-30 08:25:57
last_update2016-10-30 08:25:57
depth2
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length66
author_reputation3,324,113,748,223,111
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,650,820
net_rshares0
@vegascomic ·
<center>Cheers to the Wren!</center>
<center>http://www.crowdfunder.website/linux/pics/sketch/birds/wren/wren-1-840.jpg</center>
<center>Colored Pencil Sketch Render by @vegascomic</center>
properties (22)
authorvegascomic
permlinkre-dantheman-why-i-like-wren-for-smart-contracts-20161030t203314608z
categoryblockchain
json_metadata{"tags":["blockchain"],"users":["vegascomic"],"image":["http://www.crowdfunder.website/linux/pics/sketch/birds/wren/wren-1-840.jpg"]}
created2016-10-30 20:33:15
last_update2016-10-30 20:33:15
depth1
children0
last_payout2016-11-30 11:55:51
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length189
author_reputation37,110,678,013,541
root_title"Why I like Wren for Smart Contracts"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,654,159
net_rshares0