From 9355f523121ec3827f2b960e30b9263f80f36653 Mon Sep 17 00:00:00 2001 From: Uday Patil Date: Mon, 29 Jul 2024 16:33:01 -0500 Subject: [PATCH] Update excessBlobGas and BlobBaseFee to fix simulate evmcontext (#1782) * Update excessBlobGas and BlobBaseFee to fix simulate evmcontext * bump forge evm version * update CI --- .github/workflows/forge-test.yml | 4 ++-- contracts/hardhat.config.js | 3 ++- contracts/src/EVMCompatibilityTester.sol | 9 ++++++++- contracts/test/EVMCompatabilityTest.js | 25 +++++++++++++++--------- evmrpc/simulate.go | 12 +++++++----- x/evm/keeper/keeper.go | 2 +- 6 files changed, 36 insertions(+), 19 deletions(-) diff --git a/.github/workflows/forge-test.yml b/.github/workflows/forge-test.yml index f104ac3b51..d3ee848779 100644 --- a/.github/workflows/forge-test.yml +++ b/.github/workflows/forge-test.yml @@ -31,10 +31,10 @@ jobs: - name: Run Forge build run: | forge --version - forge build --sizes + forge build --sizes --evm-version=cancun id: build - name: Run Forge tests run: | - forge test -vvv + forge test -vvv --evm-version=cancun id: test diff --git a/contracts/hardhat.config.js b/contracts/hardhat.config.js index 9bf1ab2b58..3088f63202 100644 --- a/contracts/hardhat.config.js +++ b/contracts/hardhat.config.js @@ -5,8 +5,9 @@ require('@openzeppelin/hardhat-upgrades'); /** @type import('hardhat/config').HardhatUserConfig */ module.exports = { solidity: { - version: "0.8.20", + version: "0.8.25", settings: { + evmVersion: "cancun", optimizer: { enabled: true, runs: 1000, diff --git a/contracts/src/EVMCompatibilityTester.sol b/contracts/src/EVMCompatibilityTester.sol index 0331ffc9fc..6c2ef83852 100644 --- a/contracts/src/EVMCompatibilityTester.sol +++ b/contracts/src/EVMCompatibilityTester.sol @@ -1,5 +1,5 @@ // SPDX-License-Identifier: MIT -pragma solidity ^0.8.20; +pragma solidity ^0.8.25; import "@openzeppelin/contracts/token/ERC20/IERC20.sol"; import "@openzeppelin/contracts/token/ERC721/IERC721.sol"; @@ -173,5 +173,12 @@ contract EVMCompatibilityTester { bytesVar = value; emit BytesSet(msg.sender, value); } + + function getBlobBaseFee() public view returns (uint256 fee) { + assembly { + fee := blobbasefee() + } + return fee; + } } diff --git a/contracts/test/EVMCompatabilityTest.js b/contracts/test/EVMCompatabilityTest.js index a5f37c9a11..8ab8220ec6 100644 --- a/contracts/test/EVMCompatabilityTest.js +++ b/contracts/test/EVMCompatabilityTest.js @@ -5,6 +5,7 @@ const { ethers, upgrades } = require('hardhat'); const { getImplementationAddress } = require('@openzeppelin/upgrades-core'); const { deployEvmContract, setupSigners, fundAddress, getCosmosTx, getEvmTx} = require("./lib") const axios = require("axios"); +const { default: BigNumber } = require("bignumber.js"); function sleep(ms) { return new Promise(resolve => setTimeout(resolve, ms)); @@ -398,6 +399,12 @@ describe("EVM Test", function () { const retrievedAmount = await evmTester.readFromStorage(0); expect(retrievedAmount).to.equal(BigInt(testAmount)); }); + + it("Should work for BLOBBASEFEE opcode", async function () { + + const blobBaseFee = await evmTester.getBlobBaseFee(); + expect(blobBaseFee).to.deep.equal(BigInt(1)); + }); }) describe("Historical query test", function() { @@ -814,7 +821,7 @@ describe("EVM Test", function () { fromBlock: blockStart, toBlock: blockEnd, }; - + const logs = await ethers.provider.getLogs(filter); expect(logs).to.be.an('array'); expect(logs.length).to.equal(numTxs); @@ -826,7 +833,7 @@ describe("EVM Test", function () { toBlock: blockEnd, topics: [ethers.id("DummyEvent(string,bool,address,uint256,bytes)")] }; - + const logs = await ethers.provider.getLogs(filter); expect(logs).to.be.an('array'); expect(logs.length).to.equal(numTxs); @@ -839,7 +846,7 @@ describe("EVM Test", function () { toBlock: blockEnd, topics: [ethers.id("DummyEvent(string,bool,address,uint256,bytes)")] }; - + const logs = await ethers.provider.getLogs(filter); const blockHash = logs[0].blockHash; @@ -867,9 +874,9 @@ describe("EVM Test", function () { paddedOwnerAddr, ] }; - + const logs = await ethers.provider.getLogs(filter1); - + expect(logs).to.be.an('array'); expect(logs.length).to.equal(numTxs); @@ -885,7 +892,7 @@ describe("EVM Test", function () { }; const logs2 = await ethers.provider.getLogs(filter1); - + expect(logs2).to.be.an('array'); expect(logs2.length).to.equal(numTxs); }); @@ -901,7 +908,7 @@ describe("EVM Test", function () { "0x0000000000000000000000000000000000000000000000000000000000000003", ] }; - + const logs1 = await ethers.provider.getLogs(filter1); expect(logs1).to.be.an('array'); expect(logs1.length).to.equal(1); @@ -948,7 +955,7 @@ describe("EVM Test", function () { ethers.id("nonexistent event string"), ] }; - + const logs = await ethers.provider.getLogs(filter); expect(logs).to.be.an('array'); expect(logs.length).to.equal(0); @@ -1052,7 +1059,7 @@ describe("EVM Test", function () { value: usei, }); await txResponse.wait(); // Wait for the transaction to be mined - + // Check that the contract received the ETH const contractBalance = await ethers.provider.getBalance(evmAddr); expect(contractBalance - initialBalance).to.equal(usei); diff --git a/evmrpc/simulate.go b/evmrpc/simulate.go index 17ffa8a7cf..428ebc0ac5 100644 --- a/evmrpc/simulate.go +++ b/evmrpc/simulate.go @@ -410,12 +410,14 @@ func (b *Backend) getBlockHeight(ctx context.Context, blockNrOrHash rpc.BlockNum } func (b *Backend) getHeader(blockNumber *big.Int) *ethtypes.Header { + zeroExcessBlobGas := uint64(0) header := ðtypes.Header{ - Difficulty: common.Big0, - Number: blockNumber, - BaseFee: b.keeper.GetBaseFeePerGas(b.ctxProvider(LatestCtxHeight)).BigInt(), - GasLimit: b.config.GasCap, - Time: uint64(time.Now().Unix()), + Difficulty: common.Big0, + Number: blockNumber, + BaseFee: b.keeper.GetBaseFeePerGas(b.ctxProvider(LatestCtxHeight)).BigInt(), + GasLimit: b.config.GasCap, + Time: uint64(time.Now().Unix()), + ExcessBlobGas: &zeroExcessBlobGas, } number := blockNumber.Int64() block, err := blockByNumber(context.Background(), b.tmClient, &number) diff --git a/x/evm/keeper/keeper.go b/x/evm/keeper/keeper.go index 895baf7b51..889f1c1673 100644 --- a/x/evm/keeper/keeper.go +++ b/x/evm/keeper/keeper.go @@ -211,7 +211,7 @@ func (k *Keeper) GetVMBlockContext(ctx sdk.Context, gp core.GasPool) (*vm.BlockC Time: uint64(ctx.BlockHeader().Time.Unix()), Difficulty: utils.Big0, // only needed for PoW BaseFee: k.GetBaseFeePerGas(ctx).TruncateInt().BigInt(), // feemarket not enabled - BlobBaseFee: utils.Big0, // Cancun not enabled + BlobBaseFee: utils.Big1, // Cancun not enabled Random: &rh, }, nil }