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

Fix deserialization of negative transaction exit codes #115

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

daring2
Copy link

@daring2 daring2 commented Mar 7, 2025

Fix deserialization of negative transaction exit codes.

At the moment CellSlice#loadUint method is used for exitCode deserialization in ComputePhaseVMDetails class. But exit codes can be negative (for examples, -14), so CellSlice#loadInt should be used instead as I understand.

Steps to reproduce the problem:

  1. Load transaction with negative exit code -14 (for example, 35f6fe4b962fa3412b477e82f489da1fdf3493c79c336da2dac9b44eaefed384).
  2. Check exit code of the loaded transaction using ComputePhaseVMDetails#getExitCode method.

Expected result: exit code equals -14.
Actual result: exit code equals 4294967282.

Unit test example:

  @Test
  public void testTonlibTransactionExitCode() {
    Tonlib tonlib = Tonlib.builder()
            .pathToTonlibSharedLib(tonlibPath)
            .ignoreCache(false)
            .testnet(true)
            .build();
    RawTransactions transactions = tonlib.getRawTransactions(
            "kQCAePo20KE2fCceVmDhb09Xylcv4vvfSJCXNe5XACBGcbx0",
            null, null, 10
    );
    String failedTxHash = "35f6fe4b962fa3412b477e82f489da1fdf3493c79c336da2dac9b44eaefed384";
    for (RawTransaction rawTx : transactions.getTransactions()) {
      String txHash = base64ToHexString(rawTx.getTransaction_id().getHash());
      if (!txHash.equals(failedTxHash))
        continue;
      Cell dataCell = CellBuilder.beginCell().fromBocBase64(rawTx.getData()).endCell();
      Transaction tansaction = Transaction.deserialize(CellSlice.beginParse(dataCell));
      TransactionDescriptionOrdinary txDesc = (TransactionDescriptionOrdinary) tansaction.getDescription();
      long exitCode = ((ComputePhaseVM) txDesc.getComputePhase()).getDetails().getExitCode();
      assertThat(exitCode).isEqualTo(-14);
      break;
    }
  }

@neodix42
Copy link
Owner

neodix42 commented Mar 7, 2025

Thanks for reporting, I see the problem, you are right. This and other bugs will be fixed with the next release, hopefully next week.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants