Skip to content

Commit

Permalink
Fixed block header proof parse with pruned after merge part & minor f…
Browse files Browse the repository at this point in the history
…ixes
  • Loading branch information
xssnick committed Jan 12, 2024
1 parent 426b2cd commit c8412ad
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
20 changes: 13 additions & 7 deletions tlb/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,15 +142,15 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error {
var infoPart blockInfoPart
err := LoadFromCell(&infoPart, loader)
if err != nil {
return err
return fmt.Errorf("failed to load blockInfoPart: %w", err)
}
h.blockInfoPart = infoPart

if infoPart.Flags&1 == 1 {
var globalVer GlobalVersion
err = LoadFromCell(&globalVer, loader)
if err != nil {
return err
return fmt.Errorf("failed to load GlobalVersion: %w", err)
}
h.GenSoftware = &globalVer
}
Expand All @@ -163,29 +163,29 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error {
}
err = LoadFromCell(&masterRef, l)
if err != nil {
return err
return fmt.Errorf("failed to load ExtBlkRef: %w", err)
}
h.MasterRef = &masterRef
}

l, err := loader.LoadRef()
if err != nil {
return err
return fmt.Errorf("failed to load ref for after merge: %w", err)
}
prevRef, err := loadBlkPrevInfo(l, infoPart.AfterMerge)
if err != nil {
return err
return fmt.Errorf("failed to loadBlkPrevInfo for after merge: %w", err)
}
h.PrevRef = *prevRef

if infoPart.VertSeqnoIncr {
l, err := loader.LoadRef()
if err != nil {
return err
return fmt.Errorf("failed to load ref for vert incr: %w", err)
}
prevVertRef, err := loadBlkPrevInfo(l, false)
if err != nil {
return err
return fmt.Errorf("failed to loadBlkPrevInfo for prev vert ref: %w", err)
}
h.PrevVertRef = prevVertRef
}
Expand All @@ -195,6 +195,12 @@ func (h *BlockHeader) LoadFromCell(loader *cell.Slice) error {
func loadBlkPrevInfo(loader *cell.Slice, afterMerge bool) (*BlkPrevInfo, error) {
var res BlkPrevInfo

if loader.IsSpecial() {
// TODO: rewrite BlockHeader to pure tlb loader
// if it is a proof we skip load
return &res, nil
}

if !afterMerge {
var blkRef ExtBlkRef
err := LoadFromCell(&blkRef, loader)
Expand Down
4 changes: 4 additions & 0 deletions tlb/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,10 @@ func (s *Stack) parseValue(slice *cell.Slice) (any, error) {
}
}

if root.RefsNum() == 0 {
return nil
}

ref, err := root.LoadRef()
if err != nil {
return fmt.Errorf("failed to load tuple's %d ref, err: %w", i, err)
Expand Down
4 changes: 4 additions & 0 deletions tvm/cell/slice.go
Original file line number Diff line number Diff line change
Expand Up @@ -478,6 +478,10 @@ func (c *Slice) LoadBinarySnake() ([]byte, error) {
return data, nil
}

func (c *Slice) IsSpecial() bool {
return c.special
}

func (c *Slice) BitsLeft() uint {
return c.bitsSz - c.loadedSz
}
Expand Down

0 comments on commit c8412ad

Please sign in to comment.