-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtypes.go
219 lines (183 loc) · 7.22 KB
/
types.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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
package common
import (
"errors"
"fmt"
"math/big"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto/kzg4844"
"github.com/ethereum/go-ethereum/params"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ten-protocol/go-ten/contracts/generated/MessageBus"
"github.com/ten-protocol/go-ten/lib/gethfork/rpc"
)
type (
StateRoot = common.Hash
TxHash = common.Hash
// EncryptedSubscriptionLogs - Alias for the event subscription updates going
// out of the enclave.
EncryptedSubscriptionLogs = map[rpc.ID][]byte
// StreamL2UpdatesResponse - the struct encoded for each response message
// when streaming batches out of the enclave.
// The properties inside need to be encrypted according to the privacy rules.
StreamL2UpdatesResponse struct {
Batch *ExtBatch
Logs EncryptedSubscriptionLogs
}
// MainNet aliases
L1Address = common.Address
L1BlockHash = common.Hash
L1Transaction = types.Transaction
L1Receipt = types.Receipt
L1Receipts = types.Receipts
// Local Obscuro aliases
L2BatchHash = common.Hash
L2RollupHash = common.Hash
L2TxHash = common.Hash
L2Tx = types.Transaction
L2Transactions = types.Transactions
L2Address = common.Address
L2Receipt = types.Receipt
L2Receipts = types.Receipts
SerializedCrossChainTree = []byte
L2PricedTransaction struct {
Tx *L2Tx
// todo - add sender
PublishingCost *big.Int
FromSelf bool
SystemDeployer bool // Free contract construction
}
L2PricedTransactions []*L2PricedTransaction
CrossChainMessage = MessageBus.StructsCrossChainMessage
CrossChainMessages = []CrossChainMessage
ValueTransferEvent struct {
Sender common.Address
Receiver common.Address
Amount *big.Int
Sequence uint64
}
ValueTransferEvents = []ValueTransferEvent
EncryptedRequest []byte
EncryptedTx []byte // A single transaction, encoded as a JSON list of transaction binary hexes and encrypted using the enclave's public key
EncryptedTransactions []byte // A blob of encrypted transactions, as they're stored in the rollup, with the nonce prepended.
EncryptedParamsLogSubscription []byte
Nonce = uint64
EncodedRollup []byte
EncodedBatchMsg []byte
EncodedBatchRequest []byte
EncodedBlobHashes []byte
EnclaveID = common.Address
// RollupSignature represents a signature over a rollup's composite hash
RollupSignature = []byte
// CreateRollupResult contains all data returned from creating a rollup
CreateRollupResult struct {
Signature RollupSignature // The signature over the composite hash
Blobs []*kzg4844.Blob // The blobs containing the rollup data
}
)
// FailedDecryptErr - when the TEN enclave fails to decrypt an RPC request
var FailedDecryptErr = errors.New("failed to decrypt RPC payload. please use the correct enclave key")
// EncryptedRPCRequest - an encrypted request with extra plaintext metadata
type EncryptedRPCRequest struct {
Req EncryptedRequest
IsTx bool // we can make this an enum if we need to provide more info to the TEN host
}
func (txs L2PricedTransactions) ToTransactions() types.Transactions {
ret := make(types.Transactions, 0)
for _, tx := range txs {
ret = append(ret, tx.Tx)
}
return ret
}
const (
L1GenesisHeight = uint64(0)
L2GenesisHeight = uint64(0)
L2GenesisSeqNo = uint64(1)
L2SysContractGenesisSeqNo = uint64(2)
SyntheticTxGasLimit = params.MaxGasLimit
)
var GethGenesisParentHash = common.Hash{}
// SystemError is the interface for the internal errors generated in the Enclave and consumed by the Host
type SystemError interface {
Error() string
}
// AttestationReport represents a signed attestation report from a TEE and some metadata about the source of it to verify it
type AttestationReport struct {
Report []byte // the signed bytes of the report which includes some encrypted identifying data
PubKey []byte // a public key that can be used to send encrypted data back to the TEE securely (should only be used once Report has been verified)
EnclaveID common.Address // address identifying the owner of the TEE which signed this report, can also be verified from the encrypted Report data
HostAddress string // the IP address on which the host can be contacted by other Obscuro hosts for peer-to-peer communication
}
type (
EncryptedSharedEnclaveSecret []byte
EncodedAttestationReport []byte
)
// BlockAndReceipts - a structure that contains a fuller view of a block. It allows iterating over the
// successful transactions, using the receipts. The receipts are bundled in the host node and thus verification
// is performed over their correctness.
// To work properly, all of the receipts are required, due to rlp encoding pruning some of the information.
// The receipts must also be in the correct order.
type BlockAndReceipts struct {
BlockHeader *types.Header
TxsWithReceipts []*TxAndReceiptAndBlobs
successfulTransactions *types.Transactions
}
// ParseBlockAndReceipts - will create a container struct that has preprocessed the receipts
// and verified if they indeed match the receipt root hash in the block.
func ParseBlockAndReceipts(block *types.Header, receiptsAndBlobs []*TxAndReceiptAndBlobs) (*BlockAndReceipts, error) {
br := BlockAndReceipts{
BlockHeader: block,
TxsWithReceipts: receiptsAndBlobs,
}
return &br, nil
}
func (br *BlockAndReceipts) Receipts() L1Receipts {
rec := make(L1Receipts, 0)
for _, txsWithReceipt := range br.TxsWithReceipts {
rec = append(rec, txsWithReceipt.Receipt)
}
return rec
}
// RelevantTransactions - returns slice containing only the transactions that have receipts with successful status.
func (br *BlockAndReceipts) RelevantTransactions() *types.Transactions {
if br.successfulTransactions != nil {
return br.successfulTransactions
}
st := make(types.Transactions, 0)
for _, tx := range br.TxsWithReceipts {
if tx.Receipt.Status == types.ReceiptStatusSuccessful {
st = append(st, tx.Tx)
}
}
br.successfulTransactions = &st
return br.successfulTransactions
}
// ChainFork - represents the result of walking the chain when processing a fork
type ChainFork struct {
NewCanonical *types.Header
OldCanonical *types.Header
CommonAncestor *types.Header
CanonicalPath []L1BlockHash
NonCanonicalPath []L1BlockHash
}
func (cf *ChainFork) IsFork() bool {
return len(cf.NonCanonicalPath) > 0
}
func (cf *ChainFork) String() string {
if cf == nil {
return ""
}
return fmt.Sprintf("ChainFork{NewCanonical: %s, OldCanonical: %s, CommonAncestor: %s, CanonicalPath: %s, NonCanonicalPath: %s}",
cf.NewCanonical.Hash(), cf.OldCanonical.Hash(), cf.CommonAncestor.Hash(), cf.CanonicalPath, cf.NonCanonicalPath)
}
func MaskedSender(address L2Address) L2Address {
return common.BigToAddress(big.NewInt(0).Sub(address.Big(), big.NewInt(1)))
}
type SystemContractAddresses map[string]*gethcommon.Address
func (s *SystemContractAddresses) ToString() string {
var str string
for name, addr := range *s {
str += fmt.Sprintf("%s: %s; ", name, addr.Hex())
}
return str
}