-
Notifications
You must be signed in to change notification settings - Fork 1.7k
/
config_digest.go
69 lines (63 loc) · 1.67 KB
/
config_digest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package mercury
import (
"encoding/binary"
"fmt"
"math/big"
"strings"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/smartcontractkit/libocr/offchainreporting2plus/types"
"github.com/smartcontractkit/wsrpc/credentials"
"github.com/smartcontractkit/chainlink/v2/core/gethwrappers/llo-feeds/generated/exposed_verifier"
)
func makeConfigDigestArgs() abi.Arguments {
abi, err := abi.JSON(strings.NewReader(exposed_verifier.ExposedVerifierABI))
if err != nil {
// assertion
panic(fmt.Sprintf("could not parse aggregator ABI: %s", err.Error()))
}
return abi.Methods["exposedConfigDigestFromConfigData"].Inputs
}
var configDigestArgs = makeConfigDigestArgs()
func configDigest(
feedID common.Hash,
chainID *big.Int,
contractAddress common.Address,
configCount uint64,
oracles []common.Address,
transmitters []credentials.StaticSizedPublicKey,
f uint8,
onchainConfig []byte,
offchainConfigVersion uint64,
offchainConfig []byte,
) types.ConfigDigest {
msg, err := configDigestArgs.Pack(
feedID,
chainID,
contractAddress,
configCount,
oracles,
transmitters,
f,
onchainConfig,
offchainConfigVersion,
offchainConfig,
)
if err != nil {
// assertion
panic(err)
}
rawHash := crypto.Keccak256(msg)
configDigest := types.ConfigDigest{}
if n := copy(configDigest[:], rawHash); n != len(configDigest) {
// assertion
panic("copy too little data")
}
binary.BigEndian.PutUint16(configDigest[:2], uint16(types.ConfigDigestPrefixMercuryV02))
if !(configDigest[0] == 0 && configDigest[1] == 6) {
// assertion
panic("unexpected mismatch")
}
return configDigest
}