Talk: Fuzzing the Ethereum Consensus Layer

Secureum Talks · 14:22

A security lead from Sigma Prime, the team behind the Lighthouse consensus client, shows how fuzzing is applied to the Ethereum consensus layer. The talk walks through Beacon Fuzz: coverage-guided fuzzing per client, structural fuzzing in Rust, and differential fuzzing across the five production clients. It highlights the bugs found, from SSZ serialization panics and denial of service conditions to off-by-one state transition errors and a BLS signature malleability issue, and the ongoing work ahead of the Merge.

Topics

From Secureum Talks; community: Secureum.

Transcript

[Music] um hey everyone so rajiv already introduced me so yeah uh here i am um i'm here to talk about fuzzing those of you who know sigma prime probably know that we're really big fans of this security testing technique and we've been applying it for quite some time now to various projects including the ethereum consensus layer so i'll talk briefly about who we are what we do we're headquartered in sydney but we've

been hiring people all around the globe we're about 25 people so relatively small-ish team dedicated to the blockchain security world really there's kind of two divisions i i head up the security assessment services arm of the business i put up a few of our clients logos i'm sure some of them are familiar to you guys um but we're also the founders and maintainers of lighthouse the rust implementation of the ethereum consensus layer so this started as a little side project by my co-founder paul and has turned into this massive beast responsible for securing billions and billions of value it's the second most used uh consensus client after prism and speaking of steam it's focused on

security kind of natural considering the dna of the company uh it's heavily optimized for performance and it's free and open source um and it started about four years ago now crazy the beacon chain most of you know i'm sure that we have five production clients so lighthouse in rust lodestar in typescript nimbus in nim prism go and taku in java so a whole heap of different programming languages that we get to play with as part of our fuzzing efforts um and i'm sure you know that we've had a beacon chain now for quite some time uh it's launched on december 1st 2020 and i'd argue that it's been quite successful i remember a bunch of people on the internet um

being really worried that we wouldn't reach the threshold are required to activate the actual beacon chain a few days before the launch we obviously got there and we now have about very close to 10 percent of the total heat supply staked in ethereum which is pretty cool so if you've been uh involved in the beacon chain if you've been validating since genesis you should have made as of today about 3.1 3.2 ether depending on which client you use depending on how many proposals you got if you got any slashings as well they do impact your profitability heavily um so yeah about a hundred thousand uh eth rewarded i guess over the past few months

cool so let's let's dive into uh fuzzing a bunch of you guys i'm sure are very familiar with this testing technique uh it's just essentially the process of submitting a whole heap of randomized inputs to a certain software um so and monitoring for abnormal behavior software crashes panics and things like that so yeah it's it sounds very simple but there's a lot of different layers to it right so you can basically pick a function hit that function with a million numbers of of different inputs and uh and monitor for any anything that is you know behaving differently than what the developers have intended you can take that approach to another

level when you have several implementations of the same specification you can perform differential fuzzing so instead of fuzzing all these um software like individually and separately you can basically provide them with the same input and compare the output this is particularly interesting uh when you have as i said multiple implementations in different languages some of them perhaps heavily optimized other not so much of the same spec and this is critical in identifying consensus logic flaws and this is basically what we've been doing with beacon fuzz the differential fuzzing framework for the consensus layer a bunch of

items icons here are no longer really a thing so trinity was the python implementation by maintained by the ethereum foundation that's long gone now serenity i don't know if proto is in the room but um it's it's proto's baby um and i heard actually earlier this week that he's reviving it and uh giving it a second life um so this is what we've been doing essentially using beacon fuzz as an orchestrator to hit all these uh clients and compare the output of their state transition functions to essentially identify potential discrepancies and deviances from the spec so beacon fuzz itself just a quick history of the project um in march 2019 uh guido of rankin um

martin mentioned him earlier uh martin's very familiar with his work um has started this but had started this project and he named it kind of in e3.0 fuzzing that was simply c plus plus orchestration basically with lip fuzzer with limited set of targets and functions uh covered but he managed to find a whole heap of bugs within a few days right guido perhaps lost a bit of interest in the project and kind of moved on to other things but the theme foundation was really really keen on having someone some entity pick up this effort revive it and really extend it to the extent where we would add you know all clients all state transition functions so that's what we've done we were granted a grant from the the ef in 2019 in september 2019 and

we extended we started by extending the project and you know adding more clients more functions more fuzzing engines and finding new bugs so that was fun but we really quickly kind of realized the limitations of the existing framework and decided to redesign it completely revamp it completely and rewrite it in rust um so this is what beacon fuzz really is so beacon fuzz the project itself is really a collection of different um fuzzing frameworks and fuzzing tools so i'll go through those three um sort of green boxes are the three main components of beacon files the first one is e3 fuzz and that's really our standalone

coverage guided fuzzer right so this targets each implementation separately for each client we would write fuzzers that would first target the state transition functions and that would be coverage guided meaning that we can support a whole bunch of different engines lib fuzzer is kind of the default one go go-to fuzzing engine but we've been experimenting with afl hunk fuzz obviously when dealing with um java clients we kind of need like a specific fuzzing engine so we've played with jqf that was particularly slow i think we're getting about 10 15 executions per second that's really slow in fuzzing and we were kind of saved by jazzer that was released

later on late last year which you know speeds up things really really considerably and the idea is to essentially come up with a set of valid inputs right so you want to fetch beacon states that you know are valid you want to fetch beacon blocks proposal slashings attestations etc from the spec tests from testnet from mainnet even these days and feed that to these fuzzing engines and you essentially instruct those fuzzing engines to perform their mutations and yeah just produce these inputs send them to the right functions and hopefully i mean hopefully for us get some crashes um and that's what happened um but the

thing is if you don't include any structural fuzz ink i'll explain what this means in a bit you essentially keep hitting the serialization the marshalling and marshalling right and most of the bugs that ethan's fuzzers have been able to find are on ssz and ssz is the serialization format that we use in the consensus layout it's very hard to get right i'd say every single client had had critical vulnerabilities on their ssc implementations over the past couple of years not a single one was uh sort of flawless so it's difficult to get right because we got like dynamic lists dynamic types

um so yeah pretty pretty tricky stuff so it's don't get me wrong it's really good that we can pick up these bugs on the ssd level on the serialization level but we're really interested in hitting the state transition so how do we do that structural fuzzing right so there's this beautiful thing called um the arbitrary trait in rust which if you derive it for classic types or implement it yourself for complex types gives the ability for leapfrogs or cis not getting into too many details it's like it's a rust crate that essentially instructs your fuzzing engines to conform to a certain grammar right so you have your your structs that are in some cases quite complex in the e3 well sorry ethereum consensus world um

and uh and yeah so you basically derive that trade or implement it yourself and then your photos are like okay cool i now need to comply with this this set of rules uh and that allowed us to as i said hit state transition functions and dramatically increase our coverage so the type of bugs we've identified a whole heap of panics on the civilization as i mentioned so things like memory exhaustions kneel points neil ported the references out of band memory accessors as david mentioned yesterday denial of service vulnerabilities in this context are pretty bad right like if i can come up with a certain packet and just broadcast it to the network and take offline perhaps you know the whole

network or majority of it we're in trouble right so we treat dos conditions as extremely serious and critical um a whole bunch of interesting panics as well what happens when you put in your enr non utf-8 characters like emojis and whatnot some clients didn't really like that um so yeah a whole heap of different bugs have been identified through e3 photos the other um component i'd like to briefly mention is e3 diff and to be honest that's not i wouldn't even call that a fuzzing tool really it's more of a debugging tool it's a wrapper around a bunch of client utilities that implementers have made available to us so thank you so much to all the client teams who have worked with us over the past years to provide us with this super useful

tooling and we basically when we when we pick up an interesting input with eth2 fuzz for a specific client we want to make sure we want to observe the behavior of that input for all the other clients right so if we get like a memory memory leak or just like a hang a timeout it might be something interesting as well for other clients so this allows us to very very simply yeah just test those other clients and replay essentially those samples across all of them um and it's been really uh really interesting you think you you wouldn't find much using that but we did find a lot and i think perhaps one of my favorite bugs that we've found is the last one i mentioned in this slide

we found a way on on a client which shall remain unnamed to mint ether in the beacon chain without actually depositing it in the deposit contract so that was quite fun essentially bypassing the whole miracle root verification at the at the beacon chain level so that was cool and then beaconfuse v2 which is i'd say where most of the value add is this is where we perform our differential dynamic fuzzing so using foreign function interfaces ffi bindings this is written in rust right so if you're hitting the lighthouse you sweep you just import the crate it's a native call no worries but how do you do that how do you call you know go functions

java functions javascript functions from rust code and the answer is ffis um it's it's good it's modular but it's very slow right and and when you have five six different clients all of a sudden your fuzzing architecture just gets out of hand and it takes a while to build a while to to to execute but it's super effective at catching consensus bugs uh we found a whole heap of by one errors in the state transition functions which you know could cause an actual consensus split on the network so really bad stuff that we were able to catch using this fuzzing technique another one which was cool so as i said we were focusing on state transitions but we've

also done a bit of work on the bls signatures that have been used and one of our teammates have found a really interesting signature malleability vulnerability on the most used bls library so that was cool and as you can imagine that got patched pretty quickly and yeah so just again give you a quick overview of what we've been finding every single client had bugs right even lighthouse and that was fun some of them as i said were really really critical and could have taken down the network very easily the fuzzing the distribution professing tool as i said e3 fuzz allowed us to spot a whole heap of denial of service

conditions beacon first v2 about nine to ten interesting most of them critical consensus depleting bugs and then the re-player or easter diff uh was also instrumental in catching some of those so yeah a lot of uh a lot of cool stuff um i kind of rushed through all of it so that we can have time for questions there's a bunch of ongoing work as david mentioned we're actually fuzzing as we speak the belatrix branches of all the ethereum consensus clients getting ready for the merge and yeah hopefully catching some nasty bugs before they hit production thank you [Applause] [Music] you

Related talks