forked from ten-protocol/go-ten
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathutils.go
52 lines (46 loc) · 1.41 KB
/
utils.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
package evm
import (
"math/big"
gethcommon "github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/core/types"
"github.com/ethereum/go-ethereum/rlp"
"github.com/obscuronet/go-obscuro/go/common"
"github.com/obscuronet/go-obscuro/go/enclave/crypto"
)
// Perform the conversion between an Obscuro header and an Ethereum header that the EVM understands
// in the first stage we just encode the obscuro header in the Extra field
// todo - find a better way
func convertToEthHeader(h *common.BatchHeader, secret []byte) (*types.Header, error) {
obscuroHeader, err := rlp.EncodeToBytes(h)
if err != nil {
return nil, err
}
// deterministically calculate private randomness that will be exposed to the evm
randomness := crypto.PrivateRollupRnd(h.MixDigest.Bytes(), secret)
return &types.Header{
ParentHash: h.ParentHash,
Root: h.Root,
TxHash: h.TxHash,
ReceiptHash: h.ReceiptHash,
Bloom: h.Bloom,
Difficulty: big.NewInt(0).SetBytes(randomness),
Number: h.Number,
GasLimit: 1_000_000_000,
GasUsed: 0,
Time: h.Time,
Extra: obscuroHeader,
MixDigest: gethcommon.BytesToHash(randomness),
Nonce: types.BlockNonce{},
BaseFee: gethcommon.Big0,
}, nil
}
/*
func convertFromEthHeader(header *types.Header) *common.Header {
h := new(common.Header)
err := rlp.DecodeBytes(header.Extra, h)
if err != nil {
panic(err)
}
return h
}
*/