From f24cc576461907bfcc4edcfc382352792cbf51eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bastian=20M=C3=BCller?= Date: Tue, 5 Dec 2023 16:50:00 -0800 Subject: [PATCH] remove unsafeRandom --- runtime/runtime_test.go | 6 +----- runtime/stdlib/builtin.go | 1 - runtime/stdlib/random.go | 38 -------------------------------------- 3 files changed, 1 insertion(+), 44 deletions(-) diff --git a/runtime/runtime_test.go b/runtime/runtime_test.go index 6a716d50f3..f0a305e81f 100644 --- a/runtime/runtime_test.go +++ b/runtime/runtime_test.go @@ -4468,10 +4468,7 @@ func TestRuntimeRandom(t *testing.T) { script := []byte(` transaction { prepare() { - let rand1 = revertibleRandom() - log(rand1) - let rand2 = unsafeRandom() - log(rand2) + log(revertibleRandom()) } } `) @@ -4504,7 +4501,6 @@ func TestRuntimeRandom(t *testing.T) { assert.Equal(t, []string{ "7558174677681708339", - "7558174677681708339", }, loggedMessages, ) diff --git a/runtime/stdlib/builtin.go b/runtime/stdlib/builtin.go index 7c64f03d4b..26ed8399e6 100644 --- a/runtime/stdlib/builtin.go +++ b/runtime/stdlib/builtin.go @@ -46,7 +46,6 @@ func DefaultStandardLibraryValues(handler StandardLibraryHandler) []StandardLibr RLPContract, NewLogFunction(handler), NewRevertibleRandomFunction(handler), - NewUnsafeRandomFunction(handler), NewGetBlockFunction(handler), NewGetCurrentBlockFunction(handler), NewGetAccountFunction(handler), diff --git a/runtime/stdlib/random.go b/runtime/stdlib/random.go index 88dc2d2893..4e738e8dba 100644 --- a/runtime/stdlib/random.go +++ b/runtime/stdlib/random.go @@ -68,41 +68,3 @@ func NewRevertibleRandomFunction(generator RandomGenerator) StandardLibraryValue }, ) } - -// `unsafeRandom` related constants and functions will be deleted -// when the function is deprecated -const unsafeRandomFunctionDocString = ` -Deprecated: Use revertibleRandom instead. - -Returns a pseudo-random number. - -NOTE: The use of this function is unsafe if not used correctly. - -Follow best practices to prevent security issues when using this function -` - -var unsafeRandomFunctionType = revertibleRandomFunctionType - -func NewUnsafeRandomFunction(generator RandomGenerator) StandardLibraryValue { - return NewStandardLibraryFunction( - "unsafeRandom", - unsafeRandomFunctionType, - unsafeRandomFunctionDocString, - func(invocation interpreter.Invocation) interpreter.Value { - return interpreter.NewUInt64Value( - invocation.Interpreter, - func() uint64 { - var buffer [8]byte - var err error - errors.WrapPanic(func() { - err = generator.ReadRandom(buffer[:]) - }) - if err != nil { - panic(interpreter.WrappedExternalError(err)) - } - return binary.LittleEndian.Uint64(buffer[:]) - }, - ) - }, - ) -}