Skip to content

Commit

Permalink
remove unsafeRandom
Browse files Browse the repository at this point in the history
  • Loading branch information
turbolent committed Dec 6, 2023
1 parent cd54f5d commit f24cc57
Show file tree
Hide file tree
Showing 3 changed files with 1 addition and 44 deletions.
6 changes: 1 addition & 5 deletions runtime/runtime_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
`)
Expand Down Expand Up @@ -4504,7 +4501,6 @@ func TestRuntimeRandom(t *testing.T) {
assert.Equal(t,
[]string{
"7558174677681708339",
"7558174677681708339",
},
loggedMessages,
)
Expand Down
1 change: 0 additions & 1 deletion runtime/stdlib/builtin.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func DefaultStandardLibraryValues(handler StandardLibraryHandler) []StandardLibr
RLPContract,
NewLogFunction(handler),
NewRevertibleRandomFunction(handler),
NewUnsafeRandomFunction(handler),
NewGetBlockFunction(handler),
NewGetCurrentBlockFunction(handler),
NewGetAccountFunction(handler),
Expand Down
38 changes: 0 additions & 38 deletions runtime/stdlib/random.go
Original file line number Diff line number Diff line change
Expand Up @@ -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[:])
},
)
},
)
}

0 comments on commit f24cc57

Please sign in to comment.