Skip to content

Commit

Permalink
Merge pull request #40 from FhenixProtocol/decrypts-in-txs
Browse files Browse the repository at this point in the history
Decrypts in txs
  • Loading branch information
toml01 authored Jan 3, 2024
2 parents 43f79be + 9000a14 commit 18a6bd0
Showing 1 changed file with 9 additions and 19 deletions.
28 changes: 9 additions & 19 deletions precompiles/contracts.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ func Reencrypt(input []byte, tp *TxParams) ([]byte, error) {
logger.Info("starting new precompiled contract function ", getFunctionName())
}

if !tp.EthCall {
msg := "reencrypt only supported on EthCall"
logger.Error(msg)
return nil, vm.ErrExecutionReverted
}

if len(input) != 64 {
msg := "reencrypt input len must be 64 bytes"
logger.Error(msg, " input ", hex.EncodeToString(input), " len ", len(input))
Expand All @@ -146,6 +140,10 @@ func Reencrypt(input []byte, tp *TxParams) ([]byte, error) {
return nil, vm.ErrExecutionReverted
}

if tp.GasEstimation {
return []byte{1}, nil
}

decryptedValue, err := tfhe.Decrypt(*ct)
if err != nil {
logger.Error("failed decrypting ciphertext ", "error ", err)
Expand All @@ -171,12 +169,6 @@ func Decrypt(input []byte, tp *TxParams) (*big.Int, error) {
logger.Info("starting new precompiled contract function ", getFunctionName())
}

if !tp.EthCall {
msg := "decrypt only supported on EthCall"
logger.Error(msg)
return nil, vm.ErrExecutionReverted
}

if len(input) != 32 {
msg := "decrypt input len must be 32 bytes"
logger.Error(msg, " input ", hex.EncodeToString(input), " len ", len(input))
Expand All @@ -190,6 +182,10 @@ func Decrypt(input []byte, tp *TxParams) (*big.Int, error) {
return nil, vm.ErrExecutionReverted
}

if tp.GasEstimation {
return new(big.Int).SetUint64(1), nil
}

decryptedValue, err := tfhe.Decrypt(*ct)
if err != nil {
logger.Error("failed decrypting ciphertext", " error ", err)
Expand Down Expand Up @@ -383,12 +379,6 @@ func Req(input []byte, tp *TxParams) ([]byte, error) {
logger.Info("starting new precompiled contract function ", getFunctionName())
}

if tp.EthCall {
msg := "require not supported on EthCall"
logger.Error(msg)
return nil, vm.ErrExecutionReverted
}

if len(input) != 32 {
msg := "require input len must be 32 bytes"
logger.Error(msg, " input ", hex.EncodeToString(input), " len ", len(input))
Expand All @@ -403,7 +393,7 @@ func Req(input []byte, tp *TxParams) ([]byte, error) {
}
// If we are not committing to state, assume the require is true, avoiding any side effects
// (i.e. mutatiting the oracle DB).
if !tp.Commit {
if tp.GasEstimation {
return nil, nil
}

Expand Down

0 comments on commit 18a6bd0

Please sign in to comment.