This repository has been archived by the owner on Dec 23, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathevm.go
67 lines (54 loc) · 1.82 KB
/
evm.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
package fhevm
import (
"log/slog"
"github.com/ethereum/go-ethereum/common"
"github.com/ethereum/go-ethereum/crypto"
"github.com/holiman/uint256"
"github.com/zama-ai/fhevm-go/fhevm/tfhe"
)
var protectedStorageAddrCallerAddr common.Address
var defaultProtectedStorageAddrCallerAddr = []byte{93}
// Set the addr to be used as caller when creating protected storage contracts
func SetProtectedStorageAddrCallerAddr(addr []byte) {
protectedStorageAddrCallerAddr = common.BytesToAddress(addr)
}
func init() {
SetProtectedStorageAddrCallerAddr(defaultProtectedStorageAddrCallerAddr)
}
// A Logger interface for the EVM.
type Logger interface {
Debug(msg string, keyvals ...interface{})
Info(msg string, keyvals ...interface{})
Error(msg string, keyvals ...interface{})
}
// A default Logger implementation that logs to stdout.
type DefaultLogger struct {
slogger *slog.Logger
}
func NewDefaultLogger() Logger {
logger := &DefaultLogger{}
logger.slogger = slog.Default().With("module", "fhevm-go")
return logger
}
func (l *DefaultLogger) Debug(msg string, keyvals ...interface{}) {
l.slogger.Debug(msg, keyvals...)
}
func (l *DefaultLogger) Info(msg string, keyvals ...interface{}) {
l.slogger.Info(msg, keyvals...)
}
func (l *DefaultLogger) Error(msg string, keyvals ...interface{}) {
l.slogger.Error(msg, keyvals...)
}
func insertRandomCiphertext(environment EVMEnvironment, t tfhe.FheUintType) []byte {
nextCtHash := &environment.FhevmData().nextCiphertextHashOnGasEst
ctHashBytes := crypto.Keccak256(nextCtHash.Bytes())
handle := common.BytesToHash(ctHashBytes)
ct := new(tfhe.TfheCiphertext)
ct.FheUintType = t
ct.Hash = &handle
insertCiphertextToMemory(environment, handle, ct)
temp := nextCtHash.Clone()
nextCtHash.Add(temp, uint256.NewInt(1))
return ct.GetHash().Bytes()
}
func InitFhevm(accessibleState EVMEnvironment) {}