Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: call otel describe functions after err checks #126

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions fhevm/ciphertext_storage.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
"github.com/zama-ai/fhevm-go/fhevm/tfhe"
)

var ciphertextStorage = common.BytesToAddress([]byte{94})
var CiphertextStorageAddress = common.BytesToAddress([]byte{94})

func newInt(buf []byte) *uint256.Int {
i := uint256.NewInt(0)
Expand Down Expand Up @@ -50,13 +50,13 @@ func newCiphertextMetadata(buf [32]byte) *ciphertextMetadata {
}

func isCiphertextPersisted(env EVMEnvironment, handle common.Hash) bool {
metadataInt := newInt(env.GetState(ciphertextStorage, handle).Bytes())
metadataInt := newInt(env.GetState(CiphertextStorageAddress, handle).Bytes())
return !metadataInt.IsZero()
}

// Returns the ciphertext metadata for the given handle or nil if it doesn't point to a ciphertext.
func loadCiphertextMetadata(env EVMEnvironment, handle common.Hash) *ciphertextMetadata {
metadataInt := newInt(env.GetState(ciphertextStorage, handle).Bytes())
metadataInt := newInt(env.GetState(CiphertextStorageAddress, handle).Bytes())
if metadataInt.IsZero() {
return nil
}
Expand All @@ -73,7 +73,7 @@ func loadCiphertext(env EVMEnvironment, handle common.Hash) (ct *tfhe.TfheCipher
return ct, 0
}

metadataInt := newInt(env.GetState(ciphertextStorage, handle).Bytes())
metadataInt := newInt(env.GetState(CiphertextStorageAddress, handle).Bytes())
if metadataInt.IsZero() {
return nil, ColdSloadCostEIP2929
}
Expand All @@ -83,7 +83,7 @@ func loadCiphertext(env EVMEnvironment, handle common.Hash) (ct *tfhe.TfheCipher
idx := newInt(handle.Bytes())
idx.AddUint64(idx, 1)
for left > 0 {
bytes := env.GetState(ciphertextStorage, idx.Bytes32())
bytes := env.GetState(CiphertextStorageAddress, idx.Bytes32())
toAppend := minUint64(uint64(len(bytes)), left)
left -= toAppend
ctBytes = append(ctBytes, bytes[0:toAppend]...)
Expand Down Expand Up @@ -117,7 +117,7 @@ func persistCiphertext(env EVMEnvironment, handle common.Hash, ct *tfhe.TfheCiph
metadata.fheUintType = ct.Type()

// Persist the metadata in storage.
env.SetState(ciphertextStorage, handle, metadata.serialize())
env.SetState(CiphertextStorageAddress, handle, metadata.serialize())

ciphertextSlot := newInt(handle.Bytes())
ciphertextSlot.AddUint64(ciphertextSlot, 1)
Expand All @@ -133,7 +133,7 @@ func persistCiphertext(env EVMEnvironment, handle common.Hash, ct *tfhe.TfheCiph
ctBytes := ct.Serialize()
for i, b := range ctBytes {
if i%32 == 0 && i != 0 {
env.SetState(ciphertextStorage, ciphertextSlot.Bytes32(), common.BytesToHash(ctPart32))
env.SetState(CiphertextStorageAddress, ciphertextSlot.Bytes32(), common.BytesToHash(ctPart32))
ciphertextSlot.AddUint64(ciphertextSlot, 1)
ctPart32 = make([]byte, 32)
partIdx = 0
Expand All @@ -142,7 +142,7 @@ func persistCiphertext(env EVMEnvironment, handle common.Hash, ct *tfhe.TfheCiph
partIdx++
}
if len(ctPart32) != 0 {
env.SetState(ciphertextStorage, ciphertextSlot.Bytes32(), common.BytesToHash(ctPart32))
env.SetState(CiphertextStorageAddress, ciphertextSlot.Bytes32(), common.BytesToHash(ctPart32))
}
}

Expand Down
16 changes: 8 additions & 8 deletions fhevm/operators_arithmetic.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func fheAddRun(environment EVMEnvironment, caller common.Address, addr common.Ad

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheAdd failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheAdd operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -50,11 +50,11 @@ func fheAddRun(environment EVMEnvironment, caller common.Address, addr common.Ad

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheAdd scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -87,11 +87,11 @@ func fheSubRun(environment EVMEnvironment, caller common.Address, addr common.Ad

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheSub failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheSub operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -116,11 +116,11 @@ func fheSubRun(environment EVMEnvironment, caller common.Address, addr common.Ad

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheSub scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -153,11 +153,11 @@ func fheMulRun(environment EVMEnvironment, caller common.Address, addr common.Ad

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheMul failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheMul operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -182,11 +182,11 @@ func fheMulRun(environment EVMEnvironment, caller common.Address, addr common.Ad

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheMul scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -223,11 +223,11 @@ func fheDivRun(environment EVMEnvironment, caller common.Address, addr common.Ad
return nil, err
} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheDiv scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -264,11 +264,11 @@ func fheRemRun(environment EVMEnvironment, caller common.Address, addr common.Ad
return nil, err
} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheRem scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down
22 changes: 11 additions & 11 deletions fhevm/operators_bit.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ func fheShlRun(environment EVMEnvironment, caller common.Address, addr common.Ad

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheShl failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheShl operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -50,11 +50,11 @@ func fheShlRun(environment EVMEnvironment, caller common.Address, addr common.Ad

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheShl scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -87,11 +87,11 @@ func fheShrRun(environment EVMEnvironment, caller common.Address, addr common.Ad

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheShr failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheShr operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -116,11 +116,11 @@ func fheShrRun(environment EVMEnvironment, caller common.Address, addr common.Ad

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheShr scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -153,11 +153,11 @@ func fheRotlRun(environment EVMEnvironment, caller common.Address, addr common.A

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheShl failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheShl operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -182,11 +182,11 @@ func fheRotlRun(environment EVMEnvironment, caller common.Address, addr common.A

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheRotl scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -219,11 +219,11 @@ func fheRotrRun(environment EVMEnvironment, caller common.Address, addr common.A

if !isScalar {
lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheRotr failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if lhs.Type() != rhs.Type() {
msg := "fheRotr operand type mismatch"
logger.Error(msg, "lhs", lhs.Type(), "rhs", rhs.Type())
Expand All @@ -248,11 +248,11 @@ func fheRotrRun(environment EVMEnvironment, caller common.Address, addr common.A

} else {
lhs, rhs, _, err := getScalarOperands(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))
if err != nil {
logger.Error("fheRotr scalar failed to load inputs", "err", err, "input", hex.EncodeToString(input))
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), plainOperand(*rhs))

// If we are doing gas estimation, skip execution and insert a random ciphertext as a result.
if !environment.IsCommitting() && !environment.IsEthCall() {
Expand Down Expand Up @@ -364,11 +364,11 @@ func fheBitAndRun(environment EVMEnvironment, caller common.Address, addr common
}

lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheBitAnd failed to load inputs", "err", err)
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))

if lhs.Type() != rhs.Type() {
msg := "fheBitAnd operand type mismatch"
Expand Down Expand Up @@ -411,11 +411,11 @@ func fheBitOrRun(environment EVMEnvironment, caller common.Address, addr common.
}

lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheBitOr failed to load inputs", "err", err)
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))

if lhs.Type() != rhs.Type() {
msg := "fheBitOr operand type mismatch"
Expand Down Expand Up @@ -458,11 +458,11 @@ func fheBitXorRun(environment EVMEnvironment, caller common.Address, addr common
}

lhs, rhs, _, err := load2Ciphertexts(environment, input)
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))
if err != nil {
logger.Error("fheBitXor failed to load inputs", "err", err)
return nil, err
}
otelDescribeOperands(runSpan, encryptedOperand(*lhs), encryptedOperand(*rhs))

if lhs.Type() != rhs.Type() {
msg := "fheBitXor operand type mismatch"
Expand Down
Loading
Loading