TritonVM / tasm-lib

A collection of functions written in Triton VM assembly (tasm)
Apache License 2.0
11 stars 2 forks source link

Return both "write" and "read" address when statically allocating memory #119

Open Sword-Smith opened 1 month ago

Sword-Smith commented 1 month ago

This is a common pattern:

let alpha_challenge_pointer_write = library.kmalloc(EXTENSION_DEGREE as u32);
        let alpha_challenge_pointer_read =
            alpha_challenge_pointer_write + bfe!(EXTENSION_DEGREEas u64 - 1);
        let beta_challenge_pointer_write = library.kmalloc(EXTENSION_DEGREE as u32);
        let beta_challenge_pointer_read =
            beta_challenge_pointer_write + bfe!(EXTENSION_DEGREE as u64 - 1);
        let gamma_challenge_pointer_write = library.kmalloc(EXTENSION_DEGREE as u32);
        let gamma_challenge_pointer_read =
            gamma_challenge_pointer_write + bfe!(EXTENSION_DEGREE as u64 - 1);

This is necessary because [kmalloc] only returns one BFieldElement, the address of the 1st word of the allocated section, which in the above example are called "write" addresses since this is the pointer you need if you are writing to this section of memory. If the type signature of kmalloc was changed to return two BFieldElements, then both the "write" and the "read" address (the last word of the allocated section) could be returned.