Skip to content

Commit

Permalink
Update excessBlobGas and BlobBaseFee to fix simulate evmcontext (sei-…
Browse files Browse the repository at this point in the history
…protocol#1782)

* Update excessBlobGas and BlobBaseFee to fix simulate evmcontext

* bump forge evm version

* update CI
  • Loading branch information
udpatil authored Jul 29, 2024
1 parent 42a2964 commit 9355f52
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/forge-test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion contracts/hardhat.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
9 changes: 8 additions & 1 deletion contracts/src/EVMCompatibilityTester.sol
Original file line number Diff line number Diff line change
@@ -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";
Expand Down Expand Up @@ -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;
}
}

25 changes: 16 additions & 9 deletions contracts/test/EVMCompatabilityTest.js
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand Down Expand Up @@ -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() {
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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;

Expand Down Expand Up @@ -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);

Expand All @@ -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);
});
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 7 additions & 5 deletions evmrpc/simulate.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 := &ethtypes.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)
Expand Down
2 changes: 1 addition & 1 deletion x/evm/keeper/keeper.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down

0 comments on commit 9355f52

Please sign in to comment.