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

add new blockchain hooks #854

Open
wants to merge 13 commits into
base: rc/barnard
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions config/config.toml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@
GetCodeMetadata = 10
IsBuiltinFunction = 10
IsReservedFunctionName = 10
GetRoundTime = 10
EpochStartBlockTimeStamp = 10
EpochStartBlockNonce = 10
EpochStartBlockRound = 10

[EthAPICost]
UseGas = 10
Expand Down
108 changes: 56 additions & 52 deletions config/gasCost.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,58 +31,62 @@ type BaseOperationCost struct {

// BaseOpsAPICost defines the API operations gas cost config structure
type BaseOpsAPICost struct {
GetSCAddress uint64
GetOwnerAddress uint64
IsSmartContract uint64
GetShardOfAddress uint64
GetExternalBalance uint64
GetBlockHash uint64
GetOriginalTxHash uint64
GetCurrentTxHash uint64
GetPrevTxHash uint64
TransferValue uint64
GetArgument uint64
GetFunction uint64
GetNumArguments uint64
StorageStore uint64
StorageLoad uint64
CachedStorageLoad uint64
GetCaller uint64
GetCallValue uint64
Log uint64
Finish uint64
SignalError uint64
GetBlockTimeStamp uint64
GetGasLeft uint64
Int64GetArgument uint64
Int64StorageStore uint64
Int64StorageLoad uint64
Int64Finish uint64
GetStateRootHash uint64
GetBlockNonce uint64
GetBlockEpoch uint64
GetBlockRound uint64
GetBlockRandomSeed uint64
ExecuteOnSameContext uint64
ExecuteOnDestContext uint64
DelegateExecution uint64
ExecuteReadOnly uint64
AsyncCallStep uint64
AsyncCallbackGasLock uint64
CreateAsyncCall uint64
SetAsyncCallback uint64
SetAsyncGroupCallback uint64
SetAsyncContextCallback uint64
GetCallbackClosure uint64
CreateContract uint64
GetReturnData uint64
GetNumReturnData uint64
GetReturnDataSize uint64
CleanReturnData uint64
DeleteFromReturnData uint64
GetCodeMetadata uint64
IsBuiltinFunction uint64
IsReservedFunctionName uint64
GetSCAddress uint64
GetOwnerAddress uint64
IsSmartContract uint64
GetShardOfAddress uint64
GetExternalBalance uint64
GetBlockHash uint64
GetOriginalTxHash uint64
GetCurrentTxHash uint64
GetPrevTxHash uint64
TransferValue uint64
GetArgument uint64
GetFunction uint64
GetNumArguments uint64
StorageStore uint64
StorageLoad uint64
CachedStorageLoad uint64
GetCaller uint64
GetCallValue uint64
Log uint64
Finish uint64
SignalError uint64
GetBlockTimeStamp uint64
GetGasLeft uint64
Int64GetArgument uint64
Int64StorageStore uint64
Int64StorageLoad uint64
Int64Finish uint64
GetStateRootHash uint64
GetBlockNonce uint64
GetBlockEpoch uint64
GetBlockRound uint64
GetBlockRandomSeed uint64
ExecuteOnSameContext uint64
ExecuteOnDestContext uint64
DelegateExecution uint64
ExecuteReadOnly uint64
AsyncCallStep uint64
AsyncCallbackGasLock uint64
CreateAsyncCall uint64
SetAsyncCallback uint64
SetAsyncGroupCallback uint64
SetAsyncContextCallback uint64
GetCallbackClosure uint64
CreateContract uint64
GetReturnData uint64
GetNumReturnData uint64
GetReturnDataSize uint64
CleanReturnData uint64
DeleteFromReturnData uint64
GetCodeMetadata uint64
IsBuiltinFunction uint64
IsReservedFunctionName uint64
GetRoundTime uint64
EpochStartBlockTimeStamp uint64
EpochStartBlockNonce uint64
EpochStartBlockRound uint64
}

// DynamicStorageLoadCostCoefficients holds the signed coefficients of the func that will compute the gas cost
Expand Down
4 changes: 4 additions & 0 deletions config/gasSchedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,10 @@ func FillGasMapBaseOpsAPICosts(value, asyncCallbackGasLock uint64) map[string]ui
gasMap["GetCodeMetadata"] = value
gasMap["IsBuiltinFunction"] = value
gasMap["IsReservedFunctionName"] = value
gasMap["GetRoundTime"] = value
gasMap["EpochStartBlockTimeStamp"] = value
gasMap["EpochStartBlockNonce"] = value
gasMap["EpochStartBlockRound"] = value

return gasMap
}
Expand Down
4 changes: 4 additions & 0 deletions executor/vmHooks.go

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

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

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

