Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug] CONSTRAINT_NOT_SATISFIED when wrapping a move public function that works when run directly #15657

Open
KodamaXYZ opened this issue Dec 27, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@KodamaXYZ
Copy link

KodamaXYZ commented Dec 27, 2024

🐛 Bug

Everything tested on Mainnet

I am trying to integrate Thala's contract which I have done thousands of time with other contracts.
This time I am experiencing a very weird behavior

When trying to execute the wrapped code I get:
vm_status: 'CONSTRAINT_NOT_SATISFIED',

Running directly with the contract works.

To reproduce

  1. create a contract that uses thala's entry function:
module Test::Test {
    use std::signer;
    use aptos_framework::primary_fungible_store;
    use aptos_framework::fungible_asset::FungibleAsset;
    use aptos_framework::fungible_asset;
    use aptos_framework::object::Object;
    use std::option;
    use aptos_framework::fungible_asset::Metadata;
    use aptos_framework::coin;

    use ThalaSwapV2::pool as ThalaV2Pool;
    use ThalaSwapV2::coin_wrapper as ThalaV2PoolWrapper;

    public entry fun swap_thala_v2_weighted<X>(sender: &signer, pool: Object<ThalaV2Pool::Pool>, metadata: Object<Metadata>, u: u64, metadata2: Object<Metadata>, u2: u64) {
        ThalaV2PoolWrapper::swap_exact_in_weighted<X>(sender, pool, metadata, u, metadata2, u2);
    }
}

Interface:

module ThalaSwapV2::pool {
    use aptos_framework::fungible_asset::FungibleAsset;
    use aptos_framework::object::Object;
    use aptos_framework::fungible_asset::Metadata;

    struct Pool {}

    public fun swap_exact_in_stable(sender: &signer, pool: Object<Pool>, x_in: FungibleAsset, md: Object<Metadata>): FungibleAsset {
        abort 0
    }
    
    public fun swap_exact_in_weighted(sender: &signer, pool: Object<Pool>, x_in: FungibleAsset, md: Object<Metadata>): FungibleAsset {
        abort 0
    }
}

module ThalaSwapV2::coin_wrapper {
    use aptos_framework::fungible_asset::FungibleAsset;
    use aptos_framework::object::Object;
    use aptos_framework::fungible_asset::Metadata;
    use ThalaSwapV2::pool::Pool;

    public entry fun swap_exact_in_stable<X>(sender: &signer, pool: Object<Pool>, md: Object<Metadata>, u: u64, md2: Object<Metadata>, u2: u64) {
        abort 0
    }
    
    public entry fun swap_exact_in_weighted<X>(sender: &signer, pool: Object<Pool>, md: Object<Metadata>, u: u64, md2: Object<Metadata>, u2: u64) {
        abort 0
    }
}

address:
ThalaSwapV2 = "0x007730cd28ee1cdc9e999336cbc430f99e7c44397c0aa77516f6f23a78559bb5"

Attached two results, one directly with the contract, the second is using the wrapped contract.

Please notice how simple the wrapper is. its just forwarding the arguments to another function.

public entry fun swap_thala_v2_weighted<X>(sender: &signer, pool: Object<ThalaV2Pool::Pool>, metadata: Object<Metadata>, u: u64, metadata2: Object<Metadata>, u2: u64) {
        ThalaV2PoolWrapper::swap_exact_in_weighted<X>(sender, pool, metadata, u, metadata2, u2);
    }

Swap Directly with Thala

image

Swap Wrapped

image

arguments for ease of debugging:

T0: 0x1::aptos_coin::AptosCoin
pool: 0x99d34f16193e251af236d5a5c3114fa54e22ca512280317eda2f8faf1514c395
MD1: 0xa
u64: 1000
MD2: 0x357b0b74bc833e95a115ad22604854d6b0fca151cecd94111770e5d6ffc9dc2b
u64: 0

Expected result would be the same outcome with both flows.

Update (v2 compile not helping):

I've tried deploying to Mainnet with the following flags: --move-2 --compiler v2
and still getting same result in runtime.

@KodamaXYZ KodamaXYZ added the bug Something isn't working label Dec 27, 2024
@wrwg
Copy link
Contributor

wrwg commented Dec 28, 2024

This error most likely indicates a runtime verification error where an internal consistency check in the VM for the given program failed. Are you running this on testnet or mainnet? If its testnet, are you able to check whether it succeeds on mainnet? Also have you compiled this code with --move-2 or --compiler v2? Thank you

@KodamaXYZ
Copy link
Author

KodamaXYZ commented Dec 28, 2024

This error most likely indicates a runtime verification error where an internal consistency check in the VM for the given program failed. Are you running this on testnet or mainnet? If its testnet, are you able to check whether it succeeds on mainnet? Also have you compiled this code with --move-2 or --compiler v2? Thank you

This is running on mainnet with move v1.
Contract is deploying successfully.

Interaction is failing.

./aptos --version
aptos 5.1.0

Update:
I've tried deploying to Mainnet with the following flags: --move-2 --compiler v2
and still getting same result in runtime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants
@wrwg @KodamaXYZ and others