8000 chore(werc20): Add wrapper ERC20 precompile by Vvaradinov · Pull Request #2943 · evmos/evmos · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

chore(werc20): Add wrapper ERC20 precompile #2943

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

Merged
merged 75 commits into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
75 commits
Select commit Hold shift + click to select a range
bc03ba5
chore: re-add werc20 boilerplate
Vvaradinov Oct 15, 2024
2ff8215
run make format
Vvaradinov Oct 15, 2024
60007f2
CHANGELOG
Vvaradinov Oct 15, 2024
1366276
Merge remote-tracking branch 'origin/Vvaradinov/re-add-werc20' into V…
Vvaradinov Oct 15, 2024
11daa7f
Merge branch 'main' into Vvaradinov/re-add-werc20
Vvaradinov Oct 21, 2024
c17dd50
address comments from code review
Vvaradinov Oct 21, 2024
e60f93d
Merge remote-tracking branch 'origin/Vvaradinov/re-add-werc20' into V…
Vvaradinov Oct 21, 2024
af01cc8
fix: use the getEvmCoinDenom method
Vvaradinov Oct 21, 2024
437d1eb
Merge branch 'main' into Vvaradinov/re-add-werc20
Vvaradinov Oct 24, 2024
8e0b254
Merge branch 'main' into Vvaradinov/re-add-werc20
fedekunze Oct 28, 2024
da0bd72
add events + refactor docstring
0xstepit Oct 29, 2024
dcd7529
wire event emission
0xstepit Oct 29, 2024
8377b4a
add WEVMOS.sol
0xstepit Oct 29, 2024
631bf0a
remove unused WEVMOS files from contracts/
0xstepit Oct 29, 2024
0f87fdc
add solidity compiler to hardhat config
0xstepit Oct 29, 2024
b1a1806
add WEVMOS9 contract to werc20 precompile
0xstepit Oct 29, 2024
57d2c2c
add chainID selector for WEVMOS address
0xstepit Oct 30, 2024
343e176
make bank keeper public in erc20 precompile
0xstepit Oct 31, 2024
ff9776e
move werc20 to native precompiles
0xstepit Oct 31, 2024
5878066
make iwerc20 child of erc20
0xstepit Oct 31, 2024
64624ba
add integration and event tests
0xstepit Oct 31, 2024
b3a2edd
test suite support testnet config for erc20
0xstepit Nov 1, 2024
0a0af5b
add event tests
0xstepit Nov 1, 2024
937dd93
fix pointer error
0xstepit Nov 1, 2024
4fc23b4
small refactor tests
0xstepit Nov 1, 2024
69f98f3
Merge branch 'main' into Vvaradinov/re-add-werc20
0xstepit Nov 1, 2024
c0a4f20
remove unused file
0xstepit Nov 1, 2024
18b2e30
add license
0xstepit Nov 1, 2024
2e28d43
add tests for erc20 methods
0xstepit Nov 1, 2024
2b5296b
update test suite to register native metadata
0xstepit Nov 4, 2024
3789e5a
Merge branch 'main' into Vvaradinov/re-add-werc20
0xstepit Nov 4, 2024
659b2c0
refactor suite setup
0xstepit Nov 4, 2024
1532e75
update compiles for solidity tests
0xstepit Nov 4, 2024
4a48af7
add changelog
0xstepit Nov 4, 2024
3d71dc7
make changelog linter happy
0xstepit Nov 4, 2024
6e9f95e
fix integration tests
0xstepit Nov 5, 2024
00f385e
remove unused wevmos contract var
0xstepit Nov 5, 2024
3e31dd8
add comments
0xstepit Nov 5, 2024
8a141a3
refactor integration testsuite
0xstepit Nov 5, 2024
5c6c0b7
add balance check in withdraw plus tests
0xstepit Nov 5, 2024
2356a06
change IsTransaction signature
0xstepit Nov 5, 2024
7565fbe
adding print to investigate behavior
0xstepit Nov 7, 2024
ae48d42
remove testing logs
0xstepit Nov 8, 2024
e1fe2da
minor refactoring of docs
0xstepit Nov 8, 2024
bf74c71
Merge branch 'main' into Vvaradinov/re-add-werc20
0xstepit Nov 8, 2024
614b12c
fix test
ramacarlucho Nov 8, 2024
318fe36
add reverter test
ramacarlucho Nov 8, 2024
0ac1bc0
fix docs
ramacarlucho Nov 8, 2024
fa0a230
add err check in test
0xstepit Nov 8, 2024
ccc6497
Merge branch 'main' into Vvaradinov/re-add-werc20
0xstepit Nov 8, 2024
146abda
refactor test to remove pointer
0xstepit Nov 8, 2024
fe18ce4
Merge branch 'main' into Vvaradinov/re-add-werc20
0xstepit Nov 8, 2024
f1c0954
delete print
ramacarlucho Nov 8, 2024
a019ef8
lint
0xstepit Nov 8, 2024
61f2110
fix tests
ramacarlucho Nov 8, 2024
9cc8820
lint
ramacarlucho Nov 8, 2024
0ab1eaa
lint js
ramacarlucho Nov 8, 2024
12e1ade
Revert "lint js"
ramacarlucho Nov 8, 2024
986adb1
disable javascript standard
ramacarlucho Nov 8, 2024
4bf3b25
fix lint
ramacarlucho Nov 8, 2024
7fb3e18
lint
ramacarlucho Nov 8, 2024
46dd518
Merge branch 'main' into Vvaradinov/re-add-werc20
0xstepit Nov 11, 2024
b899bc4
remove redundant 18 dec conversion
0xstepit Nov 11, 2024
d9c1cb4
Merge branch 'main' into Vvaradinov/re-add-werc20
ramacarlucho Nov 11, 2024
e3e4aaf
Update x/erc20/types/params.go
0xstepit Nov 11, 2024
cf1748c
Update x/erc20/keeper/precompiles.go
0xstepit Nov 11, 2024
9e0608b
Update x/erc20/types/params.go
0xstepit Nov 11, 2024
fbef089
Update x/evm/core/vm/contracts.go
0xstepit Nov 11, 2024
76473cc
Update x/evm/keeper/static_precompiles.go
0xstepit Nov 11, 2024
0015ec6
Update x/evm/keeper/static_precompiles.go
0xstepit Nov 11, 2024
bb5c4fa
update from code review
0xstepit Nov 11, 2024
2503da8
Update x/erc20/keeper/precompiles.go
0xstepit Nov 12, 2024
2c9febd
Update x/erc20/keeper/precompiles.go
0xstepit Nov 12, 2024
9f5d77d
fix state db update balance
0xstepit Nov 12, 2024
f8ceeb3
fix changelog from other pr
0xstepit Nov 12, 2024
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 .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ jobs:
PROTOBUF_CONFIG_FILE: .protolint.yml
VALIDATE_NATURAL_LANGUAGE: false
VALIDATE_OPENAPI: false
VALIDATE_JAVASCRIPT_STANDARD: false
VALIDATE_JSCPD: false
VALIDATE_GO: false
VALIDATE_GO_MODULES: false
Expand Down
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,8 @@ Ref: https://keepachangelog.com/en/1.0.0/
- (evm) [#2936](https://github.com/evmos/evmos/pull/2936) Add query for EVM config.
- (app) [#2937](https://github.com/evmos/evmos/pull/2937) Fix conversion on the `CheckTxFee` ante handler and allow zero coins refunds.
- (deps) [#2967](https://github.com/evmos/evmos/pull/2967) Bump CometBFT to `v0.38.15`.
- (precompiles) [#2966](https://github.com/evmos/evmos/pull/2966) Add safety check that ERC20 precompiles cannot receive funds.
- (precompiles) [#2943](https://github.com/evmos/evmos/pull/2943) Add WERC-20 precompile.
- (precompiles) [#2966](https://github.com/evmos/evmos/pull/2966) Add safety check that ERC-20 precompiles cannot receive funds.

### Bug Fixes

Expand Down
4 changes: 0 additions & 4 deletions contracts/compiled_contracts/WEVMOS.json

This file was deleted.

18 changes: 14 additions & 4 deletions contracts/hardhat.config.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
/** @type import('hardhat/config').HardhatUserConfig */
module.exports = {
solidity: '0.8.20',
solidity: {
compilers: [
{
version: "0.8.20",
},
// This version is required to compile the werc9 contract.
{
version: "0.4.22",
},
],
},
paths: {
sources: './solidity'
}
}
sources: "./solidity",
},
};
30 changes: 0 additions & 30 deletions contracts/wevmos.go

This file was deleted.

3 changes: 2 additions & 1 deletion precompiles/bank/bank.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (

storetypes "cosmossdk.io/store/types"
bankkeeper "github.com/cosmos/cosmos-sdk/x/bank/keeper"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
cmn "github.com/evmos/evmos/v20/precompiles/common"
erc20keeper "github.com/evmos/evmos/v20/x/erc20/keeper"
Expand Down Expand Up @@ -143,6 +144,6 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [

// IsTransaction checks if the given method name corresponds to a transaction or query.
// It returns false since all bank methods are queries.
func (Precompile) IsTransaction(_ string) bool {
func (Precompile) IsTransaction(_ *abi.Method) bool {
return false
}
4 changes: 2 additions & 2 deletions precompiles/common/precompile.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func (p Precompile) RunSetup(
evm *vm.EVM,
contract *vm.Contract,
readOnly bool,
isTransaction func(name string) bool,
isTransaction func(name *abi.Method) bool,
) (ctx sdk.Context, stateDB *statedb.StateDB, s snapshot, method *abi.Method, gasConfig storetypes.Gas, args []interface{}, err error) { //nolint:revive
stateDB, ok := evm.StateDB.(*statedb.StateDB)
if !ok {
Expand Down Expand Up @@ -125,7 +125,7 @@ func (p Precompile) RunSetup(
}

// return error if trying to write to state during a read-only call
if readOnly && isTransaction(method.Name) {
if readOnly && isTransaction(method) {
return sdk.Context{}, nil, s, nil, uint64(0), nil, vm.ErrWriteProtection
}

Expand Down
7 changes: 4 additions & 3 deletions precompiles/distribution/distribution.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import (
storetypes "cosmossdk.io/store/types"
authzkeeper "github.com/cosmos/cosmos-sdk/x/authz/keeper"
distributionkeeper "github.com/cosmos/cosmos-sdk/x/distribution/keeper"
"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
cmn "github.com/evmos/evmos/v20/precompiles/common"
"github.com/evmos/evmos/v20/x/evm/core/vm"
Expand Down Expand Up @@ -76,7 +77,7 @@ func (p Precompile) RequiredGas(input []byte) uint64 {
return 0
}

return p.Precompile.RequiredGas(input, p.IsTransaction(method.Name))
return p.Precompile.RequiredGas(input, p.IsTransaction(method))
}

// Run executes the precompiled contract distribution methods defined in the ABI.
Expand Down Expand Up @@ -146,8 +147,8 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
// - SetWithdrawAddress
// - WithdrawDelegatorRewards
// - WithdrawValidatorCommission
func (Precompile) IsTransaction(methodName string) bool {
switch methodName {
func (Precompile) IsTransaction(method *abi.Method) bool {
switch method.Name {
case ClaimRewardsMethod,
SetWithdrawAddressMethod,
WithdrawDelegatorRewardsMethod,
Expand Down
17 changes: 9 additions & 8 deletions precompiles/distribution/distribution_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
sdk "github.com/cosmos/cosmos-sdk/types"
"github.com/cosmos/cosmos-sdk/x/distribution/types"

"github.com/ethereum/go-ethereum/accounts/abi"
"github.com/ethereum/go-ethereum/common"
gethtypes "github.com/ethereum/go-ethereum/core/types"
"github.com/evmos/evmos/v20/app"
Expand All @@ -18,44 +19,44 @@ import (
func (s *PrecompileTestSuite) TestIsTransaction() {
testCases := []struct {
name string
method string
method abi.Method
isTx bool
}{
{
distribution.SetWithdrawAddressMethod,
s.precompile.Methods[distribution.SetWithdrawAddressMethod].Name,
s.precompile.Methods[distribution.SetWithdrawAddressMethod],
true,
},
{
distribution.WithdrawDelegatorRewardsMethod,
s.precompile.Methods[distribution.WithdrawDelegatorRewardsMethod].Name,
s.precompile.Methods[distribution.WithdrawDelegatorRewardsMethod],
true,
},
{
distribution.WithdrawValidatorCommissionMethod,
s.precompile.Methods[distribution.WithdrawValidatorCommissionMethod].Name,
s.precompile.Methods[distribution.WithdrawValidatorCommissionMethod],
true,
},
{
distribution.FundCommunityPoolMethod,
s.precompile.Methods[distribution.FundCommunityPoolMethod].Name,
s.precompile.Methods[distribution.FundCommunityPoolMethod],
true,
},
{
distribution.ValidatorDistributionInfoMethod,
s.precompile.Methods[distribution.ValidatorDistributionInfoMethod].Name,
s.precompile.Methods[distribution.ValidatorDistributionInfoMethod],
false,
},
{
"invalid",
"invalid",
abi.Method{},
false,
},
}

for _, tc := range testCases {
s.Run(tc.name, func() {
s.Require().Equal(s.precompile.IsTransaction(tc.method), tc.isTx)
s.Require().Equal(s.precompile.IsTransaction(&tc.method), tc.isTx)
})
}
}
Expand Down
9 changes: 5 additions & 4 deletions precompiles/erc20/erc20.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ var _ vm.PrecompiledContract = &Precompile{}
type Precompile struct {
cmn.Precompile
tokenPair erc20types.TokenPair
bankKeeper bankkeeper.Keeper
transferKeeper transferkeeper.Keeper
// BankKeeper is a public field so that the werc20 precompile can use it.
BankKeeper bankkeeper.Keeper
}

// NewPrecompile creates a new ERC-20 Precompile instance as a
Expand All @@ -74,7 +75,7 @@ func NewPrecompile(
TransientKVGasConfig: storetypes.GasConfig{},
},
tokenPair: tokenPair,
bankKeeper: bankKeeper,
BankKeeper: bankKeeper,
transferKeeper: transferKeeper,
}
// Address defines the address of the ERC-20 precompile contract.
Expand Down Expand Up @@ -164,8 +165,8 @@ func (p Precompile) Run(evm *vm.EVM, contract *vm.Contract, readOnly bool) (bz [
}

// IsTransaction checks if the given method name corresponds to a transaction or query.
func (Precompile) IsTransaction(methodName string) bool {
switch methodName {
func (Precompile) IsTransaction(method *abi.Method) bool {
switch method.Name {
case TransferMethod,
TransferFromMethod,
auth.ApproveMethod,
Expand Down
Loading
Loading
0