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

"Failed to parse payload: recursive reference of cells" on "cell.FromBOC" call #170

Closed
worker-droid opened this issue Feb 12, 2024 · 2 comments

Comments

@worker-droid
Copy link

worker-droid commented Feb 12, 2024

Hello. I get error Failed to parse payload: recursive reference of cells when deserializing stateinit from mytonwallet (ton connect).
Error occurs on the call cell.FromBOC.
I believe this is a bug, because I was able to successfully parse this stateinit using tongo library as shown in the example.

Tonutils version: v1.8.9

Example:

package main

import (
  "encoding/base64"
  "fmt"
  "log"

  "github.com/tonkeeper/tongo/tonconnect"
  "github.com/xssnick/tonutils-go/tvm/cell"
)

func main() {
  // address
  // UQBe7yULTjbWZszDK2d8LOePumy9ZtGzwQgrXXfqjR1yM2fy

  // stateInit from mytonwallet
  stateInit := "te6ccsECFgEAAwQAAAAABQAwAD0AQgDEAMsBAwE9AXYBewGAAa8BtAG/AcQByQHYAecCCAJ/AsYCATQCAQBRAAAAACmpoxf4lk0qBZddWkKNjjqmudjY6QDlccYne0gS9zCGDH3x2kABFP8A9KQT9LzyyAsDAgEgCQQE+PKDCNcYINMf0x/THwL4I7vyZO1E0NMf0x/T//QE0VFDuvKhUVG68qIF+QFUEGT5EPKj+AAkpMjLH1JAyx9SMMv/UhD0AMntVPgPAdMHIcAAn2xRkyDXSpbTB9QC+wDoMOAhwAHjACHAAuMAAcADkTDjDQOkyMsfEssfy/8IBwYFAAr0AMntVABsgQEI1xj6ANM/MFIkgQEI9Fnyp4IQZHN0cnB0gBjIywXLAlAFzxZQA/oCE8tqyx8Syz/Jc/sAAHCBAQjXGPoA0z/IVCBHgQEI9FHyp4IQbm90ZXB0gBjIywXLAlAGzxZQBPoCFMtqEssfyz/Jc/sAAgBu0gf6ANTUIvkABcjKBxXL/8nQd3SAGMjLBcsCIs8WUAX6AhTLaxLMzMlz+wDIQBSBAQj0UfKnAgIBSBMKAgEgDAsAWb0kK29qJoQICga5D6AhhHDUCAhHpJN9KZEM5pA+n/mDeBKAG3gQFImHFZ8xhAIBIA4NABG4yX7UTQ1wsfgCAVgSDwIBIBEQABmvHfaiaEAQa5DrhY/AABmtznaiaEAga5Drhf/AAD2ynftRNCBAUDXIfQEMALIygfL/8nQAYEBCPQKb6ExgAubQAdDTAyFxsJJfBOAi10nBIJJfBOAC0x8hghBwbHVnvSKCEGRzdHK9sJJfBeAD+kAwIPpEAcjKB8v/ydDtRNCBAUDXIfQEMFyBAQj0Cm+hMbOSXwfgBdM/yCWCEHBsdWe6kjgw4w0DghBkc3RyupJfBuMNFRQAilAEgQEI9Fkw7UTQgQFA1yDIAc8W9ADJ7VQBcrCOI4IQZHN0coMesXCAGFAFywVQA88WI/oCE8tqyx/LP8mAQPsAkl8D4gB4AfoA9AQw+CdvIjBQCqEhvvLgUIIQcGx1Z4MesXCAGFAEywUmzxZY+gIZ9ADLaRfLH1Jgyz8gyYBA+wAGdYbenA=="

  _, err := tonconnect.ParseStateInit(stateInit)
  if err != nil {
    log.Fatal(err) 
  }
    // ok
  fmt.Println("parsed 1")

  stateInitBytes, err := base64.StdEncoding.DecodeString(stateInit)
  if err != nil {
    log.Fatal(err)
  }

  _, err = cell.FromBOC(stateInitBytes)
  if err != nil {
    log.Fatal(err) // failed to parse payload: recursive reference of cells
  }
  fmt.Println("parsed 2")

}
@xssnick
Copy link
Owner

xssnick commented Feb 13, 2024

Hi, this is corrupted BoC with recursive reference (reference to itself and infinity depth), it must not work, so it is probably a bug in tongo.

For example this is TON Node output of trying to deserealize this boc:
Unexpected Status [Error : 0 : invalid bag-of-cells failed to deserialize cell #20 [Error : 0 : bag-of-cells error: reference #1 of cell #20 is to cell #20 with smaller index]]

@worker-droid
Copy link
Author

Hm, yes, it seems so.

Corrupted BoC comes from ton-core ts library

const contract = WalletContractV4.create({ workchain: 0, publicKey: Buffer.from('MUP3GpbKCQu64L4PIU0QprZxmSUygHcaYKuo2tZYA1c=', 'base64') });

let init = beginCell()
  .storeWritable(storeStateInit(contract!.init))
  .endCell();

let s = init
  .toBoc({ idx: true, crc32: true })
  .toString('base64')
  
console.log(s)

If idx: true is set to idx: false everything works fine.

Thank you, closing issue.

@worker-droid worker-droid closed this as not planned Won't fix, can't repro, duplicate, stale Feb 13, 2024
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

2 participants