From 12e6610591ed0ec13a94d3cd18e21edf83358c17 Mon Sep 17 00:00:00 2001 From: Louis Tremblay Thibault Date: Fri, 30 Jun 2023 09:51:31 +0200 Subject: [PATCH] Fix nil pointer dereference on gas estimation (#133) * fix(contracts): remove double variable declaration * fix(contracts): remove unneeded change --- core/vm/contracts.go | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 20bc3189de88..9eccabe1edaa 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -1465,9 +1465,9 @@ func (e *fheAdd) RequiredGas(accessibleState PrecompileAccessibleState, input [] logger.Error("fheAdd/Sub RequiredGas() can not detect if operator is meant to be scalar", "err", err, "input", hex.EncodeToString(input)) return 0 } - var lhs *verifiedCiphertext + var lhs, rhs *verifiedCiphertext if !isScalar { - lhs, rhs, err := get2VerifiedOperands(accessibleState, input) + lhs, rhs, err = get2VerifiedOperands(accessibleState, input) if err != nil { logger.Error("fheAdd/Sub RequiredGas() ciphertext inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 @@ -1933,9 +1933,9 @@ func (e *fheLe) RequiredGas(accessibleState PrecompileAccessibleState, input []b logger.Error("comparison RequiredGas() can not detect if operator is meant to be scalar", "err", err, "input", hex.EncodeToString(input)) return 0 } - var lhs *verifiedCiphertext + var lhs, rhs *verifiedCiphertext if !isScalar { - lhs, rhs, err := get2VerifiedOperands(accessibleState, input) + lhs, rhs, err = get2VerifiedOperands(accessibleState, input) if err != nil { logger.Error("comparison RequiredGas() ciphertext inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 @@ -2123,9 +2123,9 @@ func (e *fheMul) RequiredGas(accessibleState PrecompileAccessibleState, input [] logger.Error("fheMul RequiredGas() can not detect if operator is meant to be scalar", "err", err, "input", hex.EncodeToString(input)) return 0 } - var lhs *verifiedCiphertext + var lhs, rhs *verifiedCiphertext if !isScalar { - lhs, rhs, err := get2VerifiedOperands(accessibleState, input) + lhs, rhs, err = get2VerifiedOperands(accessibleState, input) if err != nil { logger.Error("fheMul RequiredGas() ciphertext inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 @@ -2427,9 +2427,9 @@ func (e *fheShl) RequiredGas(accessibleState PrecompileAccessibleState, input [] logger.Error("fheShift RequiredGas() can not detect if operator is meant to be scalar", "err", err, "input", hex.EncodeToString(input)) return 0 } - var lhs *verifiedCiphertext + var lhs, rhs *verifiedCiphertext if !isScalar { - lhs, rhs, err := get2VerifiedOperands(accessibleState, input) + lhs, rhs, err = get2VerifiedOperands(accessibleState, input) if err != nil { logger.Error("fheShift RequiredGas() ciphertext inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0 @@ -3037,9 +3037,9 @@ func (e *fheMin) RequiredGas(accessibleState PrecompileAccessibleState, input [] logger.Error("fheMin/Max RequiredGas() can not detect if operator is meant to be scalar", "err", err, "input", hex.EncodeToString(input)) return 0 } - var lhs *verifiedCiphertext + var lhs, rhs *verifiedCiphertext if !isScalar { - lhs, rhs, err := get2VerifiedOperands(accessibleState, input) + lhs, rhs, err = get2VerifiedOperands(accessibleState, input) if err != nil { logger.Error("fheMin/Max RequiredGas() ciphertext inputs not verified", "err", err, "input", hex.EncodeToString(input)) return 0