-
Notifications
You must be signed in to change notification settings - Fork 40
/
Copy pathtypes.go
190 lines (162 loc) · 6.94 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
package common
import (
"fmt"
"math/big"
"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
L1Block = types.Block
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
PublishingCost *big.Int
}
L2PricedTransactions []L2PricedTransaction
CrossChainMessage = MessageBus.StructsCrossChainMessage
CrossChainMessages = []CrossChainMessage
ValueTransferEvent struct {
Sender common.Address
Receiver common.Address
Amount *big.Int
Sequence uint64
}
ValueTransferEvents = []ValueTransferEvent
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.
EncryptedParamsGetBalance []byte // The params for an RPC getBalance request, as a JSON object encrypted with the public key of the enclave.
EncryptedParamsCall []byte // As above, but for an RPC call request.
EncryptedParamsGetTxByHash []byte // As above, but for an RPC getTransactionByHash request.
EncryptedParamsGetTxReceipt []byte // As above, but for an RPC getTransactionReceipt request.
EncryptedParamsLogSubscription []byte // As above, but for an RPC logs subscription request.
EncryptedParamsDebugLogRelevancy []byte // As above, but for an RPC the relevancy call.
EncryptedParamsSendRawTx []byte // As above, but for an RPC sendRawTransaction request.
EncryptedParamsGetTxCount []byte // As above, but for an RPC getTransactionCount request.
EncryptedParamsEstimateGas []byte // As above, but for an RPC estimateGas request.
EncryptedParamsGetLogs []byte // As above, but for an RPC getLogs request.
EncryptedParamsGetPersonalTransactions []byte
EncryptedParamsGetStorageSlot []byte
Nonce = uint64
EncodedRollup []byte
EncodedBatchMsg []byte
EncodedBatchRequest []byte
EncodedBlobHashes []byte
EnclaveID = common.Address
)
func (txs L2PricedTransactions) ToTransactions() types.Transactions {
ret := make(types.Transactions, 0)
for _, tx := range txs {
ret = append(ret, tx.Tx)
}
return ret
}
const (
L2GenesisHeight = uint64(0)
L1GenesisHeight = uint64(0)
L2GenesisSeqNo = uint64(1)
// HeightCommittedBlocks is the number of blocks deep a transaction must be to be considered safe from reorganisations.
HeightCommittedBlocks = 15
)
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)
}