Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[frontier] Add support for PoV gas refunding #3036

Merged
merged 12 commits into from
Nov 27, 2024
53 changes: 27 additions & 26 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions test/suites/dev/moonbase/test-fees/test-length-fees2.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,9 @@ describeSuite({
const base_ethereum_fee = 21000n;
const modexp_min_cost = 200n * 20n; // see MIN_GAS_COST in frontier's modexp precompile
const entire_fee = non_zero_byte_fee + zero_byte_fee + base_ethereum_fee + modexp_min_cost;
// the gas used should be the maximum of the legacy gas and the pov gas
const expected = BigInt(Math.max(Number(entire_fee), 3797 * GAS_LIMIT_POV_RATIO));
// Given that the pov is refunded, the gas used should be the minimum of the legacy gas
// and the pov gas.
const expected = BigInt(Math.min(Number(entire_fee), 3797 * GAS_LIMIT_POV_RATIO));
expect(receipt.gasUsed, "gasUsed does not match manual calculation").toBe(expected);
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ describeSuite({
.getTransactionReceipt({ hash: result!.hash as `0x${string}` });

expect(receipt.status).to.equal("reverted");
// 21006 = call cost + 2*PUSH cost
expect(receipt.gasUsed).to.equal(21006n);
// 31088 = call cost + 2*PUSH cost
expect(receipt.gasUsed).to.equal(31088n);
},
});
},
Expand Down
21 changes: 11 additions & 10 deletions test/suites/dev/moonbase/test-precompile/test-precompile-modexp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ describeSuite({
id: "T03",
title: "EIP example 1 - gas",
test: async function () {
const expectedModExpGasCost = 1360n;
const expectedModExpGasCost = 9156n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000001" + // base length
"0000000000000000000000000000000000000000000000000000000000000020" + // exponent length
Expand All @@ -89,6 +89,7 @@ describeSuite({
.viem()
.getTransactionReceipt({ hash: result!.hash as `0x${string}` });
expect(receipt.status).toBe("success");

const modExpGas =
receipt.gasUsed - BigInt(numNonZeroBytes) * 16n - BigInt(numZeroBytes) * 4n - 21000n;
expect(modExpGas, "ModExp gas pricing mismatch").to.equal(expectedModExpGasCost);
Expand Down Expand Up @@ -125,7 +126,7 @@ describeSuite({
id: "T05",
title: "EIP example 2 - gas",
test: async function () {
const expectedModExpGasCost = 1360n;
const expectedModExpGasCost = 8656n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000000" + // base length
"0000000000000000000000000000000000000000000000000000000000000020" + // exponent length
Expand Down Expand Up @@ -158,7 +159,7 @@ describeSuite({
id: "T06",
title: "nagydani-1-square - gas",
test: async function () {
const expectedModExpGasCost = 200n;
const expectedModExpGasCost = 7604n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000040" + // base length
"0000000000000000000000000000000000000000000000000000000000000001" + // exponent length
Expand Down Expand Up @@ -193,7 +194,7 @@ describeSuite({
id: "T07",
title: "nagydani-1-qube - gas",
test: async function () {
const expectedModExpGasCost = 200n;
const expectedModExpGasCost = 7604n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000040" + // base length
"0000000000000000000000000000000000000000000000000000000000000001" + // exponent length
Expand Down Expand Up @@ -227,7 +228,7 @@ describeSuite({
id: "T08",
title: "nagydani-1-pow0x10001 - gas",
test: async function () {
const expectedModExpGasCost = 341n;
const expectedModExpGasCost = 7584n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000040" + // base length
"0000000000000000000000000000000000000000000000000000000000000003" + // exponent length
Expand Down Expand Up @@ -261,7 +262,7 @@ describeSuite({
id: "T09",
title: "nagydani-2-square - gas",
test: async function () {
const expectedModExpGasCost = 200n;
const expectedModExpGasCost = 5592n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000080" + // base length
"0000000000000000000000000000000000000000000000000000000000000001" + // exponent length
Expand Down Expand Up @@ -295,7 +296,7 @@ describeSuite({
id: "T10",
title: "nagydani-2-qube - gas",
test: async function () {
const expectedModExpGasCost = 200n;
const expectedModExpGasCost = 5592n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000080" + // base length
"0000000000000000000000000000000000000000000000000000000000000001" + // exponent length
Expand Down Expand Up @@ -329,7 +330,7 @@ describeSuite({
id: "T11",
title: "nagydani-2-pow0x10001 - gas",
test: async function () {
const expectedModExpGasCost = 1365n;
const expectedModExpGasCost = 5572n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000080" + // base length
"0000000000000000000000000000000000000000000000000000000000000003" + // exponent length
Expand Down Expand Up @@ -363,7 +364,7 @@ describeSuite({
id: "T12",
title: "nagydani-3-square - gas",
test: async function () {
const expectedModExpGasCost = 341n;
const expectedModExpGasCost = 1472n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000100" + // base length
"0000000000000000000000000000000000000000000000000000000000000001" + // exponent length
Expand Down Expand Up @@ -397,7 +398,7 @@ describeSuite({
id: "T13",
title: "nagydani-3-qube - gas",
test: async function () {
const expectedModExpGasCost = 341n;
const expectedModExpGasCost = 1472n;
const inputData =
"0000000000000000000000000000000000000000000000000000000000000100" + // base length
"0000000000000000000000000000000000000000000000000000000000000001" + // exponent length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,9 @@ describeSuite({
// Storage growth ratio is 366
// storage_gas = 148 * 366 = 54168
// pov_gas = 5693 * 16 = 91088
const expectedGas = 91_088n;
// Given that the remaining pov_gas is now refunded, the effective gas is
// the storage_gas = 54168.
const expectedGas = 54_168n;
const rawTxn = await context.writePrecompile!({
precompileName: "Proxy",
functionName: "addProxy",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ describeSuite({
fulFillReceipt = await context
.viem()
.getTransactionReceipt({ hash: result![1].hash as `0x${string}` });
expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`280576n`);
expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`153712n`);
});

it({
Expand Down Expand Up @@ -175,11 +175,11 @@ describeSuite({
).to.be.true;
expect(
(await context.polkadotJs().query.system.account(charleth.address)).data.free.toBigInt() >
DEFAULT_GENESIS_BALANCE
DEFAULT_GENESIS_BALANCE
).to.be.false;
expect(
(await context.polkadotJs().query.system.account(dorothy.address)).data.free.toBigInt() >
DEFAULT_GENESIS_BALANCE
DEFAULT_GENESIS_BALANCE
).to.be.true;
},
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ describeSuite({
.viem()
.getTransactionReceipt({ hash: result!.hash as `0x${string}` });

expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`280576n`);
expect(fulFillReceipt.gasUsed).toMatchInlineSnapshot(`159248n`);
});
it({
id: "T01",
Expand Down
Loading
Loading