Devreal

Scale By The Bay 2020: James Aman, Multi-language Runtime Environments for Smart Contract Execution

Scale By The Bay 2020: James Aman, Multi-language Runtime Environments for Smart Contract Execution

Recording: Scale By The Bay 2020: James Aman, Multi-language Runtime Environments for Smart Contract Execution

[Music] today i'm going to talk to you guys a little bit about um how you can use uh the graw vm and in particular what we're doing at topple um in uh well we'll talk a little bit what we're doing at topple uh to integrate raw vm into uh creating a smart contract language smart contract language for a blockchain protocol um so in particular you know thinking about how you could technically or leverage the capabilities of growl in the polyglot capacity to uh you know bring in mix and match different features of uh languages as you need them um so there we go um first off a little bit about topple uh we are a blockchain startup based in houston texas um building a protocol for uh like a novel consent our novel blockchain protocol um to allow companies to prove and monetize their ethical and sustainable business practices um primarily that is focused uh right now in helping build supply chain uh tracking and uh like provenance type applications um so we have a team of about 12 people um we have their three co-founders myself our ceo kim and our chief architect christopher um we're about three years old um and yeah so we're just that's a little bit about us and i know i would be very much busted if i didn't uh let everyone know that we are hiring um so if anyone is interested in what they see today or uh has any questions um please you know feel free to reach out to me or you can email hiring a topology um okay so a little bit about uh what we're what we're doing or like an overview of what we're gonna talk about today so i'm gonna spend a little bit of time talking about what we're actually building um and why we think that uh growl vm is is a useful tool in this respect um so we're gonna spend a little bit of time delving into like the depths of what we actually are our blockchain client um as well as a bit of a high level overview of uh growl itself um i should have said this before i will i will not claim to be an expert in growl so i apologize if someone here uh if if i butcher it to uh to no means because uh or to no end because i am uh my formal training is is in ultra cold atomic physics uh and not really like you know computer science or i would say i'm very much on the the learning curve of growl and scala and you know enterprise level languages um so so yeah i'm i will communicate what i know it's the best of my ability but uh i am very much open if i have misinterpreted something or someone wants to like ask me about certain things um anyway so then then i'm going to show a little bit about a demo of actually running brawl uh in and implement it we were we actually adopted growl pretty early on whenever it was before it even you know gone through its actual like final release um so we've been dealing with it for quite a while um and it's actually integrated as uh our whole blockchain client runs on top of it um so i'm gonna show that in some of the capabilities that we're able to actually do as well as then we'll wrap up with just talking about some some future directions where we actually plan on taking uh this work uh and actually using or like utilizing growl uh more fully um not to say so primarily what i'm going to show today particularly in this demo is work that we did uh towards the end of last year and since then even there has been a major breaking release in uh in grawl if anyone is familiar so we are stuck in or we are currently on uh version 19.3 a girl um and there's been some some major changes for in version 20 um so if if there are things if anyone is familiar and there's some things that i'm doing that might sound a little weird that's that's a bit why we just haven't had the time to uh to get to um fixing all the breaks so far um all right so [Music] all right so yeah a little bit about what we're what we what we're building um so like i said we're a blockchain company uh and that that means but unlike i think most people you know they might they might say blockchain company they they mean they like they're writing adapt or uh they're you know just in d5 or something like this um but i actually mean like we're we're a protocol level company uh building uh like our own network infrastructure based on a uh a scholar reference client which is uh derived from the scorex 2.0 framework um this is the same framework that if anyone's familiar with waves or um or ergo this is a you know they they all come from the scorex 2.0 framework um and so the the entire project is an open source project um we are it is a public permissionless protocol um in addition to actually you know making the entire uh blockchain itself we are also uh building tooling and all the infrastructure pieces around it you know block explorer javascript act like sdks python sdks uh all the normal kind of developer tooling to actually get people to to ease use of the blockchain itself um oh and uh and then um a little bit about the the actual underlying mechanisms and and this will come into play later about why i think growl is a was is going to be a benefit for us um we actually use an akka framework and i put this up here to just show that um we this this encapsulation of functionality in the the different actors of the system um really it's i think it's it's a really great way to to uh build these deterministic state machines that uh that really underlie the whole concept of what a blockchain is um and so so we'll come back to this and so like i just want to point out here that um bifrost which is our primary uh reference client is built atop an akka actor framework um yeah and then um some other work that we're doing on the uh more like i guess far long-term side is actually and again will i think where we could benefit with growl is uh implementing and research of a proof of stake protocol uh name called oroboros um so this is a one of the the you know i think oldest proof of stake protocol or like maybe well-known proof-of-stake protocols um that is from a from a group called iohk um and the the detriment being that it's not in my opinion super uh super well known uh people like in so far as there's not like implementations of it um and it's it's pretty uh pretty hard to to they don't do a there's a lot of like academic literature on it but not so much to actually like say oh these are like the nuts and bolts of how you implement it it's all very high level and abstract uh you know like academic papers um so to kind of to to get our to really sink our teeth into orbos war of wars and understand it um to since uh it does consensus is you know the the lifeblood of a blockchain protocol um we have this this simulator this this uh blockchain simulator called prisomo um which again is also open source and on github um and uh it is also using brawl at this moment um and our plan is to continue this idea of simulation um and i'm really hoping that growl will be able to be a path forward for how we're going to be able to um you know branch out into other languages over time um okay and yeah the the primary motivator here being that um since consensus is such an important part of the protocol you really you want to make sure that you're doing it right and you can test as much as you can test every nook and cranny um really trying to do that uh another like underlying uh motivation for what really are like our whole architecture in general is uh we are an application-specific architecture um so if anyone is familiar i'm sure people are familiar with ethereum or at least have heard of it um ethereum is a is a general compute blockchain or i'm sure there's a better way to say it but it but in it it aims to be touring complete and allowed to do it's a to be a world computer right for you to do any sort of computation but just like anyone knows that um you know a cpu can do anything but it's not really good to play video games on because the graphics card's better because the graphics card's application specific but an app but a graphics card can't run word necessarily um so this sort of you there's always engineering trade-off and uh i think like in the in the blockchain space itself you know bitcoin is the first application specific blockchain where the idea was let's do money it is just e-money um and and that has seen a lot of growth um so so it's not to say that that ethereum's goal is noble but when you want to do something that uh that ambitious it necessarily means you have to trade off and so one of the things we're trying to do is uh maintain the bitcoin uh utxo model as a as a i guess more rigorous uh atomicity of data to enforce more rigorous ethnicity of data as well as making particular engineering decisions to uh put assets as a first-class citizen in the whole uh in the entire uh architecture um so so growl comes in here because the what i what we'll talk about a little bit later is um really ethereum had to develop their own evm and their own op codes um and that's quite an engineering feat honestly that's very impressive that they did that but it also means that um to to work in that system is cumbersome right they they try to make solidity uh very similar to javascript but if any anyone that's ever played in solidity which is the primary i think in my opinion i i could be convinced otherwise but um probably the most popular uh smart contract language the most popular way to do transactions on the on a ethereum blockchain um the it's it's cumbersome they tried to make it like javascript but it's very cumbersome so so brawl introducing uh the ability to have uh you know just normal languages um it it it makes it much more accessible to developers so they actually know what they're doing as well as uh this application specificity comes into play that i don't want to be touring complete i'm willing to say here are the things i want to do and here i'm going to do them i'm going to try to do them very well um and and try to make my efficiency gains in those places instead of trying to do everything i can um okay so uh also i just want to show here if anyone isn't aware of what a utxo model is uh it stands for unspent transaction outputs uh meaning that uh every time there's a transaction on the blockchain the transaction being how the state updates right imagine the blockchain is just an excel spreadsheet of you know balances or data it's just an account it's some some signifier some key value pair of uh a key of like an account which is the key and some value which could be data any sort of data it could be contract data it could be state it could be you know um uh tokens anything like this um so the transactions are how you actually update those things um and in bitcoin's case in the utxo model you actually have a uh unique piece of data a uniquely addressable piece of data that is the input to a transaction uh and that is consumed in that in the the running of that transaction and the output you get another uniquely identifiable piece of atomic data um and and so this this just has large implications for the underlying infrastructure um and one of the reasons i think growl or having the ability to um replicate your your vm outside of the actual execution context of the blockchain itself um is useful because knowing what your outputs are going to be is uh in my opinion a one of the most like it it is a uh probably one of those engineering decisions that ethereum made that i most hardly disagree with let's put it that way um anyway so so what is growl i've said it a lot um and if anyone's not familiar just get a little bit of a brief overview um so growl is oracle's uh you know really no i say attempt but it's not really intended it's because i've done it um but it's their like their push to write a java compiler uh in java right so that the entire thing from machine code all the way up to the actual source code is in java um and and then part of that is they've also made it this really robust run time for uh many languages right so already you know we had things like scala and kotlin that could you know natively turn to by code and run the jvm um but now using uh with growl you can actually define uh and they have natively defined there's there's support out of the box for uh you know javascript ruby r python all of these languages um you know actually uh can can be interpreted and run directly in a jvm now um and as well as and you can even embed them in native images uh so that so to optimize it for a particular platform and have like node applications that are running on a jvm um in a native image compiled for that platform um as well as there there's been a big push to do llvm languages um so you can also run you know c and rust uh and c-sharp and uh uh maybe on c-sharp c plus ipod um in in a jvm as well now um so that's that's a high level overview of what growl is um and and you know one of the big things that they really are are um focusing on is this ability to do this polyglot context so this is just a you know kind of a silly example but here in just these those few lines of code i could do a uh a test where i make a new context that contacts just being the execution context of the of the product of like where everything's gonna get evaluated in um and i can you know write something so i start this in python um and i can type hello from python and then in python i can actually switch and say i want to evaluate javascript and then i could i could evaluate this javascript string inside the python script on a jvm um and then further i i actually realized there's a there's a typo in here um but this would be if i was if i wanted to evaluate r right i could evaluate r inside javascript inside python on a jvm um or there's there's also access for there's really um great bindings to allow any of these languages to interact with the java apis directly um which from a blockchain point of view is concerning because i you know i don't want to expose that much functionality to to arbitrary code that can be running my on my machine but from a from a um you know architecture standpoint where you're trying to do this uh multi-language interoperability is a really really great tool and can be leveraged uh really handily um so as i said before um as of now the ones that are listed on their website are uh are javascript node ruby r python and wasm um and wasm's really interesting because this is actually the language that um ethereum is is targeting for their vm um uh to to have all of their their code be wasn't compatible and actually have the vm underlying the ethereum blockchain uh to be uh wasm and uh this you know you can imagine a scenario where uh a blockchain running on a on a jvm that has implemented a wasan interpreter could now take uh contracts from uh wasm compatible blockchains and just natively run them on their blockchain and now i have uh the potential for a much easier integration mechanism between chains um that that's a bit of speculation i i not i i will say i don't know the specifics of what could be involved in doing that um but you know it's an interesting uh thought that it could that might be possible um so again at a high level how all this happens or how it all works is uh there's a really awesome tool called truffle the uh truffle uh like i don't know interpreter it's a whole like set of tools um that will allow you to define a guest language um and the you you basically just define an api for how to turn that that guest language into an abstract syntax tree and then uh the polyglot interpreter will traverse this abstract syntax tree in your evaluation and actually turn it into java bytecode for you and that's you know i think the 10 000 foot view of how this whole process works um and and so some of the examples i'm going to show are uh where actually you can you can you can actually get access to this syntax tree what's really great about these tools and what uh what oracle's been developing in this whole process um is that the the same tools that are used to make the javascript interpreter and the uh ruby interpreter and the r interpreter are all tools that are available for you to implement your own dsls i mean your own guest languages as well as your own um tool chains so like debuggers or code coverage tools um things like this and this is actually something that we we leverage uh in ourselves for our blockchain execution um okay so here i'm going to transition a little bit um to also i will welcome anyone to ask questions if they if they'd like um so so what i'm going to do now is actually show you a uh i'm going to launch a let's just clear my thing um so here i'm going to run a do i want to do this first yeah i'll do this first um i'm actually going to i'm going to start up a node uh a node running on our private test net um on the on our blockchain are of you know running our protocol um and then we're gonna we're gonna execute a couple of things so first off we're going to uh oh darn i completely forgot i apologize everyone um the here i know what to do uh all right once it starts up we will i had a nice like text doc or notepad document that i was going to show with these programs um all right so here i'm showing this on the left because there's we're going to scroll up we're going to see a couple of things but now you see these blue lines the the nodes just forging away it's just trying to make new blocks as it's going and it's it's going to slowly make them over time um so now i have a my my just postman here that's going to talk to my node um and it's going to send a what we call a create program transaction in this create program is actually going to uh everything that we've done so far has been just in javascript our exploration of integration of this tool um into into the blockchain has just been in javascript really to just get a sense for uh what it means to to actually use truffle in this context um as well as javascript's just easy to um you know it's accessible for for uh newer developers um okay so let's go ahead and send that transaction so okay so a couple of things so we get back our response here and i'm going to go ahead and i'm going to pause this um and show you uh anyway um so here we go we we see that there's a uh you know a series of boxes that are made here um but essentially the important bit is that this is the this is the code that you just implemented in the chain i i apologize that i didn't get a chance to show that i meant to but all i did was i launched a program that will put up that puts a function that it just allows me to i will call the function and i have a variable that we put in there called uh a and we initialized a as zero uh and then we were gonna have we made this increment function uh that we're just gonna add one to it um and so i can actually that call was you know this was actually the just that was not it um it's just a stringified version of the javascript i just made a javascript uh script and put it in there uh i realized i did i think i meant to do this one yeah so here it is this is just you know we set a var equal to a and then we uh we will talk about this uh this parameter um in a second but um then we have this distance increment function in a ecma 8 you know syntax um and you know we have this improvement function so now what we can do is we can go ahead and i'm going to grab the vrd that actually identifies just like an ethereum or any other blue team um there's an id that identifies that contract so that we just grabbed the idea um do this get back at the results so what we're asking for is and we're going to jump down uh let me see that we have the unconfirmed transaction here so this is when the the transaction actually got added to the mempool um and then we see here that we have a new generated block which actually includes that transaction um if we if you parse through all this stuff you actually see that we have this state box here where uh we have the new boxes where a is now the state of a is now equal to one right and indeed if we go to our program call when we click send we now see that the result is one um so so i mean that's that's pretty minor right that that but but it does show that i can i can actually integrate uh this is a this is a scala blockchain running a javascript contract right on the in a in a way that i can you know run time deployment um so the next thing i'll do is show oh like i said i apologize i meant to do this um let's see here is the the next the next one i want to show is um this program in this program it's again it's a little hard to read because of all the new lines and the way we have to actually send it into the thing but um what we're going to do here is we're going to make a uh a function called add in that's written again in the in the ac eight return or style and then we have additionally uh the whole reason i want to do this and i like i said i apologize for this being so grody but um we have one of the great things about having access to this tool chain um that is that is exposed by truffle um is that you actually see the apps like the abstract transaction and we can use that abstract syntax tree to uh to enforce parameter types right so so that that's really what i'm sure there's we actually have this a js doc parser or a js doc like parser that will uh try to enforce or do casting of types on uh on the uh whatever methods are called um so just i realized i was misinterpreting my time so um this will be the last thing but i'll show here so we we again we you know we'll we'll get that that thing it will hopefully have gone to the chain built there it goes okay locally generate block i'll grab the id um i'm going to do this i'm going to say i want to add i'm going to say this is variable x and it's going to be value 1 and variable y ww2 and this is the add function so i should get back okay let's go back here get that just that part do that and that and that will send okay and uh so we see here we initially started out with our variable a equal to zero after this transaction is done the variable a will be equal to three um but the the important bit of what i want to show here though is that if i try to send in a string right i'm just gonna send in the string done um we will actually get a rejection and say the argument types do not match right and this is only possible because in the creation of the program we are actually able to uh see do a create a you know an interface that tells that just that we're able to test against and do casting um on on the the call in um and that's that's enabled by this uh this lecture parser um using the abstract syntax string um okay so okay last last things i want to just mention is that some of the future work we're planning to go with this is uh using the ast to actually uh estimate complexity um and from there assess fees right like i said one of the one of the uh things i really like to i see is as one of the holy grails of doing this is that you're actually able to off chain um assess the complexity and therefore the uh the the gas that's the gas fee but the the amount of uh like work you're going to encumber the network with and then therefore how much you want to pay for that work uh in in ethereum right now you don't know uh a priori how much work you're going to do until you actually do the thing um it's only after you actually run the contract you know there are estimators out there but you actually there's as far as i know no good way to uh to know until you actually run the uh function itself um obviously using the the ability with truffle to create our own dsl um like i said i'm really we're really focused on on enabling the movement of assets um and so uh really locking down um if we use something javascript like or uh or end up making something else entirely um but using uh that the truffle interpreter and creating our own language to to enable that that functionality um i also already talked about the compatibility blockchain protocols and the uh the ability to kind of in a piecemeal fashion use uh implementations of other languages inside grawl interacting inside the actually instead of at the application network or what we didn't talk about was um there's this whole instrumentation layer that we actually use to sandbox the uh the running of the programs um in whenever we do the the method executions um so they don't actually influence the protocol itself until we can we've done our ability to after the after the running of the program we can enforce correctness and make sure that there's no malicious code that could have been generated during that uh that run time execution that could come back into the protocol that the scala based protocol essentially um but then so actually within that scholar based protocol uh not exposing to the user but for our own development purposes being able to use growl to uh implement pieces of the system in other languages uh and in that way know that we have uh that because i think it's a i'm a big fan of the idea that uh the only way you actually test your protocol and you know that your your blockchain is the actual like specification you say it is is if you have a multi uh client network um and you know being a smart startup right now i think every advantage i can get to try to to test that like multi-language uh capability is to my benefit at this point um and and to do that utilizing the aqua model and brazomo um okay so yeah i apologize i went a few minutes over um but yeah that's [Music] you