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

Wrong computed message hash for ext message #334

Open
eran-utila opened this issue Feb 5, 2025 · 0 comments
Open

Wrong computed message hash for ext message #334

eran-utila opened this issue Feb 5, 2025 · 0 comments

Comments

@eran-utila
Copy link

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)
}
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

No branches or pull requests

1 participant