paritytech / polkadot-sdk

The Parity Polkadot Blockchain SDK
https://polkadot.network/
1.8k stars 652 forks source link

revive issue min repro #5579

Closed pgherveou closed 3 weeks ago

pgherveou commented 3 weeks ago
RUST_LOG=runtime=DEBUG cargo test --features riscv tests::run_tests::deploy_and_call_other_contract -- --exact --nocapture

fails with

running 1 test
2024-09-03T16:23:33.271195Z DEBUG runtime::revive: write_fixed_sandbox_output: buf: [47, 50, 31, 177, 101, 48, 150, 144, 98, 124, 103, 240, 27, 20, 192, 151, 238, 53, 133, 90]    
2024-09-03T16:23:33.271234Z DEBUG runtime::revive: 
===
<Call flags: 0, callee_ptr: 4294901664, value_ptr: 4294901608, deposit_ptr: 4294967295, ref_time_limit: 0, proof_size_limit: 0, input_data_ptr: 4294901657, input_data_len: 7, output_ptr: 4294967295, output_len_ptr: 4294901740>    
2024-09-03T16:23:33.271464Z DEBUG runtime::revive: 
===
<Call flags: 0, callee_ptr: 4294901664, value_ptr: 4294901608, deposit_ptr: 4294967295, ref_time_limit: 1, proof_size_limit: 0, input_data_ptr: 4294901649, input_data_len: 8, output_ptr: 4294967295, output_len_ptr: 4294901740>    
2024-09-03T16:23:33.271631Z DEBUG runtime::revive: 
===
<Call flags: 0, callee_ptr: 4294901664, value_ptr: 4294901608, deposit_ptr: 4294967295, ref_time_limit: 0, proof_size_limit: 1, input_data_ptr: 4294901649, input_data_len: 8, output_ptr: 4294967295, output_len_ptr: 4294901740>    
2024-09-03T16:23:33.271827Z DEBUG runtime::revive: 
===
<Call flags: 0, callee_ptr: 4294901664, value_ptr: 4294901608, deposit_ptr: 1, ref_time_limit: 0, proof_size_limit: 0, input_data_ptr: 4294901649, input_data_len: 8, output_ptr: 4294901684, output_len_ptr: 4294901740>    
thread 'tests::run_tests::deploy_and_call_other_contract' panicked at substrate/frame/revive/src/tests.rs:1087:13:
Expected Ok(_). Got Err(
    DispatchErrorWithPostInfo {
        post_info: PostDispatchInfo {
            actual_weight: Some(
                Weight {
                    ref_time: 11974439090,
                    proof_size: 78489,
                },
            ),
            pays_fee: Pays::Yes,
        },
        error: Module(
            ModuleError {
                index: 4,
                error: [
                    10,
                    0,
                    0,
                    0,
                ],
                message: Some(
                    "OutOfBounds",
                ),
            },
        ),
    },
)
athei commented 3 weeks ago

My best guess is that the packed struct in the implementation of call and instantiate trips PolkaVM up. It might generate some unaligned loads/stores which instead of panicing will just do whatever.

paritytech-cicd-pr commented 3 weeks ago

The CI pipeline was cancelled due to failure one of the required jobs. Job name: test-linux-stable 2/3 Logs: https://gitlab.parity.io/parity/mirrors/polkadot-sdk/-/jobs/7252202

pgherveou commented 3 weeks ago

My best guess is that the packed struct in the implementation of call and instantiate trips PolkaVM up. It might generate some unaligned loads/stores which instead of panicing will just do whatever.

Tested with a custom encoding (poor man SCALE solution) and I got the same bug

pgherveou commented 3 weeks ago

Looks like the test pass if I disable LTO, so maybe something with polkavm-linker

athei commented 3 weeks ago

Yes it seems to be the polkavm-linker: https://github.com/xermicus/pvm-linker-bug-repro

Jan will debug.