Skip to content

Commit

Permalink
Merge pull request #61 from oraichain/fix/go-ethereum-wrong-delegatec…
Browse files Browse the repository at this point in the history
…aller

Fix/go ethereum wrong delegatecaller
  • Loading branch information
ducphamle2 authored Sep 20, 2024
2 parents 6a1ea12 + f9d6bfa commit 20723b1
Show file tree
Hide file tree
Showing 7 changed files with 56 additions and 35 deletions.
4 changes: 2 additions & 2 deletions app/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,8 @@ func NewOraichainApp(logger log.Logger, db dbm.DB, traceStore io.Writer, loadLat
app.ScopedInterTxKeeper = scopedInterTxKeeper
clockkeeper.RegisterProposalTypes()

// register wasm keeper
registry.InitializePrecompiles(app.ContractKeeper, app.WasmKeeper, app.EvmKeeper)
// register precompile keepers
registry.InitializePrecompiles(app.ContractKeeper, app.WasmKeeper, app.EvmKeeper, app.BankKeeper, app.AccountKeeper)

return app
}
Expand Down
6 changes: 3 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,12 @@ replace (
// backport iavl and go-ethereum to matching version with cosmos sdk & kava v0.14.0-kava-v21.1
github.com/cosmos/iavl => github.com/cosmos/iavl v0.19.5
// use go-ethereum with precompile
github.com/ethereum/go-ethereum => github.com/Kava-Labs/go-ethereum v1.10.27-0.20240308184817-2a5324cb7ce7
github.com/ethereum/go-ethereum => github.com/oraichain/go-ethereum v0.0.0-20240919025041-184f816b9d65

github.com/gogo/protobuf => github.com/regen-network/protobuf v1.3.3-alpha.regen.1

// use kava fork to change evm denom & cosmos denom of evmutil module to aorai and orai
github.com/kava-labs/kava => github.com/oraichain/kava v0.21.2-0.20240917014428-85b3d5030452
github.com/kava-labs/kava => github.com/oraichain/kava v0.21.2-0.20240920010755-522762952e53
// downgrade of goleveldb to avoid issues: see https://github.com/cosmos/cosmos-sdk/issues/14949
github.com/syndtr/goleveldb => github.com/syndtr/goleveldb v1.0.1-0.20210819022825-2ae1ddf74ef7

Expand All @@ -232,7 +232,7 @@ replace (
// Use ethermint fork that respects min-gas-price with NoBaseFee true and london enabled, and includes eip712 support
// also add params query, fix proto account & ibc v3 to v4 compatibility, and get first 4 bytes of sha256(chain_id) when not eip159 compatible
// also add evm & cosmos mapping
github.com/tharsis/ethermint => github.com/oraichain/ethermint v0.14.1-0.20240918011717-15939233e177
github.com/tharsis/ethermint => github.com/oraichain/ethermint v0.14.1-0.20240918072557-f5263be1acb3

google.golang.org/grpc => google.golang.org/grpc v1.33.2
)
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ github.com/DataDog/datadog-go v3.2.0+incompatible/go.mod h1:LButxg5PwREeZtORoXG3
github.com/DataDog/zstd v1.5.2 h1:vUG4lAyuPCXO0TLbXvPv7EB7cNK1QV/luu55UHLrrn8=
github.com/DataDog/zstd v1.5.2/go.mod h1:g4AWEaM3yOg3HYfnJ3YIawPnVdXJh9QME85blwSAmyw=
github.com/Joker/hpp v1.0.0/go.mod h1:8x5n+M1Hp5hC0g8okX3sR3vFQwynaX/UgSOM9MeBKzY=
github.com/Kava-Labs/go-ethereum v1.10.27-0.20240308184817-2a5324cb7ce7 h1:upwbx4E9Bt1YdlTmfSpPvPNPFT1x4vcwc+E1bho7FH8=
github.com/Kava-Labs/go-ethereum v1.10.27-0.20240308184817-2a5324cb7ce7/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo=
github.com/Knetic/govaluate v3.0.1-0.20171022003610-9aa49832a739+incompatible/go.mod h1:r7JcOSlj0wfOMncg0iLm8Leh48TZaKVeNIfJntJ2wa0=
github.com/Microsoft/go-winio v0.6.0 h1:slsWYD/zyx7lCXoZVlvQrj0hPTM1HI4+v1sIda2yDvg=
github.com/Microsoft/go-winio v0.6.0/go.mod h1:cTAf44im0RAYeL23bpB+fzCyDH2MJiz2BO69KH/soAE=
Expand Down Expand Up @@ -733,12 +731,14 @@ github.com/oraichain/cometbft v0.34.30-0.20240822152340-79f7b8278984 h1:6bnkvlyG
github.com/oraichain/cometbft v0.34.30-0.20240822152340-79f7b8278984/go.mod h1:L9shMfbkZ8B+7JlwANEr+NZbBcn+hBpwdbeYvA5rLCw=
github.com/oraichain/cosmos-sdk v0.45.17-0.20240822154747-4cc2e82d6f68 h1:zXer3jRPWbrC9jl7w2cEx4nCY19QWKNRdQ7l8xF7/+U=
github.com/oraichain/cosmos-sdk v0.45.17-0.20240822154747-4cc2e82d6f68/go.mod h1:bScuNwWAP0TZJpUf+SHXRU3xGoUPp+X9nAzfeIXts40=
github.com/oraichain/ethermint v0.14.1-0.20240918011717-15939233e177 h1:3OPZfUijDGWzLJEQJ8c7L82pVJrP7w2vzfwkvo44d3k=
github.com/oraichain/ethermint v0.14.1-0.20240918011717-15939233e177/go.mod h1:cTuxZmV5H31kxB1lIYTSSTX4zIxioQQvVuU6yZR/ZZs=
github.com/oraichain/ethermint v0.14.1-0.20240918072557-f5263be1acb3 h1:21lLXI+p0tpdKrijfK4HEox/uk+UjL42AoHicpb8GDM=
github.com/oraichain/ethermint v0.14.1-0.20240918072557-f5263be1acb3/go.mod h1:cTuxZmV5H31kxB1lIYTSSTX4zIxioQQvVuU6yZR/ZZs=
github.com/oraichain/go-ethereum v0.0.0-20240919025041-184f816b9d65 h1:oumbt8qiUC1AAt9MgHHnn/deseV5oYdg3T/PoYqsGeM=
github.com/oraichain/go-ethereum v0.0.0-20240919025041-184f816b9d65/go.mod h1:/6CsT5Ceen2WPLI/oCA3xMcZ5sWMF/D46SjM/ayY0Oo=
github.com/oraichain/juno/v15 v15.0.0-20240917111319-f17c267a5c95 h1:Pz+0Jg+Dd2v9IZyFT6P9CDFN1QQdlaJbTANA7es31Fo=
github.com/oraichain/juno/v15 v15.0.0-20240917111319-f17c267a5c95/go.mod h1:HuWFy53h3l7DzKXkFOYY/V8Eb4cXG1tekL/HlSqlPmM=
github.com/oraichain/kava v0.21.2-0.20240917014428-85b3d5030452 h1:oexXEkpJubHO7MGQsnpqB7iQTFvEwh+yD5d1j7M/mgc=
github.com/oraichain/kava v0.21.2-0.20240917014428-85b3d5030452/go.mod h1:rzsEf+BEcXxRpOoJCUMZUFFRy49/3g0uEpyckxOFe5I=
github.com/oraichain/kava v0.21.2-0.20240920010755-522762952e53 h1:19qEVoSALPjgqy1dWiWsrHbe7HEP27WVbSUrPMMXqkw=
github.com/oraichain/kava v0.21.2-0.20240920010755-522762952e53/go.mod h1:NNialHtI4NsaUBtRbW3lcXARLYRAfyOJgKoSdQMm6do=
github.com/oraichain/wasmd v0.30.2-0.20240729102409-91ec1f5fdc6c h1:M9XoVJ0EgBPBfuNUMxXGpa5AitznA27m59J0j651opk=
github.com/oraichain/wasmd v0.30.2-0.20240729102409-91ec1f5fdc6c/go.mod h1:DUWz5+p7h3BbDxXAt7IBovagwt5NRPCGVuQkweIixzM=
github.com/oraichain/wasmvm v1.5.2 h1:hN5Pa4EPlRb0BYKkNh2cgixd0+L6kPpzc+s30Il2W/Q=
Expand Down
6 changes: 1 addition & 5 deletions scripts/e2e-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,8 @@ if ! [[ $evm_denom =~ "aorai" ]] ; then
echo "Tests Failed"; exit 1
fi

sh $PWD/scripts/test_clock_counter_contract.sh
# sh $PWD/scripts/test_clock_counter_contract.sh

test gasless
NODE_HOME=$VALIDATOR_HOME USER=validator1 WASM_PATH="$PWD/scripts/wasm_file/counter_high_gas_cost.wasm" sh $PWD/scripts/tests-0.42.1/test-gasless.sh
NODE_HOME=$VALIDATOR_HOME USER=validator1 sh $PWD/scripts/tests-0.42.1/test-tokenfactory.sh
NODE_HOME=$VALIDATOR_HOME USER=validator1 sh $PWD/scripts/tests-0.42.1/test-tokenfactory-bindings.sh
Expand All @@ -50,7 +49,4 @@ NODE_HOME=$VALIDATOR_HOME sh $PWD/scripts/tests-0.42.3/test-commit-timeout.sh
NODE_HOME=$VALIDATOR_HOME sh $PWD/scripts/tests-0.42.4/test-cw-stargate-staking-query.sh
NODE_HOME=$VALIDATOR_HOME USER=validator1 sh $PWD/scripts/tests-0.42.4/test-cw20-erc20.sh

# cleanup
rm -rf ../../erc20-deploy/

echo "Tests Passed!!"
3 changes: 0 additions & 3 deletions scripts/e2e-upgrade.sh
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,4 @@ NODE_HOME=$VALIDATOR_HOME sh $PWD/scripts/tests-0.42.3/test-commit-timeout.sh
NODE_HOME=$VALIDATOR_HOME sh $PWD/scripts/tests-0.42.4/test-cw-stargate-staking-query.sh
NODE_HOME=$VALIDATOR_HOME USER=validator1 sh $PWD/scripts/tests-0.42.4/test-cw20-erc20.sh

# cleanup
rm -rf ../../erc20-deploy/

echo "Tests Passed!!"
16 changes: 10 additions & 6 deletions scripts/test-erc20-deploy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,15 @@ PRIVATE_KEY_ETH=${PRIVATE_KEY_ETH:-"021646C7F742C743E60CC460C56242738A3951667E71
# run erc20 tests
current_dir=$PWD

# clone repo
rm -rf ../../erc20-deploy/ && git clone https://github.com/oraichain/evm-bridge-proxy.git ../../erc20-deploy
cd ../../erc20-deploy
# clone or pull latest repo
if [ -d "$PWD/../evm-bridge-proxy" ]; then
cd ../evm-bridge-proxy
git pull origin master
yarn
else
git clone https://github.com/oraichain/evm-bridge-proxy.git ../evm-bridge-proxy
cd ../evm-bridge-proxy
fi

# prepare env and chain
yarn && yarn compile;
Expand All @@ -26,9 +32,7 @@ echo "ERC20 contract addr: $contract_addr"
# validate
contract_addr_len=${#contract_addr}
if [ $contract_addr_len -ne 42 ] ; then
echo "ERC20 Test Failed";
# clean up
rm -rf ../../erc20-deploy/ && exit 1
echo "ERC20 Test Failed"; exit 1
fi

echo "ERC20 Test Passed"; cd $current_dir
44 changes: 34 additions & 10 deletions scripts/tests-0.42.4/test-cw20-erc20.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ set -eu

# hard-coded test private key. DO NOT USE!!
PRIVATE_KEY_ETH=${PRIVATE_KEY_ETH:-"021646C7F742C743E60CC460C56242738A3951667E71C803929CB84B6FA4B0D6"}
PRIVATE_KEY_EVM_ADDRESS=${PRIVATE_KEY_EVM_ADDRESS:-"0xB0ac9d216b303a32907632731a93356228CAEE87"}
current_dir=$PWD
WASM_PATH=${WASM_PATH:-"$PWD/scripts/wasm_file/oraiswap-token.wasm"}
ARGS="--chain-id testing -y --keyring-backend test --gas auto --gas-adjustment 1.5 -b sync"
Expand All @@ -20,16 +21,23 @@ store_txhash=$(echo $store_ret | jq -r '.txhash')
sleep 2
code_id=$(oraid query tx $store_txhash --output json | jq -r '.logs[0].events[1].attributes[1].value | tonumber')

INSTANTIATE_MSG='{"name":"OraichainToken","symbol":"ORAI","decimals":6,"initial_balances":[]}'
# 2 addresses that map with the hard-coded private key above
INSTANTIATE_MSG='{"name":"OraichainToken","symbol":"ORAI","decimals":6,"initial_balances":[{"amount":"1000000000","address":"orai1kzkf6gttxqar9yrkxfe34ye4vg5v4m588ew7c9"},{"amount":"1000000000","address":"orai1hgscrqcd2kmju4t5akujeugwrfev7uxv66lnuu"}]}'
oraid tx wasm instantiate $code_id $INSTANTIATE_MSG --label 'cw20 ORAI' $VALIDATOR1_ARGS --admin $(oraid keys show validator1 --keyring-backend test --home $HOME/.oraid/validator1 -a) $ARGS > $HIDE_LOGS
# need to sleep 1s for tx already in block
sleep 2
contract_address=$(oraid query wasm list-contract-by-code $code_id --output json | jq -r '.contracts | last')
echo "cw-stargate-staking-query contract address: $contract_address"

# clone repo
# git clone https://github.com/oraichain/evm-bridge-proxy.git ../../erc20-deploy
cd ../../erc20-deploy
# clone or pull latest repo
if [ -d "$PWD/../evm-bridge-proxy" ]; then
cd ../evm-bridge-proxy
git pull origin master
else
git clone https://github.com/oraichain/evm-bridge-proxy.git ../evm-bridge-proxy
cd ../evm-bridge-proxy
fi


# prepare env and chain
yarn && yarn compile;
Expand All @@ -48,14 +56,30 @@ echo "ERC20 contract addr: $contract_addr"
# validate
contract_addr_len=${#contract_addr}
if [ $contract_addr_len -ne 42 ] ; then
echo "CW20-ERC20 Test Failed";
echo "Couldn't deploy ERC20 contract. CW20-ERC20 Test Failed";
fi

# try querying decimals -> get decimals from cosmwasm contract
output=$(ERC20_ADDRESS=$contract_addr yarn hardhat run scripts/cw20erc20-query-decimals.ts --network testing)
decimals=$(echo "$output" | awk '/^[0-9]+$/ { print $1 }')
if [ $decimals -ne 6 ] ; then
echo "CW20-ERC20 Test Failed";
# try querying balance of owner -> get balance of from cosmwasm contract
output=$(ERC20_ADDRESS=$contract_addr yarn hardhat run scripts/cw20erc20-query-balance-of.ts --network testing)
balance_of=$(echo "$output" | awk '/^[0-9]+$/ { print $1 }')
if ! [ $balance_of == "1000000000" ] ; then
echo "Could not query balance of CW20ERC20 address. CW20-ERC20 Test Failed"; exit 1
fi

# try querying decimals -> get decimals from cosmwasm contract
orai_balance_before_transfer=$(oraid query bank balances orai1kzkf6gttxqar9yrkxfe34ye4vg5v4m588ew7c9 --denom orai --output json | jq '.amount')
ERC20_ADDRESS=$contract_addr yarn hardhat run scripts/cw20erc20-transfer.ts --network testing
orai_balance_after_transfer=$(oraid query bank balances orai1kzkf6gttxqar9yrkxfe34ye4vg5v4m588ew7c9 --denom orai --output json | jq '.amount')

# try querying balance of owner after transfer -> should drop
output=$(ERC20_ADDRESS=$contract_addr yarn hardhat run scripts/cw20erc20-query-balance-of.ts --network testing)
balance_of=$(echo "$output" | awk '/^[0-9]+$/ { print $1 }')
if [ $balance_of == "1000000000" ] ; then
echo "Could not transfer CW20 token from ERC20 contract. CW20-ERC20 Test Failed"; exit 1
fi

if [ $orai_balance_before_transfer == $orai_balance_after_transfer ] ; then
echo "Could not transfer native ORAI token from ERC20 contract. CW20-ERC20 Test Failed"; exit 1
fi

echo "CW20-ERC20 Test Passed"; cd $current_dir

0 comments on commit 20723b1

Please sign in to comment.