Internal Compiler Error When Compiling Perp Contract: 'delta_balance' Variable Resolution Issue

Internal Compiler Error When Compiling Perp Contract: ‘delta_balance’ Variable Resolution Issue

Hello Fuel Community,

I’ve hit a roadblock in the development of my perpetual contract and am seeking insights or assistance from the community. During compilation, I encountered an internal compiler error related to the inability to resolve a variable named ‘delta_balance’. The error message is as follows:

____

error: Internal compiler error: Unable to resolve variable 'delta_balance'.
Please file an issue on the repository and include the code that triggered this error.
____

  Aborting due to 1 error.
Error: Failed to compile vault

This issue arises when I attempt to call the following function in my contract:

  #[payable, storage(read, write)]
    fn deposit_collateral(token: AssetId){
        reentrancy_guard();
        require_not_paused();
        if (token != SETTLEMENT_TOKEN) {
            require(is_allowed_collateral(token), Error::InvalidAsset);
            let config = storage.collateral_configurations.get(token).read();
            // V_GTDC: greater than deposit cap
            require(this_balance(token) <= config.deposit_cap, "V_GTDC");
        }
        let caller = msg_sender_address();
        modify_balance(caller, token, I64::from(msg_amount()));
    }

The code for the contract is currently in a private repository. If you’re able to assist and would like access to review the code more thoroughly, please reach out to me here or directly on Telegram at @defi_defiler.

Repository link: https://github.com/compolabs/spark-perps
Branch: multi-collateral

Additionally, here are the details of my current toolchain setup:

Default host: aarch64-apple-darwin
fuelup home: /Users/alexey/.fuelup

installed toolchains
--------------------
latest-aarch64-apple-darwin (default)
latest-2023-11-15-aarch64-apple-darwin
my-custom-toolchain
nightly-2024-01-24-aarch64-apple-darwin

active toolchain
----------------
latest-aarch64-apple-darwin (default)
  forc : 0.49.1
    - forc-client
      - forc-deploy : 0.49.1
      - forc-run : 0.49.1
    - forc-crypto : 0.49.1
    - forc-doc : 0.49.1
    - forc-explore : 0.28.1
    - forc-fmt : 0.49.1
    - forc-lsp : 0.49.1
    - forc-tx : 0.49.1
    - forc-wallet : 0.4.2
  fuel-core : 0.22.0
  fuel-core-keygen : 0.22.0

fuels versions
--------------
forc : 0.54.0
forc-wallet : 0.54.0

I appreciate any guidance or suggestions on how to resolve this issue or if anyone has faced something similar. Your expertise and advice would be invaluable in helping me move forward with my project.

Thank you in advance for your time and help.


This draft includes a concise description of the problem, the error message, a snippet of the code where the issue occurs, a call for assistance, and detailed information about your toolchain environment. It’s structured to provide the community with enough context to offer informed help or advice.

3 Likes

Thanks for providing that much info upfront, saves us all a lot of time.

This is definitely a compiler bug, but we’ll need a minimal example we can reproduce to fix this.

Does the delta_balance variable being mentioned here figure anywhere in your code?
The error message looks like an existing bug we have with match patterns but it’s hard to say more without looking at the code.

3 Likes

Hey @fuel, could a member of the compiler team be granted access to the repository? His GitHub handle is @ironcev.

2 Likes

I’ve found the issue.

It comes from this line elsewhere in your source:

let proxy_contract = abi(ProxyContract, PROXY_ADDRESS.into());
const contracts = proxy_contract.get_spark_contracts();

This const is nonsensical, it’s impossible to call a contract at compile time, hence weirdness.
The compiler will actually produce the right error if you modify the source a bit, but not in this exact case which is a bug.

Replace this const with a let, in the meantime we’ll try to figure out why the error doesn’t get produced here.

done
https://github.com/compolabs/spark-perps/invitations

1 Like

Thanks a lot <3
This is solution of the problem

1 Like

This topic was automatically closed 20 days after the last reply. New replies are no longer allowed.