|
8 | 8 | "time"
|
9 | 9 |
|
10 | 10 | ethcommon "github.com/ethereum/go-ethereum/common"
|
| 11 | + "github.com/ethereum/go-ethereum/consensus/clique" |
11 | 12 | "github.com/ethereum/go-ethereum/core/types"
|
12 |
| - "github.com/maticnetwork/polygon-cli/util" |
| 13 | + ethcrypto "github.com/ethereum/go-ethereum/crypto" |
13 | 14 | "github.com/rs/zerolog/log"
|
14 | 15 | "github.com/spf13/cobra"
|
15 | 16 |
|
@@ -120,7 +121,7 @@ func writeBlock(folderName string, block *types.Block, isCanonical bool) error {
|
120 | 121 | }
|
121 | 122 | fields["transactions"] = block.Transactions()
|
122 | 123 | // TODO in the future if this is used in other chains or with different types of consensus this would need to be revised
|
123 |
| - signer, err := util.Ecrecover(block) |
| 124 | + signer, err := ecrecover(block) |
124 | 125 | if err != nil {
|
125 | 126 | log.Error().Err(err).Msg("Unable to recover signature")
|
126 | 127 | return err
|
@@ -155,3 +156,19 @@ func getBlockByHash(ctx context.Context, bh ethcommon.Hash, client *ethclient.Cl
|
155 | 156 | log.Error().Err(errRetryLimitExceeded).Str("blockhash", bh.String()).Int("retryLimit", retryLimit).Msg("Unable to fetch block after retrying")
|
156 | 157 | return nil, errRetryLimitExceeded
|
157 | 158 | }
|
| 159 | + |
| 160 | +func ecrecover(block *types.Block) ([]byte, error) { |
| 161 | + header := block.Header() |
| 162 | + sigStart := len(header.Extra) - ethcrypto.SignatureLength |
| 163 | + if sigStart < 0 || sigStart > len(header.Extra) { |
| 164 | + return nil, fmt.Errorf("unable to recover signature") |
| 165 | + } |
| 166 | + signature := header.Extra[sigStart:] |
| 167 | + pubkey, err := ethcrypto.Ecrecover(clique.SealHash(header).Bytes(), signature) |
| 168 | + if err != nil { |
| 169 | + return nil, err |
| 170 | + } |
| 171 | + signer := ethcrypto.Keccak256(pubkey[1:])[12:] |
| 172 | + |
| 173 | + return signer, nil |
| 174 | +} |
0 commit comments