8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ require (
github.com/btcsuite/btcd/chaincfg/chainhash v1.0.1
github.com/gogo/protobuf v1.3.2
github.com/mitchellh/mapstructure v1.5.0
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6
github.com/multiversx/mx-chain-core-go v1.2.22
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6
github.com/multiversx/mx-chain-logger-go v1.0.15
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20240802080531-0906745c04b2
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241021074004-c2bdb78da54a
github.com/multiversx/mx-components-big-int v1.0.0
github.com/pelletier/go-toml v1.9.3
github.com/stretchr/testify v1.8.1
Expand Down
16 changes: 8 additions & 8 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -83,18 +83,18 @@ github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyua
github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo=
github.com/mr-tron/base58 v1.2.0 h1:T/HDJBh4ZCPbU39/+c3rRvE0uKBQlU27+QI8LJ4t64o=
github.com/mr-tron/base58 v1.2.0/go.mod h1:BinMc/sQntlIE1frQmRFPUoPA1Zkr8VRgBdjWI2mNwc=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6 h1:Q7uUjTYTrt8Mw9oq5JWPv+WHhpxHTv6lhZZlhPuNcoQ=
github.com/multiversx/mx-chain-core-go v1.2.21-0.20240725065431-6e9bfee5a4c6/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-core-go v1.2.22 h1:yDYrvoQOBbsDerEp7L3+de5AfMy3pTF333gWPpd+FNk=
github.com/multiversx/mx-chain-core-go v1.2.22/go.mod h1:B5zU4MFyJezmEzCsAHE9YNULmGCm2zbPHvl9hazNxmE=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f h1:jydjrmVFvSllBOTppveOAkLITpOYKk0kma5z0bfDImI=
github.com/multiversx/mx-chain-crypto-go v1.2.12-0.20240725071000-c3212540166f/go.mod h1:9aSp//uBSvqFdzh4gvYISraoruhr1FCTXgPQalQ687k=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775 h1:a8LOfz3p4MQfRtbF00rGDAJiebziwtSfVmBHIaHBDdY=
github.com/multiversx/mx-chain-logger-go v1.0.15-0.20240725065747-176bd697c775/go.mod h1:owPYyrK7RcsLx9eOCAZQ22fIyW6BE7ttJr4XIhFIbQw=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6 h1:QGQjSlPix5nBtCkcdyKo0b2sRYXwYF/GBtccOqDbU6Y=
github.com/multiversx/mx-chain-scenario-go v1.4.4-0.20240725072925-89c927c8b6a6/go.mod h1:MvJiMtuyGq43aS9eOgF+xQUWk0hYxvCQqLrT77bhBaE=
github.com/multiversx/mx-chain-logger-go v1.0.15 h1:HlNdK8etyJyL9NQ+6mIXyKPEBo+wRqOwi3n+m2QIHXc=
github.com/multiversx/mx-chain-logger-go v1.0.15/go.mod h1:t3PRKaWB1M+i6gUfD27KXgzLJJC+mAQiN+FLlL1yoGQ=
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20240802080531-0906745c04b2 h1:7/4jvB5DBQqKL4udY4RjcwHZ7sRH20fXM3Nj830Rv84=
github.com/multiversx/mx-chain-scenario-go v1.4.5-0.20240802080531-0906745c04b2/go.mod h1:5lkUsHiCCX1rJOx0d763OIlD85y85xCYU0Zlzasq6OM=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf h1:L9K7Xzq5SZz6k55R7HrafiRcU+c8/PqozJxys65G4bI=
github.com/multiversx/mx-chain-storage-go v1.0.16-0.20240725070753-aa7fb322ebdf/go.mod h1:ptvW/8r6bam55mVpeVZbyvvvydYM0DQwcPOH0W4Xyx8=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087 h1:ovxs8X50iBL9TOkn0qHrkuXrBS1Y/EWfQOYmFEaXRNs=
github.com/multiversx/mx-chain-vm-common-go v1.5.13-0.20240725072715-8806f1301087/go.mod h1:nNGN+rdLRN8Nd6OhFGrkEZS5Ipj5IQCvFT0L/iQbOpU=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241021074004-c2bdb78da54a h1:+D5GR9SkHTkKU6fIMZLdSQHeIzbDzOT6fSJfKBG80+g=
github.com/multiversx/mx-chain-vm-common-go v1.5.17-0.20241021074004-c2bdb78da54a/go.mod h1:1rSkXreUZNXyPTTdhj47M+Fy62yjxbu3aAsXEtKN3UY=
github.com/multiversx/mx-components-big-int v1.0.0 h1:Wkr8lSzK2nDqixOrrBa47VNuqdhV1m/aJhaP1EMaiS8=
github.com/multiversx/mx-components-big-int v1.0.0/go.mod h1:maIEMgHlNE2u78JaDD0oLzri+ShgU4okHfzP3LWGdQM=
github.com/nxadm/tail v1.4.4/go.mod h1:kenIhsEOeOJmVchQTgglprH7qJGnHDVpk1VPCcaMI8A=
Expand Down
65 changes: 51 additions & 14 deletions mock/context/blockChainHookStub.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,25 @@ var _ vmcommon.BlockchainHook = (*BlockchainHookStub)(nil)

// BlockchainHookStub is used in tests to check that interface methods were called
type BlockchainHookStub struct {
NewAddressCalled func(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
GetStorageDataCalled func(accountsAddress []byte, index []byte) ([]byte, uint32, error)
GetBlockHashCalled func(nonce uint64) ([]byte, error)
LastNonceCalled func() uint64
LastRoundCalled func() uint64
LastTimeStampCalled func() uint64
LastRandomSeedCalled func() []byte
LastEpochCalled func() uint32
GetStateRootHashCalled func() []byte
CurrentNonceCalled func() uint64
CurrentRoundCalled func() uint64
CurrentTimeStampCalled func() uint64
CurrentRandomSeedCalled func() []byte
CurrentEpochCalled func() uint32
NewAddressCalled func(creatorAddress []byte, creatorNonce uint64, vmType []byte) ([]byte, error)
GetStorageDataCalled func(accountsAddress []byte, index []byte) ([]byte, uint32, error)
GetBlockHashCalled func(nonce uint64) ([]byte, error)
LastNonceCalled func() uint64
LastRoundCalled func() uint64
LastTimeStampCalled func() uint64
LastRandomSeedCalled func() []byte
LastEpochCalled func() uint32
GetStateRootHashCalled func() []byte
CurrentNonceCalled func() uint64
CurrentRoundCalled func() uint64
CurrentTimeStampCalled func() uint64
CurrentRandomSeedCalled func() []byte
CurrentEpochCalled func() uint32
RoundTimeCalled func() uint64
EpochStartBlockTimeStampCalled func() uint64
EpochStartBlockNonceCalled func() uint64
EpochStartBlockRoundCalled func() uint64

ProcessBuiltInFunctionCalled func(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error)
GetBuiltinFunctionNamesCalled func() vmcommon.FunctionNames
GetAllStateCalled func(address []byte) (map[string][]byte, error)
Expand Down Expand Up @@ -153,6 +158,38 @@ func (b *BlockchainHookStub) CurrentEpoch() uint32 {
return 0
}

// RoundTime mocked method
func (b *BlockchainHookStub) RoundTime() uint64 {
if b.RoundTimeCalled != nil {
return b.RoundTimeCalled()
}
return 0
}

// EpochStartBlockTimeStamp mocked method
func (b *BlockchainHookStub) EpochStartBlockTimeStamp() uint64 {
if b.EpochStartBlockTimeStampCalled != nil {
return b.EpochStartBlockTimeStampCalled()
}
return 0
}

// EpochStartBlockNonce mocked method
func (b *BlockchainHookStub) EpochStartBlockNonce() uint64 {
if b.EpochStartBlockNonceCalled != nil {
return b.EpochStartBlockNonceCalled()
}
return 0
}

// EpochStartBlockRound VMHooks implementation.
func (b *BlockchainHookStub) EpochStartBlockRound() uint64 {
if b.EpochStartBlockRoundCalled != nil {
return b.EpochStartBlockRoundCalled()
}
return 0
}

// ProcessBuiltInFunction mocked method
func (b *BlockchainHookStub) ProcessBuiltInFunction(input *vmcommon.ContractCallInput) (*vmcommon.VMOutput, error) {
if b.ProcessBuiltInFunctionCalled != nil {
Expand Down
4 changes: 4 additions & 0 deletions mock/context/executorMockFunc.go

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

8 changes: 8 additions & 0 deletions scenario/gasSchedules/gasScheduleEmbedGenerated.go

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

4 changes: 4 additions & 0 deletions scenario/gasSchedules/gasScheduleV3.toml
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@
GetCodeMetadata = 100
IsBuiltinFunction = 100
IsReservedFunctionName = 100
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
4 changes: 4 additions & 0 deletions scenario/gasSchedules/gasScheduleV4.toml
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,10 @@
GetCodeMetadata = 100
IsBuiltinFunction = 100
IsReservedFunctionName = 100
GetRoundTime = 10000
EpochStartBlockTimeStamp = 10000
EpochStartBlockNonce = 10000
EpochStartBlockRound = 10000

[EthAPICost]
UseGas = 100
Expand Down
2 changes: 2 additions & 0 deletions test/contracts/new-blockchain-hooks/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
build:
rustc --target wasm32-unknown-unknown -O --crate-type=cdylib src/lib.rs -o output/new-blockchain-hooks.wasm
Binary file not shown.
Loading
Loading