Juvix: Towards a Functional Programming Language for Decentralized Applications and Beyond

EthPrague 2023 · June 2023 · 21:48

Jonathan Cubides and Veronika Romashkina introduce Juvix, an in-progress functional programming language for next-generation decentralized applications. Juvix combines ideas from functional languages with efficient compilation to low-level targets such as C and LLVM. The talk at ETHPrague 2023 covers the language's current state, features and open challenges.

Speakers

Topics

From EthPrague 2023, hosted by ETHPrague.

Transcript

uh hello everyone welcome to the talk about juick's towards functional programming language for decentralized application and beyond my name is Veronica ramashkina and in today's talk I want to introduce jurik language to you explain its main goals and main features that language suggests and also we will walk through the compilation Pipeline and what role it plays in writing decentralized application specifically writing arithmetic circuits for zero knowledge proofs I will explain at which is the current state of the language and what ongoing process of creating new features we have in mind

for that and uh yeah let's start so juvex is a high level programming language with a strong type system its goal is to write privacy preserving decentralized application and we're also focusing on privacy and security a lot and also on efficient compilation processes to low level languages such as C and llvm uh we also focusing on deploying uh these applications smoothly on a normal or ethereum anoma is a intense Centric protocol you can think of a normal as a system where

user can do transactions and in order to write such application you need to introduce few Concepts in your application such as transactions themselves some of the resources Concepts and also describe some of the con constraints on privacy and security that such system would have then your application your application would change the status of the system by providing these actions that you describe and it also will depend on the input for the program and on the existing privacy constraints that you have on the program

program and when we wanted to create such application with the current existing solution we Face a few limitations that we were not satisfied with such as most of the programming languages existing they are not focused on writing decentralized application per se and specifically they they're not focused on features that important for us to write application in a normal protocol especially not a specialized in privacy Security in handling complex consensus algorithms or

working with on-chain and of J interactions also even if the languages are created for decentralized application not all of them are have that level of availability performance and maintainability that we needed and also the problems that they had locked in backhands and we wanted the solutions that would be more flexible in that and another Focus for us was efficient efficient development process so with all that in mind we created our own solution language drux and to

summarize all I said here are the goals of the language that we created so first of all we are focusing on deploying these applications on anoma and we are also wanted to be very easy to write for developers and the process should be as smooth as possible that's why drux is created as high level language with a very efficient tooling for Developers we also want to focus on privacy and security and provide necessary abstraction for developers to write such applications and again we want it to be scalable performant efficient and maintainable

and developer friendly considering all that I said before and another important aspect for a normal application would be flexibility in backends as well so we created this language and here is the team meet Paul Jonathan Lucas Christopher me Veronica and John most of our team are here at the conference so you can find us at the a normal Booth so come speak to us any moment uh now let's speak about how you can actually use tricks language uh so first of all juic language can be used to

write the zero knowledge proofs uh zero knowledge proof uh plays a crucial role in decentralized application it allows parties to prove the validity of statement without reliving unnecessary information and um with with that you can use that to write systems such as secure voting system or private transaction on blockchain so it's very important and here is a scheme that can demonstrate which role Durex can play in that so uh joox is high level language so you can write your application you using the language and

as it's flexible in backends one one of the compilation Target would be vampire which is in-house language you we use in anoma for writing arithmetic circuits for zero knowledge proofs and a vampire being a flexible language itself it could compile to the different proving system backends such as Hollow 2 or plonk so basically writing one application using a high level Durex language with a which is effective and quite flexible for developers to work with and to create their type types and

business domain in the language you can actually get the approving system you need but in general you can write any decentralized application you using jurik's language and another example could be uh uni swap uni swap like application which is a swap and trading platform for your tokens or it could be open C like market for for nft on a normal protocol and basically any decentralized application you can think of off as well so now we understand better how we can use that let's speak more about

highlights of the language features it's functional language which is quite important because we believe that language being functional provides a lot of security by Design because it eliminates a whole layer of errors and bugs you can introduce and I will explain more on that on the examples I will provide as well but yes the idea is that it's important that we decided to go with a functional language and here you can see the example program written in drux it's a program that

describes the balances here we introduce the balance abstraction and some operation you can do with balances such as ADD balances together creates a empty balance negates the balance or subtract different balances and let's look closer to to what's written here first what you can notice is that syntax is a similar to Haskell or act like syntax it's because we take a lot of inspiration from those languages and if you're already familiar with functional languages it would be very easy to follow the syntax of juvex

but if if not this syntax structure is quite easy to follow and read another main feature of judic that it's strongly typed language so you can see that every function and everything is predefined with a type signature so which actually gives us a lot of information about what this function can do for example if you look at line 7 at add balance function you can see that it's already say that it will take two balances and will return as another balance so it can serve us as a documentation itself

