Henri Binsztok / DCxPrague
DCxPrague 2023 · November 2023 · 28:23
Henri Binsztok, co-founder of OK Contract, sets out a path to decentralize any front end. He explains why hosting a build on IPFS is not enough when a centralized API remains, how MiCA raises the stakes for DeFi projects, and why standardizing transaction semantics helps. The talk introduces a functional specification language, an SDK and decentralized API nodes, followed by audience questions on gateways and mobile.
Speakers
Topics
From DCxPrague 2023, hosted by Duct Tape.
Transcript
hi thank you so hi everybody uh my name is Henry or H in French and uh I'm the co-founder at OK contract uh where we basically try to redo the front end stack uh differently for for for crypto so the talk today is a path to decentralized front ends and uh we'll see uh basically why uh we want decentralized front end like we've been preaching uh in the desert for a couple years telling people you know it's very important to to to fully decentralized front ends but now there's uh some help coming in and that
help is for instance the MAA regulation uh in Europe uh which um let's say puts a strong incentive uh for defi project especially to properly decentralize their front end uh because they don't want to to bear responsibility and to do this they must let's say prove that uh they are decentralized and if you look at some of the articles that many people are publishing uh there's a lot of let's say discussion about what it means uh being uh fully decentralized uh because the the law has kind of this kind of meaning um so if you look today at uh what many project does do like dopex or
liquid uh they use e Lio which is basically a way to properly support ens to ipns to ipfs uh redirection for browers uh that don't support it because hopefully one day uh we will have native ens resolution in all browers and if we do so of course uh that will be even easier to do the the the whole path so in the end uh we have decentralized storage uh and we have a website which loads from decentralized Storage uh but the question is what do we put exactly on ipfs so what we put on ipfs is mostly the build artifacts so you have your
whole front end Cod base uh which is usually a complete mess of libraries and mpm dependencies uh a bit more about this later uh and somehow you manag to build it successfully and repeatedly uh with reliability and you say okay this is what I'm putting on ipfs and now my uh my protocol has a decentralized front end and we've seen a lot of projects uh mentioning this uh that way however uh if we just open uh the the the source code of the page uh this
is an example with for dopex on on E Lio uh and basically we see very quickly in the code here in the middle there's app. dep.io and which is uh of course uh an API kind of look centralized uh and in fact we had some discussions uh so we ask some lawyers they have different advice and we ask the best lawyers of all no I'm sorry it's just a joke uh so obviously if chat GPD uh is aware that probably uh if you have a single API endpoint mentioned in your decentralized storage somehow a
judge will say that uh it's not really decentralized and um there's I would say one very simple litmus test and that litmus test is basically uh if we somehow shut down or configure the network to to block that centralized API is the the the decentralized website still working and of course the answer is no the the the the the dabs don't load if you shut them from that API uh I'm not a lawyer myself obviously but uh but everybody has their own conclusion so when you're a project you let's say have three GitHub repos you have your contracts you deploy them on evm chains you have your front end and basically
you your build actifa go to ipfs and you have your API which is uh usually AWS or gcp so basically is it decentralized the contracts yes the front end storage yes uh but the API is not so we say we're looking for Solutions we're Builders here and we say what's the best solution we can do uh and we heard several times the idea of making uh a decentralized community of nodes uh of VMS sorry run by different people different administrators and all of these apis would be quite diverse and
they would form somehow a decentralized set of API nodes for for each of the projects the problem is of course this is an OBS nightmare because uh the stack is completely erogenous uh there could be some njs could be some go some Rust uh and each VM instance should be maintained Maybe by a different operator so there would be what guidelines like a gab repo of guidelines on how to set up maybe a repository of scripts of Docker files and the the problem is that there's a lot of Maintenance usually coming in to to to to these notes so we thought that there could be one path and definitely it's not the
only path it's just a path to rethink uh how we do the current uh implementation of front ends of a a common let's say decentralized node protocol and to do this uh first I'm going to start with some bad news the bad news is we won't be able to reuse the existing front ends uh there probably are ways to do it uh but working on a more generic solution uh means that we need to standardize the build to decentralize the run but doing so we change the build and it's gets back to when uh I started a contract uh basically it was uh we started with one problem is uh the lack
of precise semantics for frontends and if you look for instance at one uh I would say State ofth art front end implementation and of course it's so State ofthe art that now they even want to introduce fees for it uh basically uh we look at just one page uh add liquidity and add liquidity is uh just cutting the story short uh 500 lines of code for just this single page and those 500 lines rely on a very huge amount of components and libraries so you'll see here you have a custom of course analytics package uh there's
react uh there's a web3 GS uh there's ethers as well both of them uh and where three react uh there's a a lot of dependencies and then we have a lot and lots and lots of components and hooks uh and uh to we see for instance to calculate slipage to calculate margins to list the different contracts that we are interacting with etc etc and if we are concerned of extracting the actual semantics and extracting uh what is that we are going to compute on that client to perform the transaction on user behalf uh we have to go dig uh
deeper and deeper in different set of rules which are usually uh interlined so there's uh the components and that code again is very well structured uh it's one of the best implementation that we we can find uh lot of definitions on uh the the getting the state of getting the transaction values the format compute the formatted amount compute the max amount etc etc and the lines go and go and go and and we still have basically uh the semantics of it which is spread over these these lines of code and it's only at the the function on ad which basically implementation begins like 200 that we have uh we are able to let's say
send the the transaction that we have computed and uh and catching it so so why this because it's very complex and our mission is how we can make it simpler and knowing that there's a lot of thing that we should compute on the clients we should compute wallet changes react to wallet changes our chain changes uh be able to customize the interaction for the connected wallet the balances Etc and sometime it's also more than one t in that code we see a lot of glue uh required to manage the approvals and sometimes on other projects there's a series of operation that you want to
do like migrate liquidity from one pool to another uh and coming next of course will be interaction with the 4337 bundlers which will change a lot the the the interactions and right now most of the bundles for for 37s still have one Tak and or called multic Cod so there's a lot of things that we can do better here but the front code is so complex already that it's hard to add them and sometimes also and maybe even Beyond defy uh but for defy as well we need more than onchain data there's this offchain data for instance nft marketplace with who have offchain order books uh or data intensive operation
that you cash on these API nodes and all these needs to be put together so the solution that uh we began to think of was how to solve build and run uh by changing the build so the build is first introduce a standard way to specify the smart contract interaction semantics which we think is lacking and then a SDK to easily insert these transactions into any web page dabs without uh touching again that semantics and for the run then since we are making let's say a new cleans uh clean sheet implementation of the frontend St stack then we can uh think of decentralized nodes and make
everything so that uh the SDK automatically uses uh a decentralized node protocol so to specify the interactions uh we introduced in fact um an purely functional language uh which we call lambas script and which is kind of let's say a lowlevel intent of the transaction or a high level uh definition of the of the transaction uh and just to give you one example uh so I could do add liquidity as well it's on the next slide I skipped it because it's just a bit more complex but not too much uh for instance if you want to swap uh basically you just need to say who's swapping to the tokens what's the path
that you need to send to the contract uh functioned in the standard library that helps compute the deadline and uh we also need for instance to to compute the amount out mean which involves uh RPC calls uh to the get amounts out function and this is a proper lambas script program which uh we can just take compile in advance into bite code being able to detect a lot of invalid uh specifications for the interaction generating compile time errors in the middle and then when we have this bite code which represent let's say a
seemingly valid transaction then we have a TX transaction engine which basically takes the user input uh and either gives a runtime error this time on the right or outputs the transaction and so basically the the the runtime the the engine is a VM uh which is uh based on reactive programming so that uh the the whole definition in fact is a reactive program and wallet events onchain events uh change the the the foundational data and everything is recomputed uh automatically and it automates two things the RPC access and as we'll see uh next as well the the centralized API
access so now we are working on the SDK that uh we should release uh in 2023 uh that's pretty soon uh just after this talk I will keep running code no I'm just joking and um so basically what we're building is so we have a way to specify uh interactions using uh an ID uh which is the hash of the interaction definition basically which you can as well visualize so there there there will be a front end to to to visualize them but most importantly how it works you just import new TX from the the the next uh okay contract SDK and you say okay we want to do the
transaction using that transaction ID and for instance we can set the value uh if we are swapping e to die here so we just select the amount and basically from that point on everything will be automated so for instance we can test that uh if we want to get the transaction from that high level specification then for the connected wallet it resolves to the the estimated gas amount uh it says that's the wallet which is sending the transaction to the contract uh here it's I think it's sushi swap on gurle uh the value that we specified Etc and all the parameters are
built and there's no errors uh we also can generate some information which is readily available uh for instance text or information bubbles or button names or everything everything that you can put as a developer into your UI uh without having nothing to do with uh Computing the the the complex parameters formatting the amounts uh that you'll get Etc so you can show this the way you want to the end users and uh from that point on it's one line to just send uh the transaction so we get a Ash and if we wait uh for the receipt uh then we get a successful trans action and that
you can display and uh and very easily so it handles input detection gas estimation updates including USD uh error management um and support as well multi-step transaction but that's beyond this this talk uh but getting back to the decentralized nodes part so what we have right now is a way to properly Define any kind of evm interaction so it could be def swap we have a a lambas script program an ID for that uh staking some defi PS uh adding liquidity or buying nfts uh or accessing nft utility or really anything because it's uh p t
in complete uh purely functional language so we can specify any kind of transaction and once we have this we have the opportunity to run one common set of decentralized nodes for every of these specified transactions so that's how it works basically the transaction engines uh is able to run any kind of program definition and connects to RPC and the backend API and the only thing that we have to do and that's kind of a joke only uh is to decentralize the node themselves so
there are Frameworks so just adding uh the consensus and uh of course making sure that uh the definitions of new interactions are properly written is something that is already taken care of by multiple Frameworks uh but here there's a bit of issue uh in the way we the nodes give trustful information to clients and this uh is something that uh I will speak about bit more on on Saturday uh and but basically we're building this set of backend apis uh which are decentralized uh and I didn't say permissionless so so basically it's
uh because if you want to make this backend apis permissionless then is another level but uh decentralized is uh is doable and with the following goals so the first goal is to be Universal and that's already tackled in the way we Define the semantics uh for for any kind of transaction another goal uh is to be performant and being cost effective uh in terms of runtime ideally there should be let's say in an order of magnitude no more of a head compared to current RPC nodes private nodes that you may use for for any kind of project and obviously uh uh we want to be compliant with uh
coming uh regulation for for being a decentralized protocol and a decentralized interface uh and uh I think that uh in that area will be probably as fine as can be uh the questions we have is uh how to balance uh performance and security uh because we can always be more secure but it has a cost and uh on the governance of the decentralized network as well so there's uh a lot of things that we're thinking of and if you have idas or collaborations happy to talk and of course the sustainability of the the ecosystem so how it should work
basically for the sustainability is we will have a community of node operators uh who will uh get API access fees paid by project there's uh one thing uh that we can do is we can control make sure that an API key is only used for let's say a predetermined set of interactions uh which is something that you is not easy to do with with RPC noes uh and also we can build Partnerships with uh Mev uh or or M sharing protocols and maybe we can return one part of this to the users to be as Fair as we can be or we can share
this with with projects and here those are really questions and I think there's uh there's a lot of discussion that we we can have this week on that topics so basically that's uh One path where we can decentralize in front end and as I said earlier it's it's not the only path of course there will be manually implemented front ends that uh everybody will try to run in a decentralized manner and uh of course it's let's say the the the closest way to do it compared to what exist today but this is another path where we need to start a new with a definition which can be done let's say pretty quickly uh and that
will give a lot of benefits like having uh another diverse implementation of front ends which I think is of good value for protocol to to resist censorship for instance uh and also that will come with the added benefits of being decentralized without too much effort uh which uh I think is a a pretty good value so just to to sum up a bit the architectures that we discussed today uh will build front ends and store the the the artifacts on ipfs just as we do today to decentralize front ends properly and that will give uh a user interface which includes the okay
contract SDK and the okay contract SDK manages automatically connection to the RPC node to wallets and uh to the of course the decentralized uh API nodes uh of the okay contract protocol uh so that's uh that will be the yeah the LA the last slide and uh how to to contribute there's uh several things uh that uh we can discuss as well is uh formalization so right now we consider doing uh writing an EIP for the transaction specification so mostly for the functional programming language lambas script and uh the definitions of the standard libraries that that we put
in it and I would say that's an opportunity for other protocols to be present especially protocols that uh Target frontend developers somehow uh we probably can uh integrate and making your features available at uh at first level uh and that's something that uh that we can uh contribute on uh another thing is if you're a project uh let's uh let's build interaction together for for your protocol and if uh people are running nodes uh for other Protocols of course let's talk and uh and be a launch partner for for the node Runners so you
can learn more there's not yet too much public information but on okay contract.com and of course uh thanks for following us on on X now uh it's at okay contract and if you want to chat I'm often responsive on on X as well and I'm Henry _ okay I changed the the my handle name a bit too late so thanks a lot and uh I hope that uh it was a aning way to to begin the second day of Dev connecting Sprite thank [Applause] you [Applause] um I have a few questions uh the first
one um we saw the example of the uh prepared or to be prepared transaction right um and you you had there like the response texts mentioned there right which would be like populating the UI um uh do you Tre there somehow localization and internationalization yeah so of obviously yeah will'll be able to to to localize uh in the future so but for now the first version will be English only but of course yeah it's intern inter I 18n is do you think that that would like change the architecture significantly when you go like 118
uh I hope not I worked on previous project where we internationalized the the the front end and uh that's peripheral so so I I this is an extra module in fact added to to to the rest of the core so that should be easy and the second question is um um we are talking here mainly about the web front ends basically right um um since you were researching this field um have you also research the fact that that many users are actually moving to the mobile apps and um how that could be applicable or whatever there would be a way for the mobile apps even though we know that due
to the stores that there is some certain censorship or you know uh risk anyway but but is there any way for the mobile apps like you pres you presented for the web apps okay thanks for asking this question so yes the answer is definitely and mobile was first was fought first before any kind of implementation so of course there will be a mobile SDK coming in cool thanks thank you any question um if it sounds like there are sort of there are multiple things that you're packaging together that are probably useful independently right like the the setup that you have for you know decentralizing the API nodes seems
relatively independent of what happens on the front end right yes it's an added layer which benefits from the the specification because uh the the the way it in fact we specify the interaction make sure that we have common end points for any kind of interaction so that that's why basically it would be I think harder to adapt the decentralized nodes to the the existing front ends unless all the the the front end in fact change a bit the way they are implemented today yeah thanks
uh do you address uh another point of centralization which is access to ipfs actually like the Gateway because most users do not run their own nodes so they have to use this f. limo and it's still like it's still point of centralization that's the first question and I have another one left okay so very good question and uh so no right right now we we don't there are several efforts uh in the the protocol Labs Community uh in that regard and we will'll build on on whatever they they're doing and uh we already have enough problems on our own for for now and second question can Lambda be used uh for creating some kind of common line interfaces oh yes uh and in in fact
those tools do exist okay and it it started so the we started the The Core implementation with CLI thank you yeah um at the beginning I saw you had um like it would retrieve a widget with a code is that like a a widget library is the intent that that people will create widgets put it on like a widget store or yeah definitely so one of the thing in fact that uh we want to do as the the let's say Okay contract part brand somehow and this is how we chose our name uh is to give confidence in the interactions so so we will have a set of
these WID listed interactions uh and which are part of the the the node protocol so the these interactions in fact are stored in in the nodes okay that's all yep thanks to everyone in the questions and yeah for the talk yeah thanks everybody see
Related talks
- Freedom: A Browser for the Decentralized Web
- Decentralizing the Internet Collaboration Layer
- Decentralized video streaming: architecture, performance, and trade-offs
- Moving from MVC to SACI - a development framework for modern DApps
- Universal frames
- ChainSafe Products & Developer Tools
- Decentralized Web3 Infrastructure Karen Scarbrough mod; Nick Fett Tellor; Evgeny Ponomarev Fluence;
- EthCC 2: Lightning talk sessions
- oksolc, a Solidity compiler in Zig
