Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IsReservedFunctionName vmhook impl #851

Merged
merged 7 commits into from
Jun 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@
DeleteFromReturnData = 10
GetCodeMetadata = 10
IsBuiltinFunction = 10
IsReservedFunctionName = 10

[EthAPICost]
UseGas = 10
Expand Down
1 change: 1 addition & 0 deletions config/gasCost.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@ type BaseOpsAPICost struct {
DeleteFromReturnData uint64
GetCodeMetadata uint64
IsBuiltinFunction uint64
IsReservedFunctionName uint64
}

// DynamicStorageLoadCostCoefficients holds the signed coefficients of the func that will compute the gas cost
Expand Down
1 change: 1 addition & 0 deletions config/gasSchedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ func FillGasMapBaseOpsAPICosts(value, asyncCallbackGasLock uint64) map[string]ui
gasMap["DeleteFromReturnData"] = value
gasMap["GetCodeMetadata"] = value
gasMap["IsBuiltinFunction"] = value
gasMap["IsReservedFunctionName"] = value

return gasMap
}
Expand Down
1 change: 1 addition & 0 deletions executor/vmHooks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions executor/wrapper/wrapperVMHooks.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions mock/context/executorMockFunc.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions mock/context/runtimeContextMock.go
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,11 @@ func (r *RuntimeContextMock) ValidateCallbackName(_ string) error {
return nil
}

// IsReservedFunctionName moked method
func (r *RuntimeContextMock) IsReservedFunctionName(_ string) bool {
return false
}

// HasFunction mocked method
func (r *RuntimeContextMock) HasFunction(_ string) bool {
return r.HasFunctionResult
Expand Down
5 changes: 5 additions & 0 deletions mock/context/runtimeContextWrapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -582,6 +582,11 @@ func (contextWrapper *RuntimeContextWrapper) ValidateCallbackName(callbackName s
return contextWrapper.runtimeContext.ValidateCallbackName(callbackName)
}

// IsReservedFunctionName calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) IsReservedFunctionName(functionName string) bool {
return contextWrapper.runtimeContext.IsReservedFunctionName(functionName)
}

// HasFunction calls corresponding xxxFunc function, that by default in turn calls the original method of the wrapped RuntimeContext
func (contextWrapper *RuntimeContextWrapper) HasFunction(functionName string) bool {
return contextWrapper.runtimeContext.HasFunction(functionName)
Expand Down
2 changes: 2 additions & 0 deletions scenario/gasSchedules/gasScheduleEmbedGenerated.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions scenario/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
DeleteFromReturnData = 100
GetCodeMetadata = 100
IsBuiltinFunction = 100
IsReservedFunctionName = 100

[EthAPICost]
UseGas = 100
Expand Down
1 change: 1 addition & 0 deletions scenario/gasSchedules/gasScheduleV4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@
DeleteFromReturnData = 100
GetCodeMetadata = 100
IsBuiltinFunction = 100
IsReservedFunctionName = 100

[EthAPICost]
UseGas = 100
Expand Down
5 changes: 5 additions & 0 deletions vmhost/contexts/runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,11 @@ func (context *runtimeContext) ValidateCallbackName(callbackName string) error {
return nil
}

// IsReservedFunctionName checks if the function name is reserved
func (context *runtimeContext) IsReservedFunctionName(functionName string) bool {
return context.validator.reserved.IsReserved(functionName)
}

// HasFunction checks if loaded contract has a function (endpoint) with given name.
func (context *runtimeContext) HasFunction(functionName string) bool {
return context.iTracker.Instance().HasFunction(functionName)
Expand Down
3 changes: 3 additions & 0 deletions vmhost/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,9 @@ type RuntimeContext interface {
GetAllErrors() error

ValidateCallbackName(callbackName string) error

IsReservedFunctionName(functionName string) bool

HasFunction(functionName string) bool
GetPrevTxHash() []byte
EndExecution()
Expand Down
23 changes: 23 additions & 0 deletions vmhost/vmhooks/baseOps.go
Original file line number Diff line number Diff line change
Expand Up @@ -2324,6 +2324,29 @@ func (context *VMHooksImpl) GetCallValueTokenNameByIndex(
return int32(len(tokenName))
}

// IsReservedFunctionName VMHooks implementation.
// @autogenerate(VMHooks)
func (context *VMHooksImpl) IsReservedFunctionName(nameHandle int32) int32 {
host := context.host
managedTypes := context.GetManagedTypesContext()
runtime := host.Runtime()
metering := host.Metering()

gasToUse := metering.GasSchedule().BaseOpsAPICost.IsReservedFunctionName
metering.UseAndTraceGas(gasToUse)

name, err := managedTypes.GetBytes(nameHandle)
if context.WithFault(err, runtime.BaseOpsErrorShouldFailExecution()) {
return -1
}

if runtime.IsReservedFunctionName(string(name)) {
return 1
}

return 0
}

// WriteLog VMHooks implementation.
// @autogenerate(VMHooks)
func (context *VMHooksImpl) WriteLog(
Expand Down
12 changes: 12 additions & 0 deletions wasmer/wasmerImportsCgo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Binary file modified wasmer2/libvmexeccapi.dylib
Binary file not shown.
1 change: 1 addition & 0 deletions wasmer2/libvmexeccapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ typedef struct {
int32_t (*get_num_esdt_transfers_func_ptr)(void *context);
int32_t (*get_call_value_token_name_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset);
int32_t (*get_call_value_token_name_by_index_func_ptr)(void *context, int32_t call_value_offset, int32_t token_name_offset, int32_t index);
int32_t (*is_reserved_function_name_func_ptr)(void *context, int32_t name_handle);
void (*write_log_func_ptr)(void *context, int32_t data_pointer, int32_t data_length, int32_t topic_ptr, int32_t num_topics);
void (*write_event_log_func_ptr)(void *context, int32_t num_topics, int32_t topic_lengths_offset, int32_t topic_offset, int32_t data_offset, int32_t data_length);
int64_t (*get_block_timestamp_func_ptr)(void *context);
Expand Down
Binary file modified wasmer2/libvmexeccapi.so
Binary file not shown.
Binary file modified wasmer2/libvmexeccapi_arm.dylib
Binary file not shown.
Binary file modified wasmer2/libvmexeccapi_arm.so
Binary file not shown.
8 changes: 8 additions & 0 deletions wasmer2/wasmer2ImportsCgo.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions wasmer2/wasmer2Names.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading