keep-starknet-strange / raito

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

[bug] Client fails on block 51740: Couldn't compute operand op1 #245

Open maciejka opened 1 week ago

maciejka commented 1 week ago

Client fails on block 51740:

scarb cairo-run --verbose --no-build --package client --function test --arguments-file arguments-full_51740_1.json

with error message:

Running client error: failed to run the function Caused by: Couldn't compute operand op1. Unknown value for memory cell 1:65546

where:

same error on block 55861(small block, just 4 txs):

and 70183:

Minimal program on which the error reproduces:

fn main(arguments: Span<felt252>) {}

There seems to be some upper bound for the arguments of type array with length >= 2^15

Jeanmichel7 commented 1 week ago

Can I do it ?

m-kus commented 1 week ago

A bit of context:

maciejka commented 1 week ago

Possible directions of attack:

@Jeanmichel7 still ready?

Jeanmichel7 commented 1 week ago

@maciejka Yep

Jeanmichel7 commented 1 week ago

@maciejka Sorry, but what exactly is the error? I can't launch the client scarb cairo-run --verbose --no-build --package client --function test --arguments-file arguments-full_51740_1.json is not supposed to work directly, is it? with full_51740_1.json in client/tests/data and arguments-full_51740.json in client/.client_cache ? error: unexpected argument '--arguments-file' found

I can't launch it via client.sh either. scarb run client is supposed to work? What did I miss?

maciejka commented 1 week ago

It should work directly with scarb cairo-run ...

sob., 5 paź 2024, 18:58 użytkownik Jean-Michel @.***> napisał:

Sorry, but what exactly is the error? I can't launch the client scarb cairo-run --verbose --no-build --package client --function test --arguments-file arguments-full_51740_1.json is not supposed to work directly, is it? with full_51740_1.json in client/tests/data and arguments-full_51740.json in client/.client_cache ? error: unexpected argument '--arguments-file' found

I can't launch it via client.sh either. scarb run client is supposed to work? What did I miss?

— Reply to this email directly, view it on GitHub https://github.com/keep-starknet-strange/raito/issues/245#issuecomment-2395117227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABOTB5XJFG2NKCH4QCSHGLZ2ALBXAVCNFSM6AAAAABPMBN4R6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJVGEYTOMRSG4 . You are receiving this because you were mentioned.Message ID: @.***>

maciejka commented 1 week ago

Update scarb to the latest version.

sob., 5 paź 2024, 19:23 użytkownik Maciek Kamiński @.***> napisał:

It should work directly with scarb cairo-run ...

sob., 5 paź 2024, 18:58 użytkownik Jean-Michel @.***> napisał:

Sorry, but what exactly is the error? I can't launch the client scarb cairo-run --verbose --no-build --package client --function test --arguments-file arguments-full_51740_1.json is not supposed to work directly, is it? with full_51740_1.json in client/tests/data and arguments-full_51740.json in client/.client_cache ? error: unexpected argument '--arguments-file' found

I can't launch it via client.sh either. scarb run client is supposed to work? What did I miss?

— Reply to this email directly, view it on GitHub https://github.com/keep-starknet-strange/raito/issues/245#issuecomment-2395117227, or unsubscribe https://github.com/notifications/unsubscribe-auth/AABOTB5XJFG2NKCH4QCSHGLZ2ALBXAVCNFSM6AAAAABPMBN4R6VHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGOJVGEYTOMRSG4 . You are receiving this because you were mentioned.Message ID: @.***>

Jeanmichel7 commented 1 week ago

oh already in 2.8.3! ok thanks got it

maciejka commented 6 days ago

When you comment out body of the test function the error still persists. Which means the cause of the problem is not in Cairo logic, we should look at the way arguments are loaded into the memory.

m-kus commented 6 days ago

Seems to be related https://github.com/lambdaclass/cairo-vm/issues/1728

Jeanmichel7 commented 6 days ago

Yes, the problem doesn't come from the Cairo logic, it's the weight of the argument that's too heavy in the cairo-run management. For full block 51740 we're at 641KB, while for full block 757738 we're only at 71KB.

maybe useful: There's a operating system's limitation, the integration test script doesn't work on block 51740: test tests/data/full_51740.json ... scarb/2.8.3/bin/scarb: Argument list too long This Operating System Limitation reveals that we've exceeded the 2MB argument limit, at least on my system $> getconf ARG_MAX //2097152 This problem can be solved by using a temporary file and use the --arguments-file option in scarb cairo-run

This raises the question of whether we're using the right way of doing things? Will it support the biggest blocks? (4Mo) And even several

I think that's beyond my skills, maybe we need to look at scarb-cairo-run. scarb/extensions/scarb-cairo-run/src/main.rs l86 &fs::read_to_string(path.clone()) We put all the arguments in memory at once, maybe we should stream them or use a temporary file? Not easy to test

maciejka commented 3 days ago

@Jeanmichel7 Argument list too long is fixed in #195.

I think that the problem is in the way the Cairo runner handles arguments, especially:

Somewhere in the above code, there must be an assumption that the argument length is less than 2^15.

Let me know if you want to continue to work on this issue.

Jeanmichel7 commented 2 days ago

@maciejka Yes, I'll try it. It could be because of the i16

/// Information about an array argument that has been added to the stack.
struct ArrayDataInfo {
    /// The offset of the pointer to the array data on the stack.
    ptr_offset : i16,
    /// The size of the array data in the stack.
    size : i16,
}

I'll try using a modified version of cairo to see