Race condition in FunC

Hi everyone,

I am new to TON Blockchain and FunC smart contract language.

I am trying to manifest a race condition using FunC as a part of my project. Below is the code →

#include "imports/stdlib.fc";


(int) load_data() inline {
    var ds = get_data().begin_parse();
    return (ds~load_uint(64));
}

() save_data(int counter) impure inline {
    set_data(begin_cell()
    .store_uint(counter, 64)
    .end_cell());
}

() recv_internal(int msg_value, cell in_msg, slice in_slice) impure {
    if(in_slice.slice_empty?()) {
        return ();
    } else {
        var counter = load_data();

        int i = 0;
        while(i < 5) {
            i += 1;
        }
        ;; send_raw_message(begin_cell().end_cell(), 64);

        counter += 1;
        save_data(counter);
    }
}

(int) get_counter() method_id {
    return load_data();
}

When writing tests, I am sending two internal messages. The final value of counter should be 1 after execution of both messages due to the race but it is actually 0. Can anyone tell me what I am doing wrong and is race condition even possible in TON?

I have even tried to loop for more than 100000 times.

You can consider asking the question here :point_down::point_down::point_down:

1 Like