#DappCon22: Day 3 - Multi-Hop Transfers In The Circles UBI, Christian Reitwiessner
DappCon 2022 · September 2022 · 28:36
Solidity creator Christian Reitwiessner explains multi-hop transfers within Circles UBI at DappCon 2022, the trust-graph mechanism that lets the project route payments between users who don't directly trust each other. The talk digs into the technical design underpinning Circles' approach to decentralized, community-issued currency.
Speakers
Topics
From DappCon 2022, hosted by Dappcon Berlin.
Transcript
so yeah maybe just clarify one thing you I I work for the ethereum foundation but this is a private project to do in my free time um yeah if you so there's a link for the slides on the screen on screen if you I don't know want to have a better look um in this talk I will briefly describe the the actual token mechanism of the circle's uvi and then I will explain how multi-hub transfers work in this system to allow you to interact or transfer circles to people you do not have a direct connection with and I will talk about some challenges in implementing this and
um yeah at the end we'll have a a quick Outlook about the future of the of the Pathfinder so what does Ubi mean it's a Universal basic income some people say unconditional basic income and the idea is that every human gets a certain amount of money whatever that means per month or per time unit and you can spend it on whatever you like so that there are no constraints and you can also you're you're free to earn as much money on top as you like um yeah it's a kind of social welfare and the idea is that it because it it removes this uncertainty of of income uh that it boosts especially yeah creative
or high risk projects um but I'm not a social scientist so I will leave it at that we had a lot of talks about Ubi in general uh before so um my personal opinion and I think that was also yeah shared by some of the other people earlier that this is implemented best on a national level from by a government because then it's yeah it's just the easiest way to reach everyone but we're not there yet and that's why we choose the second best way and that's just yeah let's just build our own uh Universal basic income and because there's a blockchain conference here we use blockchain to do this
um and uh the biggest problem if we do this on our own is uh the so-called civil attack um this happens when the uh one person just creates 1000 accounts for example and then the system has to if the system just hands out money to these 1000 accounts then one person gets 1000 times more money than all the others and that's kind of bad not really working uh so there are several ways to avoid this problem one way is to just build a registry so humans go to some place and put their name there maybe their their uh national ID card may be a photo of their face and
then this registry checks that the same person does not sign up twice um yeah I think this is I mean this might be a bit more user friendly but I think it's not really elegant because then we have as we as we talked about in the in the uh previous talk then we have a central registry of all the data and we kind of want to avoid that and the the circles Ubi um yeah kind of puts the burden onto the user of deciding what is a unique human which also has its downsides but I I really like the system and so how does it work uh technically um everyone who signs up to the system so every account who signs up to that this
system creates a new erc20 token and uh these tokens are all different from each other but kind of similar and then you earn your basic income just by new tokens being new of so new units of your own tokens are created every month or every time unit and um then the receivable resistance is that if nobody accepts your token as payment because we have different everyone has different tokens if nobody accepts your tokens then they are essentially worthless and you can't damage the system because yeah everyone just has their own tokens and you're the fact that you have 1000 scam tokens that doesn't really influence the value of
the other tokens um and this accepting tokens or okay of course you can always accept tokens as XF tokens of other people as payment but there's also another mechanism and this Builds on the concept of trust and on a technical level a trust means so if we have an account B and the account b trust the account a then this means that anyone so really anyone can convert a certain amount of a tokens into B tokens one by one um and in essence this means that b says Ace tokens are worth the same as my tokens
so it's kind of a trust relation and how does that uh work to perform payments um this is done by so-called multi-hub transfers and these multi-hop transfers use this trust and conversion mechanism to to yeah internally um okay so as I said let's take a look at this in more detail so as I said every erc20 token can of course be sent directly to someone so if if B trusts me I can just send my my tokens to b or if I have B tokens I can also send my B tokens to that person and
that works as a means of payment I I'm also of course I'm also free to just send random coins to random people who don't really trust the owner of these tokens so this would not be a means of value transfer for the person I want to pay for they just would not accept it as payment but they still can do it of course I mean I can send tokens anywhere um and um and this multi-op mechanism what this does is uh it kind of automates the the way of swapping tokens between multiple users along our path
uh let's take a let's maybe let's take a look at an example so uh we have a person a and a person b and a person C A wants to send one token to C um a is trusted by B and B is trusted by C but there's no truss connection between a and C okay and we start out with a having one a token B having one B token and C having one C tokens these are all circles tokens but they are still different um and um yeah what we can do in this multi-hop system is we can send one a token from A to B this now has the effect that B has one a
token A and A has zero a tokens and then we then the system can automatically do in in the same step uh send one Beacon one B token from B to C with the result that c now has one B token and B still has this 1A token so at the end a has has no token at all B has one a token and C has one C token and one B token in in some C has two circles and a has a zero Circle so um this effective effectively was a circles transfer and in the end um uh I think Julio said it you have 160 different tokens in your account so if
you use this system the the tokens will just spread and uh you will have multiple different tokens in your account but the user interface abstracts that away and just says you have X circles um yeah this is of course a very very simple example and it gets complicated the more circles I want to transfer and as an example um just take a look at this graph here so this is an example of a transfer of 2539.32 circles from me to Martin and uh it uses I think it's 40 54 different transfers different single transfers
um yeah so this is how it can look like we will take a look at this uh website later and um yeah the the circus graph is highly connected we have roughly 20 trust connections from at each account so one account roughly trusts 20 other accounts and there is a you need five hops to go from anywhere to anywhere else inside this this truss graph and there are also many many fake accounts we talked about this earlier you can just because you can just sign up you can also create multiple fake accounts but um you can actually only abuse the
system if you have a connection to the other to the kind of non-fake accounts and if the connection has a high capacity so you can only extract as much money from the main non-fake system as this single trust Edge has as capacity or if you have multiple trust edges it's so that yeah um in total it's currently a little bit over 800 000 edges and um so the the Pathfinder is implemented as a Max flow problem on a multi-graph and uh you might already see the next slide it would get a bit more technical so but we will it will just be one slide
I just want to explain the problem in detail for people who are interested um yeah let's just do it so um the the pathfinding system is solving a maximum flow problem on a graph and the the actual problem is not really a Max flow problem it's but it's very similar and it's different in two ways and the first way is uh there can be multiple edges between two accounts there's not just a single ads but there can be one Edge per token uh in essence and that is what what you call a multi-graph in graph Theory
and the other problem is that it's not really a flow problem because flow problems uh just have that they have edges with capacities but we don't really have capacities but we have balances so if we have a token in one account and we move the token then the token is spending we can't spend it a second time so it's not really just a capacity problem and um I actually didn't find this reduction I don't know who it was it was in the original implementation and so the the way this is solved is by reduction to the regular Max flow problem and this is done by so first so as I said we have a multicraft so multiple edges between two
nodes and we just introduce new nodes on each one new node on each Edge so we get regular edges again and the capacitors are also modified a little so [Music] um we have the so we have the Edge from A to B and we split it into two edges and the first Edge to this inner node um receives the actual token balance of the account a as capacity and the second Edge is the is the trust capacity so if we if we choose to use this Edge in the in the final transfer then we can only use it um
as much as the balance dictates essentially and then if we if we from there go on to B then the um the trust is taken into account and this way uh this reduction both solves these constraints that we can only spend as much as we have and we can only transfer as much as we are as the the trust allows us to I think I'm a bit quicker than I thought but we have more time for questions afterwards um this is currently implemented in C plus plus and it also compiles ym scripting to JavaScript and the cool thing about that is
that you can run it in your browser and this is something I really like because in the end blockchains allow you to do uh actual peer-to-peer networks without the need for any server so you can run the whole pathfinding process on your your end user device and um um it's yeah increases uh decentralization and reduces the risk of I don't know service going down or being shut down or yeah um the trust graph is a 30 megabyte compressed binary currently uh so this is the downside of running it in the
browser because you need to download the 30 megabytes before you can use it but of course there is yeah a way to there's always a middle ground um and uh there's yeah one implementation of that when you run it in the browser then uh it takes a snapshot of the truss graph every two hours and it re-updates to the current state of the trust Network by connecting to a Json to an ethereum Json RPC um provider which you can run your own and yeah performance the search for a transfer path takes currently between one and five seconds to find the optimal solution and this of course also is true for the for the
server implementation and yeah this implementation is currently used both by by circles land and by by circles Garden so um future plans I'm currently re-implementing this whole thing in Rust which is yeah someone approves mainly to learn some Rust because it's fun but also because I think that it's uh maybe a bit easier to write a multi-threaded version of this so currently it's single threaded and especially in in the server implementation uh this is bad because you can't use multiple codes in the server you will get multiple parallel requests for paths from different
clients at the same time and that of course is better if it's multi-threaded and we also want to or I also want to write a version which so I said it takes one to five seconds to find the trust connection and it's of course bad if you want to send money and have to wait five seconds and then again you have to wait for the for the block time so I'm working on a version which just tries a direct transfer first which is immediate and then tries to find maybe a transfer that uses two hops and then computes the full transfer and um yeah if the first one already works then you can already use it um yeah so this is a website I built around the Pathfinder it's the URL is
Chris eth.github.io slash Pathfinder and you can use it to yeah to compute these transfer um multi-up transfer connections [Music] um you can also so it so this is this is the version that runs fully in the browser um it uh uses so of course the the icons are are pulled from somewhere else uh you can also use it to explore the trust networks of circle 2 by which is also quite nice so um um yeah for that you you enter an address
or a name a username here and then click on explore and then you have the graph here and you click on node and it opens new nodes and it's nice to look at and um yeah I think it also it's it's really cool to visualize um the capacity of the edges so thin edges have a lower capacity and thick edges have higher capacity in the capacity and um yeah that's all I wanted to say thank you for your attention and uh opportunity questions [Applause] I know that that was quite technical but you you need to think of everything he said in the current world setting so
when he talks about Hops and nodes your Banks already do that your Banks and the banking systems and the servers they already do that so there's a lot of real world in what he said it's just it has technical jargon instead so feel free to ask anything I think what he's trying to do is really optimize the system so you have to wait lesser time um in the days of past when immigrant workers used to work abroad remittance would take up to 48 hours and today it's much much faster so that's all thanks to technology so Daniel has a question for you so uh first thanks for your talk um can you
explain again how you expand the graph so you said that um sender receiver and token and you have to mutate a graph or change it to to make it a real max flow problem which you then can solve um I can try it again so the the database consists of edges of the form which have have a start and an end and a token and a capacity and the capacity is in yeah that that number of tokens um and regular regular Max flow
um graphs only have from Two and capacity so we just split this single edge into two edges by introducing an intermediate node and that's why how it gets into a regular graph so we introduced so we okay a is from B is 2 T is token so we introduce a new node which is just a pair of from and token and then we from there we go on to the to the end point of the edge okay I see now yeah thank you maybe I should have drawn a small diagram here sorry anyone else have questions here Julio has one
I am an anthropologist so I'm just curious about why is rust better at that or not better but more interesting to run the graph the Pathfinder than C plus plus or why is it faster or is there something about the rust language that makes it more interesting to use not really I mean it's the tooling is a bit better it's kind of it just feels a bit more more modern uh the speed is the same um and I just wanted to learn a bit rust cool and it has an integrated package manager which also makes it easier to to uh distribute it it's also awesome friendly
right like cosmosm or any sort of wasm Stack goes easily on it so this becomes multi-thread like you can be multi-chain easily otherwise you have to code everything yeah I mean I also compiled the so this um this inscription so this is okay it doesn't come out to JavaScript it's actually webassembly so we already had that but yeah it's a bit easier with rust that's true um I have a question regarding blocking paths which have been calculated in between one block time for example those five seconds on the extra or gnosis chain um have you thought about a solution how to
solve that challenge did you understand the question yeah so let me rephrase it so that the problem is trust connections change over time and if we calculate a multi especially a complicated multi-hop transfer uh at the time it reaches the network it might not be valid anymore because the trust changed um it's diffic I mean I mean that also happens for simple connections right it's just less likely because fewer edges are involved um one idea would be to just not max out the capacity but I don't think that really helps right because if you remove a trust then it's zero the capacity is zero so so yeah I just hope that it doesn't happen
too often for yeah for small value transfers I mean regarding balances as well it's not just a trust connection because like if one path is asking for 100 of of a tokens and the second one in the same block time is also trying to use those hundred a tokens um they are competing so who is winning or how can we but I'm actually not sure if balances are a problem here I mean the balance of the initial account of the center account is of course a problem anywhere in the chain but yeah there's a there's a weird thing in the code where when you send some money first to an account then you can send more money in the
Second Step but I haven't tried to exploit that so it might be possible to use that just weird in a weird way to order transaction so you send money somewhere that allows you to send more money there and then you take it away again to to balance it out so that that could work but I'm not sure if we should have used it thank you any more questions yeah also thank you from my side for your work on the Pathfinder and your presentation I have a question um about a different setup of of um using using the circle swap one could argue that
um there would be some upsides of there's a principle that one circle is always exchanged to one Circle depends one circle is this has the same value like one of your circles one could argue that putting a price tag on that so if I can say 100 circles I rather have my own circles so but I'm ready to exchange 100 Circles of my circles to 98 of your circles if and philosophical questions aside that you could want that or not because of equality if you would put like an exchange rate between circles individual circles how much would that make the pathfinding more complicated
would you have a guess on that yeah that's a good question I think it wouldn't be too much more complicated because the the main problem is is just exploring this large graph I mean it it adds a multiplication so the main problem is exploring large graph and handling the the 256-bit numbers and you would have a multiplication on these numbers which is also quite expensive you would have the additional interest of finding the cheapest path to exchange so because I lose I lose some value in the exchanges so my new interest would not find to find like the the the the easiest flow but how can I exchange the
tokens in the cheapest way so most of my value gets to the recipient I think he would have to use a completely different algorithm in that case yeah that's true hello thank you um compared to trust lines that we just heard that they said the transactions or the operations try to minimize the depth to other accounts is this implemented in some way here like for example trying to give back the tokens to their own owners
or is something desirable yeah that has come up earlier as well um it's not taken account at all um what I do is I try to find a a a multi-hop transfer that uses as few individual transactions as possible because that if you have more than I don't know 12 transactions or maybe 20 then it doesn't fit the gas limit anymore uh but I don't try to return the the tokens to the original owner I mean they don't I think they they don't wander around too much anyway right because
your tokens will only be in the accounts of the people you trust or that trust you or in in organization wallets or something like that so uh we just had a discussion about um the complexity which basically comes with trusting people and uh untrusting people and uh I I couldn't answer the question uh what happens if you like got 50 circles from somebody you once trusted and then untrust yeah I mean in
the worst case you uh I don't know there's a fake account uh that is discovered and it's completely shut off from the network but you still have tokens from that fake account no I'm really talking about once a friend not anymore a friend oh um I think you can still uh transfer I mean okay I already said the opposite but there is still a way to get to try use a multi-hop transfer to uh get that change that to exchange that token into other tokens I think any more questions um yeah I guess related to what Yuna
just said is very risk but it gets harder to transfer over time if we don't try to concentrate the same types of tokens in the same users because if you trust like 200 people you'll likely end up like entropy wise with 200 different tokens and if you want to um transfer all of those you can't do that in one transaction you'll have to do many more transactions than if you try to like um keep fewer tokens in each account yeah I I mean I could imagine to just
build a separate tool that tries to yeah reduce the number of different tokens you have um I think that might be better that you just do that at a regular interval you just clean up do some housekeeping uh and not put that into the pathfinding itself yeah interesting yeah thank you that's all the time we have today we will move into a coffee break thank you so much for your time Christian thank you thank you [Applause]