runtimeverification / kasmer-multiversx

Wasm semantics for the Elrond/MultiversX blockchain network
BSD 3-Clause "New" or "Revised" License
0 stars 0 forks source link

Multi-contract support in `kasmerx` #128

Closed bbyalcinkaya closed 1 month ago

bbyalcinkaya commented 2 months ago

Some MultiversX projects produce multiple build outputs, resulting in more than one *.wasm files in the ./output directory. For example, the Multisig contract has three outputs: multisig, multisig-full, and multisig-view.

Relevant links:

Currently, kasmerx takes the root directory path of the contract and, after compiling, fetches the first *.wasm file found in the <path_to_contract>/output directory. This approach does not handle projects with multiple output contracts.

We should allow users to specify which contract output to use. My initial suggestion is to extend the kasmerx.json file structure as follows:

{
  "contract_paths": [
    // single contract -- should fail if more than one *.wasm file exist
    "mx-sdk-rs/contracts/examples/adder",

    // multi-contract
    {
      "dir": "mx-sdk-rs/contracts/examples/multisig",
      "target": "multisig-full" // fetch '...multisig/output/multisig-full.wasm'
    }
  ]
}
virgil-serbanuta commented 1 month ago

We confirmed that there is no default target that we can use, and we need to include it in the configuration file.

tothtamas28 commented 1 month ago

Let's point to the output file directly for now.

Once we know how the compiler comes up with the output file path, we can replicate that logic and then maybe pointing to dir (and processing configuration files there) will be enough.

tothtamas28 commented 1 month ago

Based on #150, it looks like we still need to have the dir. So maybe

{
  "contract_path": "../../../deps/mx-sdk-rs/contracts/examples/multisig",
  "targets": [
    {
      "target": "multisig-full",
      "output": "output/multisig-full.wasm"
    }
  ]
}

contract_path is resolved relative to the parent of kasmerx.json.

output is resolved relative to (the resolved) contract path.

@bbyalcinkaya, what do you think?

Edit: or if we're only interested in a single contract per test,

{
  "contract_path": "../../../deps/mx-sdk-rs/contracts/examples/multisig",
  "target": "multisig-full",
  "output": "output/multisig-full.wasm"
}
bbyalcinkaya commented 1 month ago

I have seen test scenarios that involve more than one contract, so I believe the format should support multiple contracts per test. Additionally, the contracts do not need to be under the same contract_path.

I also confirmed with the MultiversX team that output is a function of contract_path and target:

output = contract_path / 'output' / f'{target}.wasm'

Here is an example configuration:

{
  "contracts": [
    {
      "path": "../../../deps/mx-sdk-rs/contracts/examples/multisig",
      "target": "multisig-full"
    },
    {
      "path": "../../../deps/mx-sdk-rs/contracts/examples/adder",
      "target": "adder"
    }
  ]
}