NethermindEth / cairo-vm-go

A virtual machine for Cairo written in Go
MIT License
79 stars 49 forks source link

Different memory file generated compared to other VMs #395

Closed har777 closed 3 months ago

har777 commented 3 months ago

The same compiled cairo file seems to be generating different memory files depending on the VM used.

The comparisons are made between the original python vm, lambdaclass rust vm and our go vm. I'm using shasum to check if the files match. The steps to reproduce this is at the end of the issue. I'm not sure if I'm testing something wrong or if there is indeed a bug.

Examples:

  1. rust vm and nethermind vm match but python vm is different:
    
    from starkware.cairo.common.alloc import alloc

func main() { alloc_locals;

let (local p) = alloc();

ret; }

comparing generated memory files: 601af58bee65974f8a742a35684bde3929ccb5329da5cdcf1522bff3ad0aba75 lambdaworks_rust_memory 601af58bee65974f8a742a35684bde3929ccb5329da5cdcf1522bff3ad0aba75 nethermind_memory 6ff36c06517cc549f8a9c728e544425f47871462a7abff7f1060d593a3a74348 starkware_memory

func get_z() -> (z: felt) {
    return (z=123);
}

func main() {
    alloc_locals;
    let (local z) = get_z();

    return ();
}

4e11c3548b4d158bd12c773315b456be191c8d188a2de6d9b6a6e8fb7af9ee9f  lambdaworks_rust_memory
4e11c3548b4d158bd12c773315b456be191c8d188a2de6d9b6a6e8fb7af9ee9f  nethermind_memory
7704c8a11392ea8c1b73fd7bb5e4b7ab9a3a95fdd5067aad740f90e40dc11010  starkware_memory
  1. rust vm and python vm match but nethermind vm is different:
    
    %builtins output

func main{output_ptr: felt*}() { return (); }

comparing generated memory files: 59ec4a9c715e8ad336ec953fb06279c107fde622759910669c198b4670064df9 lambdaworks_rust_memory 44c1ed850fbb5e96974ad639ab45b1d4bd71b9c31a3f697176ab8fdef003cdc2 nethermind_memory 59ec4a9c715e8ad336ec953fb06279c107fde622759910669c198b4670064df9 starkware_memory

  1. all 3 vm's differ:
    
    %builtins range_check

from starkware.cairo.common.alloc import alloc from starkware.cairo.common.uint256 import Uint256 from starkware.cairo.common.cairo_blake2s.blake2s import blake2s_add_uint256

func main{range_check_ptr: felt}() {

let high = 10633823966279317261796329637309054975;
let low = 340282366920938463463374607431768211424;

let (data_new) = alloc();    
blake2s_add_uint256{data=data_new}(Uint256(low=low, high=high));

return ();

}

comparing generated memory files: dafd786a6a4611e78f381732ce0e586086075a4dc9ceae43e8bf74064bb08e8a lambdaworks_rust_memory 4f20bf80d128aae56316532464d0b524d4c1226b6f3dad5caefeed301aceffdf nethermind_memory bf0d2f982a44586ce9b8fce28ccf63c52ff996fbbf3d70aac37861638cde5929 starkware_memory

Steps to reproduce:

Compiling

cairo-compile test.cairo --proof_mode --output ./compiled.json

Python VM

cairo-run --program compiled.json --proof_mode --trace_file starkware_trace --memory_file starkware_memory

Rust VM

cairo-vm-cli --proof_mode --trace_file lambdaworks_rust_trace --memory_file lambdaworks_rust_memory compiled.json

Nethermind VM

cairo-vm run --proofmode --tracefile nethermind_trace --memoryfile nethermind_memory compiled.json

Comparing memory files

shasum -a 256 *_memory