Ledger-Donjon / rainbow

Makes Unicorn traces. Generic Side-Channel and Fault Injection simulator
GNU Lesser General Public License v3.0
172 stars 34 forks source link

Rework tracing and priniting #45

Closed J08nY closed 1 year ago

J08nY commented 1 year ago

This PR is a rather significant rework (and cleanup) of the tracing and printing setup in Rainbow. It moves away from setting booleans on the Rainbow object to configuring the tracing via a structure passed in the constructor, which allows for setting the leakage models and tracing different things more easily. Printing is also handled similarly. This allows the Rainbow instance to only add hooks it needs for the requested options, which makes simulation quite a bit faster if not all hooks are needed.

This PR also includes several other leakage models (identity, bit, slice, Hamming weight, Hamming distance) which can be set for any of the tracing options (memory value, memory address, registers).

It also contains a bunch of cleanups and fixes. Some examples were re-applying the Hamming Weight function to already Hamming Weight leakages, etc. The generics code is also rather simplified, with standard class attributes making most of the setup of the generics.

The Rainbow instance API is also harmonized a bit. An explicit call to .setup() is necessary to setup the hooks, but doing this after loading the binary makes things faster as loading is not slowed down by the installed hooks.

I believe this PR improves the overall usability of Rainbow. I started working on it after trying to use Rainbow for a bit and hitting its limits with unclearly named arguments, limited tracing options, etc.

yhql commented 1 year ago

Thanks for what looks like really great improvements :) (and the quick fix for Python 3.8/3.9) Can't take a look right now but will do soon

J08nY commented 1 year ago

Hey, thanks for checking this out. I am open to changes in the PR if you would like the API to look differently. I would also like to document the API a bit more.

J08nY commented 1 year ago

I cherry-picked some commits from #43 to make this branch also work with Unicorn 2.

J08nY commented 1 year ago

Hey there, any update on this? We are using this fork in some of our applications and it seems quite a bit faster than the original code (when not all features/printing/tracing is enabled).

J08nY commented 1 year ago

Pinging.

yhql commented 1 year ago

It's on its way. I'm testing on a few cases when I grab the chance but everything looks very good and well designed, thans very much again. The 'blocking' point here is about the way we copyrighted things and how to integrate your name to it, for which I need a more formal approval from another team.

yhql commented 1 year ago

And just had my answer. Everything good to go, thanks very much for your work !

J08nY commented 1 year ago

Thanks a lot for merging this. We are using this to run simulated attacks on generated ECC implementations in https://github.com/J08nY/pyecsca-codegen.

yhql commented 1 year ago

Thanks for the heads-up, interesting project! :)