keep-starknet-strange / raito

Bitcoin ZK client written in Cairo.
https://raito.wtf
MIT License
40 stars 34 forks source link

[feat] Generate Utreexo integration tests #273

Closed m-kus closed 1 week ago

m-kus commented 2 weeks ago

Context

We are porting (a subset of) rustreexo to Cairo and we also need to adopt their testing suite to ensure correctness.

Task

Generate a Cairo file with unit test stubs so that each stub contains test case data (initial roots, leaves to be added/deleted, proofs, expected roots). We will add the actual execution later.

Step 1: pre-process files from https://github.com/mit-dci/rustreexo/tree/main/test_values by converting them to a flat list of identical test cases (removing unnecessary info like cached nodes and adding missing data like expected roots).

Step 2: code generate Cairo unit tests using the processed data.

You'll end up having two Python scripts that do the job.

Implementation notes

Expected processed file format:

[{
    "type": "<test type: add,verify,delete,update>",
    "roots": [],
    "numleaves": 0,
    "expected_roots": [],
    "expected_numleaves": 0,
    "leaves_to_add": [],
    "leaves_to_del": [],
    "proof": { "targets": [], "hashes": [] },
}]

Expected Cairo unit test:

#[test]
fn test_add_0() {
    let test_case = UtreexoTestCase {
        type: UtreexoTestType::Add,
        roots: [],
        ...
    };
}

Note that depending on the test type some data might be omitted.

Test data pre-processing:

Write files to the following locations (one for each test type):

Place definitions of UtreexoTestCase and UtreexoTestType to packages/utreexo/tests/lib.cairo