Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Memory Model: pointer casts are not handled atm #147

@dkales

Description

@dkales

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions