Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Memory Model: pointer casts are not handled atm #147

Open
dkales opened this issue Nov 15, 2023 · 0 comments
Open

Memory Model: pointer casts are not handled atm #147

dkales opened this issue Nov 15, 2023 · 0 comments

Comments

@dkales
Copy link

dkales commented Nov 15, 2023

At the moment, pointer casts are not handled in the current memory model.
We encountered the issue because our mlir-toolchain packed some constants into a dense byte array (probably to reduce assembly size) and then later indexed into this array using a pointer of the original data type.

Since each constant is currently put into a single cell, the loads do not correctly recombine the (e.g., 4) bytes needed to correctly load an uint32_t from the uint8_t array.

here is a small example demonstrating the issue:

#include <stdlib.h>
#include <stdint.h>

#ifndef __ZKLLVM__
#include <iostream>
#endif

uint8_t global[4] = {1,1,1,1};

[[circuit]] int memory_demo() {
    uint32_t* ptr = (uint32_t*)&global[0];
    uint32_t val = *ptr;
    #ifndef __ZKLLVM__
    std::cout << val << std::endl;
    #endif
    return val;
}

#ifndef __ZKLLVM__

int main (int argc, char *argv[]){

    memory_demo();
    return 0;
}
#endif

The compiled version returns 0x01010101, while the assigner version returns 0x01;

We could work around this at the moment by forcing our mlir-toolchain to output constants as arrays of their original type, so this is not that big of a priority for us, but we were told to open an issue either way.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant