Skip to content

Commit

Permalink
Merge branch 'main' into yiren/silent-encoding
Browse files Browse the repository at this point in the history
  • Loading branch information
blindchaser authored Oct 8, 2024
2 parents 434a5f6 + b9199c6 commit 46d6893
Show file tree
Hide file tree
Showing 39 changed files with 454 additions and 158 deletions.
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ Ref: https://keepachangelog.com/en/1.0.0/
-->

# Changelog
## v5.9.0
sei-chain
* [#1867](https://github.com/sei-protocol/sei-chain/pull/1867) Add synthetic events in separate sei endpoints
* [#1861](https://github.com/sei-protocol/sei-chain/pull/1861) Revert showing wasm txs in EVM RPCs
* [#1857](https://github.com/sei-protocol/sei-chain/pull/1857) Fix events in 2-hop scenarios
* [#1856](https://github.com/sei-protocol/sei-chain/pull/1856) Add delegatecall flag to properly detect delegatecalls
* [#1850](https://github.com/sei-protocol/sei-chain/pull/1853) Fix websocket from_height
* [#1849](https://github.com/sei-protocol/sei-chain/pull/1849) Reduce block bloom storage
* [#1844](https://github.com/sei-protocol/sei-chain/pull/1844) Allowlist for token extensions

sei-iavl
*[#41](https://github.com/sei-protocol/sei-iavl/pull/41) Fix tree versions causing slow restart and OOM
## v5.8.0
sei-chain
* [#1840](https://github.com/sei-protocol/sei-chain/pull/1840) Add migration for new params
Expand Down
4 changes: 2 additions & 2 deletions app/receipt.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ func (app *App) AddCosmosEventsToEVMReceiptIfApplicable(ctx sdk.Context, tx sdk.
return
}
logs := []*ethtypes.Log{}
wasmGasLimit := app.EvmKeeper.GetDeliverTxHookWasmGasLimit(ctx)
queryCtx := ctx.WithGasMeter(sdk.NewGasMeterWithMultiplier(ctx, wasmGasLimit))
// wasmGasLimit := app.EvmKeeper.GetDeliverTxHookWasmGasLimit(ctx)
queryCtx := ctx.WithGasMeter(sdk.NewInfiniteGasMeter(1, 1))
for _, wasmEvent := range wasmEvents {
contractAddr, found := GetAttributeValue(wasmEvent, wasmtypes.AttributeKeyContractAddr)
if !found {
Expand Down
1 change: 1 addition & 0 deletions app/upgrades.go
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@ var upgradesList = []string{
"v5.7.4",
"v5.7.5",
"v5.8.0",
"v5.9.0",
}

// if there is an override list, use that instead, for integration tests
Expand Down
52 changes: 36 additions & 16 deletions contracts/test/ERC20toCW20PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,16 @@ describe("ERC20 to CW20 Pointer", function () {
});

describe("transfer()", function () {
it("should transfer", async function () {
it.only("should transfer", async function () {
let sender = accounts[0];
let recipient = accounts[1];

expect(await pointer.balanceOf(sender.evmAddress)).to.equal(balances.account0);
expect(await pointer.balanceOf(recipient.evmAddress)).to.equal(balances.account1);

const blockNumber = await ethers.provider.getBlockNumber();
const tx = await pointer.transfer(recipient.evmAddress, 1);
await tx.wait();
const receipt = await tx.wait();
const blockNumber = receipt.blockNumber;

expect(await pointer.balanceOf(sender.evmAddress)).to.equal(balances.account0-1);
expect(await pointer.balanceOf(recipient.evmAddress)).to.equal(balances.account1+1);
Expand All @@ -107,18 +107,38 @@ describe("ERC20 to CW20 Pointer", function () {
address: await pointer.getAddress(),
topics: [ethers.id("Transfer(address,address,uint256)")]
};
// send via eth_ endpoint - synthetic event doesn't show up
// send via eth_ endpoint - synthetic event should show up because we are using the
// synthetic event in place of a real EVM event
const ethlogs = await ethers.provider.send('eth_getLogs', [filter]);
expect(ethlogs.length).to.equal(0);
expect(ethlogs.length).to.equal(1);

// send via sei_ endpoint - synthetic event shows up
const seilogs = await ethers.provider.send('sei_getLogs', [filter]);
expect(seilogs.length).to.equal(1);
expect(seilogs.length).to.equal(1);
expect(seilogs[0]["address"].toLowerCase()).to.equal((await pointer.getAddress()).toLowerCase());
expect(seilogs[0]["topics"][0]).to.equal(ethers.id("Transfer(address,address,uint256)"));
expect(seilogs[0]["topics"][1].substring(26)).to.equal(sender.evmAddress.substring(2).toLowerCase());
expect(seilogs[0]["topics"][2].substring(26)).to.equal(recipient.evmAddress.substring(2).toLowerCase());

const logs = [...ethlogs, ...seilogs];
logs.forEach(async (log) => {
expect(log["address"].toLowerCase()).to.equal((await pointer.getAddress()).toLowerCase());
expect(log["topics"][0]).to.equal(ethers.id("Transfer(address,address,uint256)"));
expect(log["topics"][1].substring(26)).to.equal(sender.evmAddress.substring(2).toLowerCase());
expect(log["topics"][2].substring(26)).to.equal(recipient.evmAddress.substring(2).toLowerCase());
});

const ethBlock = await ethers.provider.send('eth_getBlockByNumber', ['0x' + blockNumber.toString(16), false]);
const seiBlock = await ethers.provider.send('sei_getBlockByNumber', ['0x' + blockNumber.toString(16), false]);
expect(ethBlock.transactions.length).to.equal(1);
expect(seiBlock.transactions.length).to.equal(1);

const ethReceipts = await ethers.provider.send('eth_getBlockReceipts', ['0x' + blockNumber.toString(16)]);
const seiReceipts = await ethers.provider.send('sei_getBlockReceipts', ['0x' + blockNumber.toString(16)]);
expect(ethReceipts.length).to.equal(1);
expect(seiReceipts.length).to.equal(1);
expect(ethReceipts[0].transactionHash).to.equal(seiReceipts[0].transactionHash);

const ethTx = await ethers.provider.send('eth_getTransactionReceipt', [receipt.hash]);
expect(ethTx.logs.length).to.equal(1); // check for transfer event
const ethTxByHash = await ethers.provider.send('eth_getTransactionByHash', [tx.hash]);
expect(ethTxByHash).to.not.be.null;

const cleanupTx = await pointer.connect(recipient.signer).transfer(sender.evmAddress, 1);
await cleanupTx.wait();
Expand Down Expand Up @@ -147,7 +167,7 @@ describe("ERC20 to CW20 Pointer", function () {
const spender = accounts[1].evmAddress;
const blockNumber = await ethers.provider.getBlockNumber();
const tx = await pointer.approve(spender, 1000000);
await tx.wait();
const receipt = await tx.wait();
const allowance = await pointer.allowance(owner, spender);
expect(Number(allowance)).to.equal(1000000);

Expand All @@ -160,15 +180,15 @@ describe("ERC20 to CW20 Pointer", function () {
};
// send via eth_ endpoint - synthetic event doesn't show up
const ethlogs = await ethers.provider.send('eth_getLogs', [filter]);
expect(ethlogs.length).to.equal(0);
expect(ethlogs.length).to.equal(1);
expect(ethlogs[0]["address"].toLowerCase()).to.equal((await pointer.getAddress()).toLowerCase());
expect(ethlogs[0]["topics"][0]).to.equal(ethers.id("Approval(address,address,uint256)"));
expect(ethlogs[0]["topics"][1].substring(26)).to.equal(owner.substring(2).toLowerCase());
expect(ethlogs[0]["topics"][2].substring(26)).to.equal(spender.substring(2).toLowerCase());

// send via sei_ endpoint - synthetic event shows up
const seilogs = await ethers.provider.send('sei_getLogs', [filter]);
expect(seilogs.length).to.equal(1);
expect(seilogs[0]["address"].toLowerCase()).to.equal((await pointer.getAddress()).toLowerCase());
expect(seilogs[0]["topics"][0]).to.equal(ethers.id("Approval(address,address,uint256)"));
expect(seilogs[0]["topics"][1].substring(26)).to.equal(owner.substring(2).toLowerCase());
expect(seilogs[0]["topics"][2].substring(26)).to.equal(spender.substring(2).toLowerCase());
});

it("should lower approval", async function () {
Expand Down
45 changes: 32 additions & 13 deletions contracts/test/ERC721toCW721PointerTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,17 +94,22 @@ describe("ERC721 to CW721 Pointer", function () {
address: await pointerAcc1.getAddress(),
topics: [ethers.id("Approval(address,address,uint256)")]
};
// send via eth_ endpoint - synthetic event doesn't show up
// send via eth_ endpoint - synthetic event should show up because we are using the
// synthetic event in place of a real EVM event
const ethlogs = await ethers.provider.send('eth_getLogs', [filter]);
expect(ethlogs.length).to.equal(0);
expect(ethlogs.length).to.equal(1);

// send via sei_ endpoint - synthetic event shows up
const seilogs = await ethers.provider.send('sei_getLogs', [filter]);
expect(seilogs.length).to.equal(1);
expect(seilogs[0]["address"].toLowerCase()).to.equal((await pointerAcc1.getAddress()).toLowerCase());
expect(seilogs[0]["topics"][0]).to.equal(ethers.id("Approval(address,address,uint256)"));
expect(seilogs[0]["topics"][1].substring(26)).to.equal(accounts[0].evmAddress.substring(2).toLowerCase());
expect(seilogs[0]["topics"][2].substring(26)).to.equal(accounts[1].evmAddress.substring(2).toLowerCase());

const logs = [...ethlogs, ...seilogs];
logs.forEach(async (log) => {
expect(log["address"].toLowerCase()).to.equal((await pointer.getAddress()).toLowerCase());
expect(log["topics"][0]).to.equal(ethers.id("Transfer(address,address,uint256)"));
expect(log["topics"][1].substring(26)).to.equal(accounts[0].evmAddress.substring(2).toLowerCase());
expect(log["topics"][2].substring(26)).to.equal(accounts[1].evmAddress.substring(2).toLowerCase());
});
});

it("cannot approve token you don't own", async function () {
Expand All @@ -116,7 +121,7 @@ describe("ERC721 to CW721 Pointer", function () {
await mine(pointerAcc0.approve(accounts[1].evmAddress, 2));
const blockNumber = await ethers.provider.getBlockNumber();
transferTxResp = await pointerAcc1.transferFrom(accounts[0].evmAddress, accounts[1].evmAddress, 2);
await transferTxResp.wait();
const receipt = await transferTxResp.wait();
const filter = {
fromBlock: '0x' + blockNumber.toString(16),
toBlock: 'latest',
Expand All @@ -125,19 +130,33 @@ describe("ERC721 to CW721 Pointer", function () {
};
// send via eth_ endpoint - synthetic event doesn't show up
const ethlogs = await ethers.provider.send('eth_getLogs', [filter]);
expect(ethlogs.length).to.equal(0);

expect(ethlogs.length).to.equal(1);
const seilogs = await ethers.provider.send('sei_getLogs', [filter]);
expect(seilogs.length).to.equal(1);
expect(seilogs[0]["address"].toLowerCase()).to.equal((await pointerAcc1.getAddress()).toLowerCase());
expect(seilogs[0]["topics"][0]).to.equal(ethers.id("Transfer(address,address,uint256)"));
expect(seilogs[0]["topics"][1].substring(26)).to.equal(accounts[1].evmAddress.substring(2).toLowerCase());
expect(seilogs[0]["topics"][2].substring(26)).to.equal(accounts[1].evmAddress.substring(2).toLowerCase());
const logs = [...ethlogs, ...seilogs];
logs.forEach(async (log) => {
expect(log["address"].toLowerCase()).to.equal((await pointerAcc1.getAddress()).toLowerCase());
expect(log["topics"][0]).to.equal(ethers.id("Transfer(address,address,uint256)"));
expect(log["topics"][1].substring(26)).to.equal(accounts[1].evmAddress.substring(2).toLowerCase());
expect(log["topics"][2].substring(26)).to.equal(accounts[1].evmAddress.substring(2).toLowerCase());
});

const balance0 = await pointerAcc0.balanceOf(accounts[0].evmAddress);
expect(balance0).to.equal(0);
const balance1 = await pointerAcc0.balanceOf(accounts[1].evmAddress);
expect(balance1).to.equal(2);

// do same for eth_getBlockReceipts and sei_getBlockReceipts
const ethBlockReceipts = await ethers.provider.send('eth_getBlockReceipts', ['0x' + blockNumber.toString(16)]);
expect(ethBlockReceipts.length).to.equal(1);
const seiBlockReceipts = await ethers.provider.send('sei_getBlockReceipts', ['0x' + blockNumber.toString(16)]);
expect(seiBlockReceipts.length).to.equal(1);

const ethTx = await ethers.provider.send('eth_getTransactionReceipt', [receipt.hash]);
expect(ethTx.logs.length).to.equal(1);
const ethTxByHash = await ethers.provider.send('eth_getTransactionByHash', [receipt.hash]);
expect(ethTxByHash).to.not.be.null;

// return token id 2 back to accounts[0] using safe transfer from
await mine(pointerAcc1.approve(accounts[0].evmAddress, 2));
await mine(pointerAcc1.safeTransferFrom(accounts[1].evmAddress, accounts[0].evmAddress, 2));
Expand Down
8 changes: 4 additions & 4 deletions contracts/test/EVMCompatabilityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe("EVM Test", function () {
testToken = await TestToken.deploy("TestToken", "TTK");

const EVMCompatibilityTester = await ethers.getContractFactory("EVMCompatibilityTester");
evmTester = await EVMCompatibilityTester.deploy();
evmTester = await EVMCompatibilityTester.deploy({ gasPrice: ethers.parseUnits('100', 'gwei') });

await Promise.all([evmTester.waitForDeployment(), testToken.waitForDeployment()])

Expand Down Expand Up @@ -148,7 +148,7 @@ describe("EVM Test", function () {

await delay()
// Set balance
await testToken.setBalance(owner.address, setAmount);
await testToken.setBalance(owner.address, setAmount, { gasPrice: ethers.parseUnits('100', 'gwei') });

// Prepare call data for balanceOf function of MyToken
const balanceOfData = testToken.interface.encodeFunctionData("balanceOf", [owner.address]);
Expand All @@ -169,7 +169,7 @@ describe("EVM Test", function () {
describe("Msg Properties", function() {
it("Should store and retrieve msg properties correctly", async function() {
// Store msg properties
const txResponse = await evmTester.storeMsgProperties({ value: 1 });
const txResponse = await evmTester.storeMsgProperties({ value: 1, gasPrice: ethers.parseUnits('100', 'gwei') });
await txResponse.wait();

// Retrieve stored msg properties
Expand Down Expand Up @@ -1004,7 +1004,7 @@ describe("EVM Test", function () {

// increment value
debug("Incrementing value...")
const resp = await box.boxIncr();
const resp = await box.boxIncr({ gasPrice: ethers.parseUnits('100', 'gwei') });
await resp.wait();

// make sure value is incremented
Expand Down
29 changes: 18 additions & 11 deletions evmrpc/block.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"encoding/hex"
"errors"
"fmt"
"math"
"math/big"
"strings"
"sync"
Expand All @@ -26,18 +27,20 @@ import (
tmtypes "github.com/tendermint/tendermint/types"
)

const ShellEVMTxType = math.MaxUint32

type BlockAPI struct {
tmClient rpcclient.Client
keeper *keeper.Keeper
ctxProvider func(int64) sdk.Context
txConfig client.TxConfig
connectionType ConnectionType
namespace string
includeSyntheticTxs bool
tmClient rpcclient.Client
keeper *keeper.Keeper
ctxProvider func(int64) sdk.Context
txConfig client.TxConfig
connectionType ConnectionType
namespace string
includeShellReceipts bool
}

func NewBlockAPI(tmClient rpcclient.Client, k *keeper.Keeper, ctxProvider func(int64) sdk.Context, txConfig client.TxConfig, connectionType ConnectionType, namespace string) *BlockAPI {
return &BlockAPI{tmClient: tmClient, keeper: k, ctxProvider: ctxProvider, txConfig: txConfig, connectionType: connectionType, includeSyntheticTxs: shouldIncludeSynthetic(namespace)}
return &BlockAPI{tmClient: tmClient, keeper: k, ctxProvider: ctxProvider, txConfig: txConfig, connectionType: connectionType, includeShellReceipts: shouldIncludeSynthetic(namespace)}
}

func (a *BlockAPI) GetBlockTransactionCountByNumber(ctx context.Context, number rpc.BlockNumber) (result *hexutil.Uint, returnErr error) {
Expand Down Expand Up @@ -80,7 +83,7 @@ func (a *BlockAPI) getBlockByHash(ctx context.Context, blockHash common.Hash, fu
return nil, err
}
blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height))
return EncodeTmBlock(a.ctxProvider(block.Block.Height), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx, a.includeSyntheticTxs)
return EncodeTmBlock(a.ctxProvider(block.Block.Height), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx, a.includeShellReceipts)
}

func (a *BlockAPI) GetBlockByNumber(ctx context.Context, number rpc.BlockNumber, fullTx bool) (result map[string]interface{}, returnErr error) {
Expand Down Expand Up @@ -128,7 +131,7 @@ func (a *BlockAPI) getBlockByNumber(ctx context.Context, number rpc.BlockNumber,
return nil, err
}
blockBloom := a.keeper.GetBlockBloom(a.ctxProvider(block.Block.Height))
return EncodeTmBlock(a.ctxProvider(block.Block.Height), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx, a.includeSyntheticTxs)
return EncodeTmBlock(a.ctxProvider(block.Block.Height), block, blockRes, blockBloom, a.keeper, a.txConfig.TxDecoder(), fullTx, a.includeShellReceipts)
}

func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.BlockNumberOrHash) (result []map[string]interface{}, returnErr error) {
Expand Down Expand Up @@ -169,7 +172,8 @@ func (a *BlockAPI) GetBlockReceipts(ctx context.Context, blockNrOrHash rpc.Block
mtx.Unlock()
}
} else {
if !a.includeSyntheticTxs && len(receipt.Logs) > 0 && receipt.Logs[0].Synthetic {
// If the receipt has synthetic logs, we actually want to include them in the response.
if !a.includeShellReceipts && receipt.TxType == ShellEVMTxType {
return
}
encodedReceipt, err := encodeReceipt(receipt, a.txConfig.TxDecoder(), block, func(h common.Hash) bool {
Expand Down Expand Up @@ -242,6 +246,9 @@ func EncodeTmBlock(
if err != nil {
continue
}
if !includeSyntheticTxs && receipt.TxType == ShellEVMTxType {
continue
}
newTx := ethapi.NewRPCTransaction(ethtx, blockhash, number.Uint64(), uint64(blockTime.Second()), uint64(receipt.TransactionIndex), baseFeePerGas, chainConfig)
transactions = append(transactions, newTx)
}
Expand Down
Loading

0 comments on commit 46d6893

Please sign in to comment.