From fa7d2a14d2d869ea64e86c925c6fb5c4f1d756c0 Mon Sep 17 00:00:00 2001 From: Steven Landers Date: Tue, 23 Jan 2024 16:26:54 -0500 Subject: [PATCH] [EVM] Add index to logs based on order (#1273) * add index to logs based on order * add check for getLogs * add log conversion test --- contracts/src/EVMCompatibilityTester.sol | 7 ++ contracts/test/EVMCompatabilityTester.js | 35 ++++++- proto/evm/receipt.proto | 1 + x/evm/keeper/log.go | 3 +- x/evm/keeper/log_test.go | 83 +++++++++++++++++ x/evm/state/log.go | 1 + x/evm/types/receipt.pb.go | 112 +++++++++++++++-------- 7 files changed, 199 insertions(+), 43 deletions(-) create mode 100644 x/evm/keeper/log_test.go diff --git a/contracts/src/EVMCompatibilityTester.sol b/contracts/src/EVMCompatibilityTester.sol index d0e5d77471..4b1e36309f 100644 --- a/contracts/src/EVMCompatibilityTester.sol +++ b/contracts/src/EVMCompatibilityTester.sol @@ -12,6 +12,7 @@ contract EVMCompatibilityTester { event AddressSet(address indexed performer); event Uint256Set(address indexed performer, uint256 value); event StringSet(address indexed performer, string value); + event LogIndexEvent(address indexed performer, uint256 value); struct MsgDetails { address sender; @@ -62,6 +63,12 @@ contract EVMCompatibilityTester { emit BoolSet(msg.sender, value); } + function emitMultipleLogs(uint256 count) public { + for (uint256 i = 0; i < count; i++) { + emit LogIndexEvent(msg.sender, i); + } + } + function setStringVar(string memory value) public { stringVar = value; emit StringSet(msg.sender, value); diff --git a/contracts/test/EVMCompatabilityTester.js b/contracts/test/EVMCompatabilityTester.js index 76b560f53a..5d581b7a8a 100644 --- a/contracts/test/EVMCompatabilityTester.js +++ b/contracts/test/EVMCompatabilityTester.js @@ -428,7 +428,7 @@ describe("EVM Test", function () { }); describe("Differing maxPriorityFeePerGas and maxFeePerGas", async function() { - testCases.forEach(async ([name, maxPriorityFeePerGas, maxFeePerGas]) => { + for (const [name, maxPriorityFeePerGas, maxFeePerGas] of testCases) { it(`EIP-1559 test: ${name}`, async function() { console.log(`maxPriorityFeePerGas = ${maxPriorityFeePerGas}`) console.log(`maxFeePerGas = ${maxFeePerGas}`) @@ -458,12 +458,12 @@ describe("EVM Test", function () { console.log(`tip = ${tip}`) const effectiveGasPrice = tip + gasPrice; console.log(`effectiveGasPrice = ${effectiveGasPrice}`) - + const diff = balanceBefore - balanceAfter; console.log(`diff = ${diff}`) expect(diff).to.equal(21000 * effectiveGasPrice); }); - }); + } }); }); }); @@ -560,14 +560,41 @@ describe("EVM Test", function () { expect(nonce).to.be.a('number'); }); + it("Should set log index correctly", async function () { + const blockNumber = await ethers.provider.getBlockNumber(); + const numberOfEvents = 5; + + // check receipt + const txResponse = await evmTester.emitMultipleLogs(numberOfEvents); + const receipt = await txResponse.wait(); + expect(receipt.logs.length).to.equal(numberOfEvents) + for(let i=0; i 0 { i -= len(m.Data) copy(dAtA[i:], m.Data) @@ -471,6 +485,9 @@ func (m *Log) Size() (n int) { if l > 0 { n += 1 + l + sovReceipt(uint64(l)) } + if m.Index != 0 { + n += 1 + sovReceipt(uint64(m.Index)) + } return n } @@ -667,6 +684,25 @@ func (m *Log) Unmarshal(dAtA []byte) error { m.Data = []byte{} } iNdEx = postIndex + case 4: + if wireType != 0 { + return fmt.Errorf("proto: wrong wireType = %d for field Index", wireType) + } + m.Index = 0 + for shift := uint(0); ; shift += 7 { + if shift >= 64 { + return ErrIntOverflowReceipt + } + if iNdEx >= l { + return io.ErrUnexpectedEOF + } + b := dAtA[iNdEx] + iNdEx++ + m.Index |= uint32(b&0x7F) << shift + if b < 0x80 { + break + } + } default: iNdEx = preIndex skippy, err := skipReceipt(dAtA[iNdEx:])