0

I am trying to verify the endorsement operations of the endorsers in every blocks but I am unable to verify them. I took the details of the endorsement operation and reentered the details in TenderBakeEndorsement struct and tried to verify the signature against this preimage using the public key of the endorser but this did not work.

package client

import (
    "context"
    "fmt"

    "blockwatch.cc/tzgo/codec"
    "blockwatch.cc/tzgo/rpc"
    "blockwatch.cc/tzgo/tezos"
)
func EndorsementVerify() {

    ctx, cancel := context.WithCancel(context.Background())
    defer cancel()

    c, err := rpc.NewClient("https://ghostnet.smartpy.io", nil)

    if err != nil {
        fmt.Println(err)
        return
    }

    err = c.Init(ctx)

    if err != nil {
        fmt.Println(err)
        return
    }

    c.Listen()

    header, err := c.GetBlockHeader(ctx, rpc.BlockLevel(2866772))
    if err != nil {
        return  
    }

    block, err := c.GetBlockOperations(ctx, rpc.BlockLevel(2866772))
    if err != nil {
        return 
    }

    for i := 0; i < len(block); i++ {
        for j := 0; j < len(block[i]); j++ {
            for _, operation := range block[i][j].Contents {
                signature := block[i][j].Signature
                branch := block[i][j].Branch
                switch operation.Kind() {
                case tezos.OpTypeEndorsement:
                    tx := operation.(*rpc.Endorsement)

                    endorsement := codec.TenderbakeEndorsement{
                        Slot: int16(tx.Slot),
                        Level: int32(tx.Level),
                        Round: int32(tx.Round),
                        BlockPayloadHash: tx.PayloadHash,
                    }
                    
                    // also tried with branch = hash of previous block 
                    // when i looked at the block in the explorer, the branch field contained the hash of previous block of its predecessor 
                    // i.e hash of block - 2 

                    digested := codec.NewOp().WithContentsFront(&endorsement).WithChainId(header.ChainId).WithBranch(branch).Digest()

                    managerKey, err := c.GetManagerKey(ctx, tx.Metadata.Delegate, rpc.BlockLevel(2866772))
                    if err != nil {
                        fmt.Println(err)
                        return 
                    }


                    err = managerKey.Verify(digested[:], signature)
                    
                    if err != nil {
                        fmt.Println("error in verification")
                        fmt.Println(err)
                        return 
                    }

                    fmt.Println(tx)
                }
            }
        }
    }
}

I could not figure out any other way or if I have done something wrong with my implementation.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.