/
abi_consts.go
155 lines (144 loc) · 3.3 KB
/
abi_consts.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package types
import (
"log"
"strings"
wrapper "github.com/celestiaorg/quantum-gravity-bridge/v2/wrappers/QuantumGravityBridge.sol"
"github.com/ethereum/go-ethereum/accounts/abi"
ethcmn "github.com/ethereum/go-ethereum/common"
)
const (
// InternalQGBabiJSON is the json encoded abi for private functions in the
// qgb contract. This is needed to encode data that is signed over in a way
// that the contracts can easily verify.
InternalQGBabiJSON = `[
{
"inputs": [
{
"components": [
{
"internalType": "address",
"name": "addr",
"type": "address"
},
{
"internalType": "uint256",
"name": "power",
"type": "uint256"
}
],
"internalType": "struct Validator[]",
"name": "_validators",
"type": "tuple[]"
}
],
"name": "computeValidatorSetHash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_separator",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "_nonce",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "_dataRootTupleRoot",
"type": "bytes32"
}
],
"name": "domainSeparateDataRootTupleRoot",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
},
{
"inputs": [
{
"internalType": "bytes32",
"name": "_separator",
"type": "bytes32"
},
{
"internalType": "uint256",
"name": "_nonce",
"type": "uint256"
},
{
"internalType": "uint256",
"name": "_powerThreshold",
"type": "uint256"
},
{
"internalType": "bytes32",
"name": "_validatorSetHash",
"type": "bytes32"
}
],
"name": "domainSeparateValidatorSetHash",
"outputs": [
{
"internalType": "bytes32",
"name": "",
"type": "bytes32"
}
],
"stateMutability": "pure",
"type": "function"
}
]`
// Domain separator constants copied directly from the contracts.
ValidatorSetDomainSeparator = "0x636865636b706f696e7400000000000000000000000000000000000000000000"
DataCommitmentDomainSeparator = "0x7472616e73616374696f6e426174636800000000000000000000000000000000"
)
var (
ExternalQGBabi abi.ABI
InternalQGBabi abi.ABI
BridgeValidatorAbi abi.Arguments
VsDomainSeparator ethcmn.Hash
DcDomainSeparator ethcmn.Hash
)
func init() {
contractAbi, err := abi.JSON(strings.NewReader(wrapper.WrappersMetaData.ABI))
if err != nil {
log.Fatalln("bad ABI constant", err)
}
ExternalQGBabi = contractAbi
internalABI, err := abi.JSON(strings.NewReader(InternalQGBabiJSON))
if err != nil {
log.Fatalln("bad internal ABI constant", err)
}
InternalQGBabi = internalABI
solValidatorType, err := abi.NewType("tuple", "validator", []abi.ArgumentMarshaling{
{Name: "Addr", Type: "address"},
{Name: "Power", Type: "uint256"},
})
if err != nil {
panic(err)
}
BridgeValidatorAbi = abi.Arguments{
{Type: solValidatorType, Name: "Validator"},
}
// create the domain separator for valset hashes
VsDomainSeparator = ethcmn.HexToHash(ValidatorSetDomainSeparator)
DcDomainSeparator = ethcmn.HexToHash(DataCommitmentDomainSeparator)
}