Skip to content

Commit

Permalink
Merge pull request #809 from multiversx/speed-up-checks-early
Browse files Browse the repository at this point in the history
Speed up check - early checks
  • Loading branch information
sasurobert authored Jan 10, 2024
2 parents 5526c1d + b7fa5b5 commit 40dadf9
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
4 changes: 4 additions & 0 deletions vmhost/contexts/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,10 @@ func (context *runtimeContext) CountSameContractInstancesOnStack(address []byte)
// FunctionNameChecked returns the function name, after checking that it exists in the contract.
func (context *runtimeContext) FunctionNameChecked() (string, error) {
functionName := context.FunctionName()
err := verifyCallFunction(functionName)
if err != nil {
return "", executor.ErrFuncNotFound
}
if context.HasFunction(functionName) {
return functionName, nil
}
Expand Down
17 changes: 14 additions & 3 deletions vmhost/contexts/validator.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,20 @@ func (validator *wasmValidator) verifyProtectedFunctions(instance executor.Insta
}

func (validator *wasmValidator) verifyValidFunctionName(functionName string) error {
err := verifyCallFunction(functionName)
if err != nil {
return err
}

errInvalidName := fmt.Errorf("%w: %x", vmhost.ErrInvalidFunctionName, functionName)
if validator.reserved.IsReserved(functionName) {
return errInvalidName
}

return nil
}

func verifyCallFunction(functionName string) error {
const maxLengthOfFunctionName = 256

errInvalidName := fmt.Errorf("%w: %s", vmhost.ErrInvalidFunctionName, functionName)
Expand All @@ -78,9 +92,6 @@ func (validator *wasmValidator) verifyValidFunctionName(functionName string) err
if !validCharactersOnly(functionName) {
return errInvalidName
}
if validator.reserved.IsReserved(functionName) {
return errInvalidName
}

return nil
}
Expand Down

0 comments on commit 40dadf9

Please sign in to comment.