Skip to content

Commit

Permalink
Merge pull request #27 from Kava-Labs/precompile-manager
Browse files Browse the repository at this point in the history
Injecting enabled precompiles list to EVM
  • Loading branch information
evgeniy-scherbina authored Apr 29, 2024
2 parents 031b717 + 23ac221 commit fef649a
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 149 deletions.
2 changes: 1 addition & 1 deletion Dockerfile.dev
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
FROM golang:1.20-alpine
FROM golang:1.21-alpine

RUN apk add bash make curl

Expand Down
80 changes: 52 additions & 28 deletions build/checksums.txt
Original file line number Diff line number Diff line change
Expand Up @@ -22,35 +22,59 @@ e2bc0b3e4b64111ec117295c088bde5f00eeed1567999ff77bc859d7df70078e go1.21.5.linux
bbe603cde7c9dee658f45164b4d06de1eff6e6e6b800100824e7c00d56a9a92f go1.21.5.windows-amd64.zip
9b7acca50e674294e43202df4fbc26d5af4d8bc3170a3342a1514f09a2dab5e9 go1.21.5.windows-arm64.zip

# version:golangci 1.51.1
# version:golangci 1.57.2
# https://github.com/golangci/golangci-lint/releases/
# https://github.com/golangci/golangci-lint/releases/download/v1.51.1/
fba08acc4027f69f07cef48fbff70b8a7ecdfaa1c2aba9ad3fb31d60d9f5d4bc golangci-lint-1.51.1-darwin-amd64.tar.gz
75b8f0ff3a4e68147156be4161a49d4576f1be37a0b506473f8c482140c1e7f2 golangci-lint-1.51.1-darwin-arm64.tar.gz
e06b3459aaed356e1667580be00b05f41f3b2e29685d12cdee571c23e1edb414 golangci-lint-1.51.1-freebsd-386.tar.gz
623ce2d0fa4d35cc2e8d69fa7334227ab592380962a13b4d9cdc77cf41db2008 golangci-lint-1.51.1-freebsd-amd64.tar.gz
131365feb0584cc2736c43192fa673ca50e5b6b765456990cb379ecfb787e568 golangci-lint-1.51.1-freebsd-armv6.tar.gz
98fb627927cbb654f5bf85dcffc5f646666b2ce96ea0fed977c9fb28abd51532 golangci-lint-1.51.1-freebsd-armv7.tar.gz
b36a99702fa762c15840261bc0fb41b4b1b16b8b19b8c0941bae98c85bb0f8b8 golangci-lint-1.51.1-linux-386.tar.gz
17aeb26c76820c22efa0e1838b0ab93e90cfedef43fbfc9a2f33f27eb9e5e070 golangci-lint-1.51.1-linux-amd64.tar.gz
9744bc34e7b8d82ca788b667bfb7155a39b4be9aef43bf9f10318b1372cea338 golangci-lint-1.51.1-linux-arm64.tar.gz
0dda8dbeb2ff7455a044ec8e347f2fc6d655d2e99d281b3b95e88167031c673d golangci-lint-1.51.1-linux-armv6.tar.gz
0512f311b11d43b8b22989d929f0fe8a2e1e5ebe497f1eb0ff73a0fc3d188fd1 golangci-lint-1.51.1-linux-armv7.tar.gz
d767108dcf84a8eaa844df3454cb0f75a492f4e7102ecc2b0a3545cfe073a566 golangci-lint-1.51.1-linux-loong64.tar.gz
3bd56c54daec16585b2668e0dfabb27af2c2b38cc0fdb46923e2521e1634846b golangci-lint-1.51.1-linux-mips64.tar.gz
f72f5adfa2219e15d2414c9a2966f86e74556cf17a85c727a7fb7770a16cf814 golangci-lint-1.51.1-linux-mips64le.tar.gz
e605521dac98096d8737e1997c954f41f1d0d8275b8731f62783d410c23574b9 golangci-lint-1.51.1-linux-ppc64le.tar.gz
2f683217b814339e74d61ca700922d8407f15addd6d4c5e8b156fbab79f26a87 golangci-lint-1.51.1-linux-riscv64.tar.gz
d98528292b65971a3594e5880530e7624597dc9806fcfccdfbe39be411713d63 golangci-lint-1.51.1-linux-s390x.tar.gz
9bb2d0fe9e692ed0aea4f2537e3e6862b2f6768fe2849a84f4a6ad09da9fd971 golangci-lint-1.51.1-netbsd-386.tar.gz
34cafdcd11ae73ae88d66c33eb8449f5c976fc3e37b44774dbe9c71caa95e592 golangci-lint-1.51.1-netbsd-amd64.tar.gz
f8b4e1e47ac17caafe8a5f32f975a2b6a7cb14c27c0f73c1fb15c20ca91c2e03 golangci-lint-1.51.1-netbsd-armv6.tar.gz
c4f58b7e227b9fd41f0e9310dc83f4a4e7d026598e2f6e95b78761081a6d9bd2 golangci-lint-1.51.1-netbsd-armv7.tar.gz
6710e2f5375dc75521c1a17980a6cbbe6ff76c2f8b852964a8af558899a97cf5 golangci-lint-1.51.1-windows-386.zip
722d7b87b9cdda0a3835d5030b3fc5385c2eba4c107f63f6391cfb2ac35f051d golangci-lint-1.51.1-windows-amd64.zip
eb57f9bcb56646f2e3d6ccaf02ec227815fb05077b2e0b1bf9e755805acdc2b9 golangci-lint-1.51.1-windows-arm64.zip
bce02f7232723cb727755ee11f168a700a00896a25d37f87c4b173bce55596b4 golangci-lint-1.51.1-windows-armv6.zip
cf6403f84707ce8c98664736772271bc8874f2e760c2fd0f00cf3e85963507e9 golangci-lint-1.51.1-windows-armv7.zip
# https://github.com/golangci/golangci-lint/releases/download/v1.57.2/
83157f5378d259d51c88e310e88513bd80bd42e497974a1bbe51b82931f229c7 golangci-lint-1.57.2-darwin-amd64.tar.gz
0d6f10544fc0b5bd94b9eeb20d89646b9c19b52a98dca1ca62f94c08ac641b98 golangci-lint-1.57.2-darwin-arm64.tar.gz
4b8e83d91e05b968c33d861cd4c917533d648560e84fe30464a1e7a8aac93e49 golangci-lint-1.57.2-freebsd-386.tar.gz
eff30d840518a24f429565d7a52ebf1ac2c0c4c1680968d581b2c7116c1dc835 golangci-lint-1.57.2-freebsd-amd64.tar.gz
6ee437fc8913aafef9b8f09dd5766037ecdd13cd75cf581a0e38b61dabe82bc7 golangci-lint-1.57.2-freebsd-armv6.tar.gz
045359345ec63b81ab269391731d22739dbc6fba0fcf4adce7a214538f33118f golangci-lint-1.57.2-freebsd-armv7.tar.gz
4885b856a380717ae79edf00aa81fbbc337948fddc33bc80dada49ed5e4d85db golangci-lint-1.57.2-illumos-amd64.tar.gz
4b874eca42cd186735aae9a3f4af1b476997819ab2abec16aec0d8a52aa258da golangci-lint-1.57.2-linux-386.deb
43ca7476fa18dbadc8cb7d4827a81a96cf5799e8ad0b60d734d23367e3f84a9d golangci-lint-1.57.2-linux-386.rpm
51694b9b9da783f70fb4060403cd476f7e77509bbbfeda222994a0ec3c43a8f8 golangci-lint-1.57.2-linux-386.tar.gz
a7b811e93c4fe6be45f862806ec121b38dbe36b81f877a6bd3f728baabce1c06 golangci-lint-1.57.2-linux-amd64.deb
4639fc82a8baad59efffbc1e7f4048b7e5e2d580d70017a0c39aaddd0c669a13 golangci-lint-1.57.2-linux-amd64.rpm
391483daa5d58d037832ba2fac709fdb5df0c67471c0d7698d1f67cbfa5f10f0 golangci-lint-1.57.2-linux-amd64.tar.gz
80deed46f7354eec109808a48fbde7232578baf52530fcf2e2f708a0daca1bd0 golangci-lint-1.57.2-linux-arm64.deb
36d61363268a3ceeae7467e34887b36813467d426123962b4e6655f502c02fe6 golangci-lint-1.57.2-linux-arm64.rpm
9e079e19b3d81e357d2acc90518c6a86a533e26a74af1e5eadf8dfcd640b66ee golangci-lint-1.57.2-linux-arm64.tar.gz
c71a28a34084826d556ada999b759f1c7016da1d293f9db3e6e6d0ed00004aea golangci-lint-1.57.2-linux-armv6.deb
ee6a61d8fd49fcf0f75263640dbfeee4b3ff0bb39e1247ba2ae3601ae8006f6c golangci-lint-1.57.2-linux-armv6.rpm
0a22ab5885803dda31f285581cdf281efe773da0be9b7ea316be416e30c012dc golangci-lint-1.57.2-linux-armv6.tar.gz
62942bf5d9acb4ad9e461be606e8ce433d0b58b2bbc61d55d6c434d927513557 golangci-lint-1.57.2-linux-armv7.deb
f2498cf873f8e92e4469516696549490b99c92649eba634d3e693ed75252e85f golangci-lint-1.57.2-linux-armv7.rpm
c1d99d122e4ec1c087f6eab1f8776b6406e284882977c57b806470207c1b85f6 golangci-lint-1.57.2-linux-armv7.tar.gz
ac21b7903ac421f7ebb62a71a110d77874ab813878bcda5ce34f2d8642aed90a golangci-lint-1.57.2-linux-loong64.deb
5dba8379a25c183c5e3524af9d5cd4a684ee305bb7173fe337f048604ed88888 golangci-lint-1.57.2-linux-loong64.rpm
bc2b63bf57ab5398e84352df24e3088791f974d53fcd9fb683955146430de3cc golangci-lint-1.57.2-linux-loong64.tar.gz
66973457d9b0b3251d76b455b3f2d64895f655d4d602ed66c285227509768b37 golangci-lint-1.57.2-linux-mips64.deb
6b3a0b987c1d207de2689bdb86cb21e74e7ddffff954a9882141018609c2431c golangci-lint-1.57.2-linux-mips64.rpm
12a386657b3eace4d6a2bae1bd0ca1c58e0098bdd0e621296b37fcfb9b4c91bb golangci-lint-1.57.2-linux-mips64.tar.gz
2dbcd6918abf2da190ec5f3fcbfde81a42f4685f0e1f7a6758abfad3010d7646 golangci-lint-1.57.2-linux-mips64le.deb
9489933a329ce30a54b230cc6d90d7b9b409c6f2905af99747bed7c9115edb8c golangci-lint-1.57.2-linux-mips64le.rpm
d813cc9d5688f8170f8695d6468cf5b4995b401ee8270834d5fc333f5e2cce05 golangci-lint-1.57.2-linux-mips64le.tar.gz
da8f59eb18eb478f9b782d2a844674d827fc31b92df0cae581d99b69d5a26226 golangci-lint-1.57.2-linux-ppc64le.deb
b371a14c364978bfb71b86c1a3e5e951dbb5b4ab9ee14a184fadb024a59cd490 golangci-lint-1.57.2-linux-ppc64le.rpm
36084ebd725fb046e1c956f823b2c57b49781f41df0592501cfb5eb5d315b6c5 golangci-lint-1.57.2-linux-ppc64le.tar.gz
73936770432d10f7a5aefa86049382bc554f07cae035e79d515d754c77bdd3d5 golangci-lint-1.57.2-linux-riscv64.deb
4f4407bb197e1fd6db04187aaf2671faf94dc1764822248fefbedf025691705c golangci-lint-1.57.2-linux-riscv64.rpm
240b6b406d21d24a3041927aa39094c8d2fc2c7c6723e295b7f2d9d59c6e245b golangci-lint-1.57.2-linux-riscv64.tar.gz
486887715432f177fb1b795f9656e3338a18400a3b63f9e0c0ca9aae7ce91182 golangci-lint-1.57.2-linux-s390x.deb
8af126c8319d59dc3892a67df5ae10a51afef8fe5724906e8e340122384355a6 golangci-lint-1.57.2-linux-s390x.rpm
aede4a55e49f46d50c1ea6d21a093834faea33e80ab9c641833b29f53a030695 golangci-lint-1.57.2-linux-s390x.tar.gz
b47561dd99d8fc5aadffc629196f753a37f7eb33fa88d1f869e576cfe0c78b6f golangci-lint-1.57.2-netbsd-386.tar.gz
f19bb6886f7e47539f4d06844e4ba9be8af4ae3aff7b7118e7f0ac0b7c0fb34b golangci-lint-1.57.2-netbsd-amd64.tar.gz
65d3c14d46d205f3d1b2159b153ae93ee4a455a490605eda0935fb2ec8929f1a golangci-lint-1.57.2-netbsd-armv6.tar.gz
f975b1910afae5166598254319c2eb6231143a7cb63816df1bc193bdac3451a2 golangci-lint-1.57.2-netbsd-armv7.tar.gz
621326544b0fec6d4a7569bc504850dc7bf33b011ecef34ae6c292a5b24acd02 golangci-lint-1.57.2-source.tar.gz
95321b1ec07db22e29538d0b18d36a376ca7d834c4826351db2b73436d27f7c1 golangci-lint-1.57.2-windows-386.zip
10c1ab7eb4a99f8b292a8f910bc78a50e9547a4ffe7444fcddc68f722adf6612 golangci-lint-1.57.2-windows-amd64.zip
f88ac03faa185da6547beab8a91983db2767e2e154323518f592f7e24772ca9e golangci-lint-1.57.2-windows-arm64.zip
1c2c738d241be1091cebf119d38758d51d56b5a02bbe410979545e51dc39cf70 golangci-lint-1.57.2-windows-armv6.zip
88acd5987fb883ac56c46a78d804595ab5fb26be9b0b253bfb397d7838df3f78 golangci-lint-1.57.2-windows-armv7.zip

