Skip to content

Commit 2279293

Browse files
committed
revert fork stuff
1 parent b29a1ef commit 2279293

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

cmd/fork/fork.go

+19-2
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@ import (
88
"time"
99

1010
ethcommon "github.com/ethereum/go-ethereum/common"
11+
"github.com/ethereum/go-ethereum/consensus/clique"
1112
"github.com/ethereum/go-ethereum/core/types"
12-
"github.com/maticnetwork/polygon-cli/util"
13+
ethcrypto "github.com/ethereum/go-ethereum/crypto"
1314
"github.com/rs/zerolog/log"
1415
"github.com/spf13/cobra"
1516

@@ -120,7 +121,7 @@ func writeBlock(folderName string, block *types.Block, isCanonical bool) error {
120121
}
121122
fields["transactions"] = block.Transactions()
122123
// 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)
124125
if err != nil {
125126
log.Error().Err(err).Msg("Unable to recover signature")
126127
return err
@@ -155,3 +156,19 @@ func getBlockByHash(ctx context.Context, bh ethcommon.Hash, client *ethclient.Cl
155156
log.Error().Err(errRetryLimitExceeded).Str("blockhash", bh.String()).Int("retryLimit", retryLimit).Msg("Unable to fetch block after retrying")
156157
return nil, errRetryLimitExceeded
157158
}
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

Comments
 (0)