So Hi, I have been coming back to SC programming and I tried to create this smart contract that crashes the remix VM. I do not know what error is causing it and curious to understand it from a low level.

// SPDX-License-Identifier: MIT
pragma solidity 0.8.9;
contract ComeBack {
    uint256 public FavoriteNb;
    uint256 nb = 0;
    function store(uint256 _nb, uint256 _FavoriteNb) public payable {
        _nb = nb;
        while (_nb >= 0) {
            FavoriteNb = _FavoriteNb;

1 Answer 1


Your function store is wrong.

You are trying to set your storage value to your argument instead of the reverse.

It should be:

nb = _nb;
while(nb >= 0){
   FavoriteNb = _FavoriteNb;

And you are increasing nb. That makes your while loop an infinite loop since you check that nb >= 0. Maybe you should decrement it?

And why are you setting FavoriteNb in the loop since the value never changes.

All of your function is weird. What are you trying to do?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.