uh but not only that we have built-in primitive types we can also introduce custom data types and in this example we see that on line one the balance itself is custom data type that we introduced in here with a type keyword and basically it represents as a list of the pairs of denominator and quantity together and you can work with that [Music] it's a very handy because you can actually represent all your business logic in the type system of your

applications that you need another feature I want to highlight is a polymorphic functions which means that you can write very generic functions that would work with a different data types in different abstractions that would mean that you can write less code and work with any type that you need in your system and if you look at line 15 in the negate balance function we are using map function that could be the example of such function polymorphic function because it doesn't care with which container it would work with it can can actually

change the inside of any container not depending on the type that container contains inside and we also have higher order function which means that our function can take another function as arguments or return functions so again if we look at the same map function we see that the first argument is actually the function that it takes so we don't say how we need to change every element of the container we just provide one as one function in order to say how to apply this function to each

element in the container so another thing which is very important in development of drugs is referential transparency a referential transparency means that each expression can be replaced with the corresponding value and the output will never change so if we for example create two balances as an in example one B one and B2 and use add balance function with them or we just directly use add balance function with a function run of balance

it will make no difference it will work the same each time or we run that it's very important because we will have the predictable behavior of the program each time so it gives us opportunity to reason about the effectiveness of our application or the outputs of our application as well and um two weeks being the in-house language that we are creating means that we can take the best of any existing languages so we can integrate all the best features that we will think that we think um will be best for creating

decentralized application and have it implemented in jurix itself so currently from the functional programming we are using Purity totality immutability pattern matching pattern matching means that as a function could decide which actions to run based on the pattern or of the inputting argument it has and now let's look from the perspective of juvik's project for Developers so first of all two weeks has a model system so each file each drux file is a model

and jubix Project X actually contains one or more more juice models inside here you can see the example of such models which is specified with a model keyword and inside each model we can also import all other models it could be either from the same project that we just implemented or it could come from the dependencies of the project which could be separate ux projects that you can use inside your application as well you can see online for example 11 and 12 there are examples of both such Imports one is from the standard library and another

from the another data TMP model of the same project another thing that we can do with models is to re-export it from the existing models so we can provide them more more beneficial way for for users to use our library or application by specifying the right export output of the model also we have a local model system so it helps to separate the internal Logic for from external logic of the application so if you need some Implement some

internal details inside the model you can do so without leaking these details into the whole application or other models as well and with that in mind we can have the nice testing system implemented provided through the testing libraries and here we can see example of how we can Implement testing our balance model with the usage of jurix test libraries we have the libraries for Boss implementing unit testing or property based testing as well and you can write it with you can run it

with a drux test command which will output all successful and failing tests another great picture feature for developers is a rebel which is a read evaluate print loop it's a interactive process that you can run in order to evaluate any expression and here is in the example you can just run any Mass multiplication or anything you can get information about any expression like we do with the type keyword here or even get the documentation for each function of your project

uh but besides that you can also load any model you are currently working at so in order to test this it very quickly and reduce the time development time for for your project you can load the model and test the function you are currently working at uh like in the example here we can load the balance model and use the function from that model inside the Ripple terminal um and uh we have out of box documentation provided as well if you provide the comments to your function to your types or to your models you can get for free the documentation provided in

HTML format which you use then can deploy somewhere where you want to have the reference to your project with all the corresponding documentation uh and um also we have already a consistent with the libraries that you can use in your project we can uh we have a standard library that has all built-in types and functions that working uh with them we also have containers which is the data structures such as set Maps hash maps and we have testing libraries a quick check and a unit testing Library as well and the best part is that you can add any

Library into the ecosystem and reuse that in any project you want as well and we support different IDs we have the plugin for for vscot that we wrote specific for for jurik's language and it has such features as semencing highlighting go to definitions uh preview of the documentation and so on and here in the example you can see that hovering can provide you information about every token about every function and variable in your project so it's quite handy to develop

with such hints and uh the same features are supported in the emac so if your emacs user we have emacs mode for that so it basically has all the same functionality as vs code plugin and it's not all the languages in development so we continue working on that and adding new features as well so here's a few things I can share that we are working at we are adding the support of record types which would help you to even even more precisely integrate your business Logics in your

type system of your application we are adding trades which are type classes like structures which will help you to write abstract functions that you will be able to use with different data types we are also working on formal verification capabilities in increase it which could include uh dependent types for example which is very important also for verification of your programs and we're constantly improving tooling and adding more documentation and libraries in the ecosystem and we also put a lot of effort in working on the compiler

efficiency and performance in for compile time and runtime as well so this is jurik's high level functional application so uh try it now and if you're interested we are having Workshop today at 4 30 in the workshop group so you can you can join us and our team will help you with your first two weeks application thank you very much [Applause] yes sorry we have time only for one

question if you have some you can ask or you can find us in the a normal booth and ask any question or at Workshop as well thank you