Code Monkey home page Code Monkey logo

pinballctf's Introduction

This is an attempt to solve the CTF in Rinkeby https://rinkeby.etherscan.io/address/0xffb9205c84d0b209c215212a3cdfc50bf1cfb0e0#code using hevm.

The goal is to ask hevm for an input that leads to a high score by asserting "the score is always less than X". If hevm can prove that this is false, it will give us the input to reach that score.

In the original code, the input is a bytes memory. Unfortunately hevm does not support symbolic dynamic types. However, the input actually has a fixed length of 512, so we can change that to bytes1[512]. A few other changes are required in the library helpers functions to read bytes and integers from the bytes1[512] array instead of a dynamic bytes. The full contract with all the changes is in PinballHevm.sol.

The file Helpers.t.sol has a few specific tests for those helpers. The file Pinball.t.sol has tests for both the original and hevm contracts. It has a few solutions and scores that were already sent to the contract, that I use here mainly to get some coverage on the PinballHevm contract and the new helper functions, and to check that I didn't break anything in the original contract. These are all the functions that start with test_. You can run them with

$ dapp test

or

$ dapp test --verbosity 3

to see all the emitted events and the actual final score.

Finally, function prove_high_score_letsgo is the one that tries to symbolically find the input leading to a high score (all functions named prove_* run symbolically). The target score is specified in the assertion at the end of PinballHevm.sol::play. That function is commented out so all the tests pass currently. Uncomment it to see it hang :)

You might also wanna check dapp test -h to see the options regarding SMT query timeout and the allowed loop max iterations.

pinballctf's People

Contributors

leonardoalt avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.