# This is the builder on PPA that will build Go itself (inception-y), don't modify!
#
Expand Down
81 changes: 0 additions & 81 deletions contracts/test/sum3.ts

This file was deleted.

32 changes: 24 additions & 8 deletions core/vm/evm.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package vm

import (
"math/big"
"slices"
"sync/atomic"

"github.com/ethereum/go-ethereum/common"
Expand Down Expand Up @@ -54,13 +55,16 @@ func (evm *EVM) precompile(addr common.Address) (contract.StatefulPrecompiledCon
precompiles = PrecompiledContractsHomestead
}

// Check the existing precompiles first
// Check the native stateless precompiles first
p, ok := precompiles[addr]
if ok {
return p, true
}

// Otherwise, check for the additionally configured precompiles.
// Otherwise, check for the additionally configured stateful precompiles
if !evm.isStatefulPrecompileEnabled(addr) {
return nil, false
}
module, ok := modules.GetPrecompileModuleByAddress(addr)
if !ok {
return nil, false
Expand All @@ -69,6 +73,11 @@ func (evm *EVM) precompile(addr common.Address) (contract.StatefulPrecompiledCon
return module.Contract, true
}

// isStatefulPrecompileEnabled checks if stateful precompile is enabled at current block height
func (evm *EVM) isStatefulPrecompileEnabled(addr common.Address) bool {
return slices.Contains(evm.enabledPrecompiles, addr)
}

// BlockContext provides the EVM with auxiliary information. Once provided
// it shouldn't be modified.
type BlockContext struct {
Expand Down Expand Up @@ -135,11 +144,17 @@ type EVM struct {
// available gas is calculated in gasCall* according to the 63/64 rule and later
// applied in opCall*.
callGasTemp uint64

enabledPrecompiles []common.Address
}

// NewEVM returns a new EVM. The returned EVM is not thread safe and should
// only ever be used *once*.
func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config) *EVM {
return NewEVMWithEnabledPrecompiles(blockCtx, txCtx, statedb, chainConfig, config, nil)
}

func NewEVMWithEnabledPrecompiles(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig *params.ChainConfig, config Config, enabledPrecompiles []common.Address) *EVM {
// If basefee tracking is disabled (eth_call, eth_estimateGas, etc), and no
// gas prices were specified, lower the basefee to 0 to avoid breaking EVM
// invariants (basefee < feecap)
Expand All @@ -152,12 +167,13 @@ func NewEVM(blockCtx BlockContext, txCtx TxContext, statedb StateDB, chainConfig
}
}
evm := &EVM{
Context: blockCtx,
TxContext: txCtx,
StateDB: statedb,
Config: config,
chainConfig: chainConfig,
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),
Context: blockCtx,
TxContext: txCtx,
StateDB: statedb,
Config: config,
chainConfig: chainConfig,
chainRules: chainConfig.Rules(blockCtx.BlockNumber, blockCtx.Random != nil, blockCtx.Time),
enabledPrecompiles: enabledPrecompiles,
}
evm.interpreter = NewEVMInterpreter(evm)
return evm
Expand Down
Loading

0 comments on commit fef649a

Please sign in to comment.