Skip to content

Wrong computed message hash for ext message #334

@eran-utila

Description

@eran-utila

Hi,
When I publish transactions to the chain, I calculate the message hash, and use it later to track the transaction.
Unfortunately, since yesterday, I have experienced multiple occurrences where the in memory computed message hash for the boc, did not match the one on the chain.
I have not made any related changes to my code recently, and I also have not upgraded my tongo version (I am using v1.9.0).
It kept happening even after upgrading the tongo version to v1.14.4.
Is it possible that the hash computation algorithm in the chain has changed and the the algorithm in tongo is no longer relevant?

here is a code snippet which fetches the message from the chain, and computes the hash, and we can see we get a different result:

func Test_FailingTx(t *testing.T) {
	tonKeeprClient, err := tap.New()
	require.NoError(t, err)

	failingTx := "7cd5ce546570218f31e0ea233a245cdd693fdf38bdbdbb620a8284eefe427891"
	tx, err := tonKeeprClient.GetBlockchainTransactionByMessageHash(
		context.Background(),
		tap.GetBlockchainTransactionByMessageHashParams{
			MsgID: failingTx,
		},
	)
	require.NoError(t, err)

	inMsg := tx.InMsg
	fmt.Println(inMsg)

	msgBody := inMsg.Value.RawBody
	hash := inMsg.Value.Hash

	fmt.Printf("real hash %s\n", hash)

	bodyBocs, err := boc.DeserializeBocHex(msgBody.Value)
	require.NoError(t, err)
	require.Len(t, bodyBocs, 1)

	accountID := ton.MustParseAccountID(tx.GetAccount().Address)
	require.NoError(t, err)

	require.False(t, inMsg.Value.Init.IsSet())

	extMsg, err := ton.CreateExternalMessage(
		accountID,
		bodyBocs[0],
		nil,
		tlb.VarUInteger16{},
	)
	require.NoError(t, err)

	extMsgCell := boc.NewCell()
	err = tlb.Marshal(extMsgCell, extMsg)
	require.NoError(t, err)

	computedHash, err := extMsgCell.HashString()
	require.NoError(t, err)

	require.NoError(t, err)
	fmt.Printf("computed hash %s\n", computedHash)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions