From 21f4932c9bbb8664cf7b3e3c3602b6a48c747893 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ula=C5=9F=20Erdo=C4=9Fan?= Date: Sun, 24 Sep 2023 04:42:41 +0300 Subject: [PATCH] core/vm: force the input length of p256verify --- core/vm/contracts.go | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/core/vm/contracts.go b/core/vm/contracts.go index 0d63721425..94bf91ee40 100644 --- a/core/vm/contracts.go +++ b/core/vm/contracts.go @@ -1152,13 +1152,15 @@ func (c *p256Verify) RequiredGas(input []byte) uint64 { return params.P256VerifyGas } -// Run executes the precompiled contract, returning the output and the used gas +// Run executes the precompiled contract with given 160 bytes of param, returning the output and the used gas func (c *p256Verify) Run(input []byte) ([]byte, error) { // Required input length is 160 bytes const p256VerifyInputLength = 160 - - // "input" is (hash, r, s, x, y), each 32 bytes - input = common.RightPadBytes(input, p256VerifyInputLength) + // Check the input length + if len(input) != p256VerifyInputLength { + // Input length is invalid + return nil, nil + } // Extract the hash, r, s, x, y from the input hash := input[0:32]