Stack overflow in cross-contract calls

I keep running into stack overflow of variables during cross-contract calls. It’s not obvious at compile-time, but errors out – very subtly – at runtime. Variable values get changed (overflowed) during cross-contract calls and this is particularly annoying.

I’ve been able to, for the most part, solve this issue by wrapping the cross-contract call within curly braces (effectively, giving it it’s own “stack” similar to Solidity) and it goes away.

Ran into this issue again, but no matter how many times I add curly braces. I’ve been clever with this as well, making sure to signal to the compiler not to optimize it away, but alas.

Is there any compiler construct I can use to signal to the compiler not to remove these curly braces/stacks?

Unfortunately, this is not an issue that can be reproduced easily unless you have access to my codebase. All I can say is that this is a very large codebase, the function is itself quite large, there are a lot of cross-contract calls made within this function.

PS: I’ve made sure to cache values inside variables before passing them as parameters (this was one of the reasons I’ve observed that’s caused these issues in the past), but that hasn’t helped in this case.

Using log statements, I can demonstrate that there is indeed a stack overflow:

// before: variable value: 6000000000000000000000000000000000 (u256)
// after:    variable value: 43576667781058576478110942251566715893472315779287205560898110781599471274368 (u256)

this not only happens to u256 values, but other types as well (like AssetId)

1 Like

cc @danielbate @IGI-111 @calldelegation

Hey @theAusicist, can you please share the codebase to look at and the steps to reproduce it? Also, the output of the command fuelup show from your terminal would be much helpful

1 Like