Skip to content

A Python-based predictor using z3 to reverse-engineer and predict random values generated by Math.random in V8 with 100% accuracy. This script leverages a series of Math.random() values (min 5) to deduce future states.

License

Notifications You must be signed in to change notification settings

sexfrance/v8-randomness-predictor

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

8 Commits
 
 
 
 
 
 
 
 

Repository files navigation

V8 Randomness Predictor

A Python-based predictor using z3 to reverse-engineer and predict random values generated by Math.random in V8 with 100% accuracy. This script leverages a series of Math.random() values (min 5) to deduce future states.

💬 Discord · 📜 ChangeLog · ⚠️ Report Bug · 💡 Request Feature


⚙️ Installation

  • Requires: Python 3.8+
  • Set up a virtual environment:
    python3 -m venv venv
  • Activate the environment:
    # Windows
    venv\Scripts\activate
    # macOS/Linux
    source venv/bin/activate
  • Install requirements:
    pip install -r requirements.txt
  • Install nodejs (optional)

🔥 Features

  • Debug Logging: Debug logging through logmagix that tracks each prediction stage.
  • Z3 Integration: Uses Z3 to reverse the XORSHIFT+128 algorithm behind Math.random in V8.
  • Custom Sequence Input: Optionally, input your own sequence of Math.random() values for testing.
  • Automated Prediction: Computes the next Math.random() output based on previous values.
  • Error Handling: Verifies the Z3 model's validity and provides detailed feedback.

🔍 Usage

  1. Generate Random Numbers: Use V8 (Node.js, Chrome, etc.) to produce a sequence of random values with Math.random(). An example sequence can be generated by running:

    Array.from(Array(5), Math.random);

    Optionally, set a seed in Node.js to reproduce the same random sequence:

    node --random_seed=1337
    Array.from(Array(5), Math.random)
  2. Run the Predictor: Input the random sequence into the script. For example:

    python main.py --sequence "[0.9311600617849973, 0.3551442693830502, 0.7923158995678377, 0.787777942408997, 0.376372264303491]"

    Or for testing purposes you can run the python code directly (requires NodeJS):

    python main.py
  3. Output Example:

    Using Sequence: [0.376372264303491, 0.787777942408997, 0.7923158995678377, 0.3551442693830502, 0.9311600617849973]
    States: {'se_state0': 4268050313212552111, 'se_state1': 6942842836049070467}
    Successfully guessed result: 0.23137147109312428
    

📹 Demo

Demo


📜 ChangeLog

v1.0.0 ⋮ 11/10/2024
! Initial release with Math.random predictor

Inspired by: PwnFunction

About

A Python-based predictor using z3 to reverse-engineer and predict random values generated by Math.random in V8 with 100% accuracy. This script leverages a series of Math.random() values (min 5) to deduce future states.

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages