Taking Compositionality Seriously
DeFi Security Summit 2023 · 16 Jul 2023 · 8:33
Fabrizio Genovese of 20squares argues that many smart contract failures arise at interfaces, where contracts, chains or onchain and offchain components interact, and that the field lacks a deep theory of composition. He proposes category theory, with its functors and structure-preserving maps, as a formal foundation for reasoning about how systems compose, and shows graphical calculi used for quantum mechanics and for game theory, where composed diagrams compute equilibria.
Speakers
Topics
From DeFi Security Summit 2023, hosted by DeFi Security Summit.
Transcript
um hello everyone my name is Fabricio from 20 squares and today I wanted to talk a little bit about a technique more of what we do or stuff like that so okay this is the current state of the ecosystem I'm going to be honest I think that uh basically every Auditor in this room has had to shovel enough to know that you know we live in a time of often badly City specs badly implemented code and Auditors are basically called to fix that um if you you know listen around and look at what many people have to say
about methods to improve the situation at least to me it really feels sometimes that the proposal solution looks a bit like this like many people you know propose some fancy new cryptographic primitive that is going to solve everything and stuff like that but in the end at least my feeling is that sometimes what we still lack is a deep theoretical understanding of you know some of the things that go on uh in basically the smart contract and blockchain word more generally so uh for what I had to for what I experienced one of the uh worst Parts
um where a lot of Errors basically pop up are around interfaces interfaces here is a very Loosely defined concept for instance a contract calls another contract bad stuff happens multi-chain interaction bad stuff happens you know off-chain on-chain interaction bad stuff happens it feels like a lot of times when you have something of type A and something of type B interacting but stuff can happen now uh basically if you ask to you know a programming language Theory experts and people that do that that kind of
Kink they will tell you well we invented type Theory to solve some of these problems um that is true but sometimes that's not enough so in that picture you can see for instance a very well defined type a very well defined other type a very creative type conversion between one and the other that yes works but it really feels like duct tape again so what we if we had a formal solution to solve this uh basically the kind of thing I wanted to talk about in this talk is exactly that uh there is a mathematical theory that is called
category Theory um that I feel is very underrepresented in our community basically category theory was invented in the 40s and it's the formalism on which all the nearly all of the biggest achievements of mathematics in the last 50 years have been built upon and the idea is that category theory is the super glue of mathematics it really makes you able to describe what happens when things interact so uh in this image here for instance we have the basic object one of the basic objects of category theory that is the concept of a functor so the idea is that a category is basically a mathematical
object made of objects and structure preserving Maps between them if you are versed that could be types and functions between them it could be sets and functions it could be groups and group homomorphisms it could be I don't know topological spaces and continuous maps that the list can basically go on forever but the idea is that you can package the idea of a particular structure a particular flavor of structure into the notion of a category and now you can basically have the notion of a morphism between different categories that is basically a kind of coherent transformation that allows you to morph this structure to map it to another kind of structure so that's
exactly what happens there I have a notion of objects down a b and c and Transformations between them that can be composed and the idea is that I also have another category upstairs and a functor is exactly a map that allows me to map objects into objects and Transformations into transformations in a coherent way now you could be like okay interesting but what do I do with that well funnily enough basically in the last 20 years or so a category theory has been used extensively to model things that are kinda not really related with mathematics so I mean not yet joking they are but not as much as you would
expect so for instance this thing here this kind of a weird bunch of dots and stuff it's a pictorial calculus that allows you to do quantum mechanics basically these kind of pictures can be manipulated in a very formal way and they allow you to reason about quantum mechanical systems and they allow you to instantiate Quantum algorithms and Quantum protocols without touching linear algebra at all like you can basically play like a little kid with these things and you can verify improved properties about Quantum stuff how does it work well it works because there is category Theory underneath that
basically uh says to us that we can consistently mapping all the linear algebra that we usually need to do Quantum Computing into these pictures so the idea is that you do all this giant work it took like 20 years or something and then you can hide it and you can basically let kids playing with these things and they are happy and you can do Quantum computing similarly here we have a picture of basically the bread and butter of what we do at 20 squares this is a graphical calculus that allows you to do Game Theory and in fact those things depicted there are basically the prisoner dilemma the idea is that you have two players that are the two triangles they basically perform an action this action
gets piped into a payoff Matrix and the payoff Matrix basically gives back the um payoffs to the players uh again you can follow these as a picture but the funny thing is that again there are categories in the back that basically tells you yeah these things compile to games in the traditional sense and I kid you not basically we implemented this thing you can compose this little Lego bricks and then you can basically push a button and compute the equilibria of this game um so yeah uh in here we have again other categorical stuff I'm not really going to talk uh in depth uh about this but
basically I guess that the gist of this talk is that uh yeah category theory is really the math of composition and studying it in depth will you know really turn your understanding of mathematics and how interfaces work interface between thing upside down so that guy in the picture is a guy that did a ton of category Theory and I mean you see how it started and now it went it ended probably that's not a good example but yeah I mean uh and yeah so in all in all is through theories are just theories but when you have a good
obstruction about your problem I think that really helps you understanding what's going on so yeah I think that's it I just wanted to point out to you that this thing existed and look it up on Wikipedia if you want I'm done thank you thank you