From 0c2e9806988f51b0fe26576d3ad089fa05b6f867 Mon Sep 17 00:00:00 2001 From: Jawad Tariq Date: Fri, 4 Aug 2023 17:09:15 -0400 Subject: [PATCH] chore: fix the tests for using receipt Signed-off-by: Jawad Tariq --- test/topos-core/ToposCore.test.ts | 10 +- test/topos-core/ToposMessaging.test.ts | 213 ++++++------------ .../shared/constants/certificates.ts | 2 +- .../shared/constants/transactions.ts | 30 +-- test/topos-core/shared/utils/common.ts | 4 +- test/topos-core/shared/utils/mpt_proof.ts | 66 +++--- 6 files changed, 111 insertions(+), 214 deletions(-) diff --git a/test/topos-core/ToposCore.test.ts b/test/topos-core/ToposCore.test.ts index 7e03b28..97bd0cf 100644 --- a/test/topos-core/ToposCore.test.ts +++ b/test/topos-core/ToposCore.test.ts @@ -11,7 +11,7 @@ describe('ToposCore', () => { cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - cc.TX_ROOT_MAX, + cc.RECEIPT_ROOT_MAX, [cc.TARGET_SUBNET_ID_4, cc.TARGET_SUBNET_ID_5], cc.VERIFIER, cc.CERT_ID_1, @@ -68,7 +68,7 @@ describe('ToposCore', () => { cc.PREV_CERT_ID_0, checkpoint[2].toString(), cc.STATE_ROOT_MAX, - cc.TX_ROOT_MAX, + cc.RECEIPT_ROOT_MAX, [cc.TARGET_SUBNET_ID_4], cc.VERIFIER, checkpoint[0].toString(), @@ -102,7 +102,7 @@ describe('ToposCore', () => { cc.PREV_CERT_ID_0, checkpoint[2].toString(), cc.STATE_ROOT_MAX, - cc.TX_ROOT_MAX, + cc.RECEIPT_ROOT_MAX, [cc.TARGET_SUBNET_ID_4], cc.VERIFIER, checkpoint[0].toString(), @@ -128,7 +128,7 @@ describe('ToposCore', () => { cc.PREV_CERT_ID_0, updatedTestCheckpoint[2].toString(), cc.STATE_ROOT_MAX, - cc.TX_ROOT_MAX, + cc.RECEIPT_ROOT_MAX, [cc.TARGET_SUBNET_ID_4], cc.VERIFIER, updatedTestCheckpoint[0].toString(), @@ -158,7 +158,7 @@ describe('ToposCore', () => { const tx = await toposCore.pushCertificate(defaultCert, cc.CERT_POS_1) await expect(tx) .to.emit(toposCore, 'CertStored') - .withArgs(cc.CERT_ID_1, cc.TX_ROOT_MAX) + .withArgs(cc.CERT_ID_1, cc.RECEIPT_ROOT_MAX) }) }) diff --git a/test/topos-core/ToposMessaging.test.ts b/test/topos-core/ToposMessaging.test.ts index 534687b..a57fd0f 100644 --- a/test/topos-core/ToposMessaging.test.ts +++ b/test/topos-core/ToposMessaging.test.ts @@ -2,7 +2,7 @@ import { Contract } from 'ethers' import { deployContractConstant } from '../../scripts/const-addr-deployer' import { ethers, network } from 'hardhat' import { expect } from 'chai' -import { getMptProof } from './shared/utils/mpt_proof' +import { getReceiptMptProof } from './shared/utils/mpt_proof' import { loadFixture } from '@nomicfoundation/hardhat-network-helpers' import { JsonRpcProvider } from '@ethersproject/providers' import { SignerWithAddress } from '@nomiclabs/hardhat-ethers/signers' @@ -30,7 +30,7 @@ describe('ToposMessaging', () => { cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - cc.TX_ROOT_MAX, + cc.RECEIPT_ROOT_MAX, [cc.TARGET_SUBNET_ID_4, cc.TARGET_SUBNET_ID_5], cc.VERIFIER, cc.CERT_ID_1, @@ -261,14 +261,16 @@ describe('ToposMessaging', () => { tokenAddress ) - const { indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await getMptProof(sendToken, ethers.provider) + const { proofBlob, receiptsRoot } = await getReceiptMptProof( + sendToken, + ethers.provider + ) const certificate = testUtils.encodeCertParam( cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - transactionsRoot, + receiptsRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -276,14 +278,7 @@ describe('ToposMessaging', () => { cc.DUMMY_SIGNATURE ) await toposCore.pushCertificate(certificate, cc.CERT_POS_1) - await expect( - erc20Messaging.execute( - indexOfTxData, - proofBlob, - txRaw, - transactionsRoot - ) - ) + await expect(erc20Messaging.execute(proofBlob, receiptsRoot)) .to.emit(erc20, 'Transfer') .withArgs( ethers.constants.AddressZero, @@ -292,7 +287,7 @@ describe('ToposMessaging', () => { ) }) - it('reverts if the index of tx data is out of range', async () => { + it('reverts if the certificate is not present', async () => { const { admin, receiver, @@ -301,53 +296,17 @@ describe('ToposMessaging', () => { erc20Messaging, erc20MessagingContract, } = await loadFixture(deployERC20MessagingFixture) - const { indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await deployDefaultToken( - admin, - receiver, - ERC20, - defaultToken, - erc20Messaging, - erc20MessagingContract - ) - - const outOfBoundsMax = 300 - await expect( - erc20Messaging.execute( - indexOfTxData + outOfBoundsMax, - proofBlob, - txRaw, - transactionsRoot - ) - ).to.be.revertedWithCustomError(erc20Messaging, 'IllegalMemoryAccess') - }) - - it('reverts if the certificate is not present', async () => { - const { + const { proofBlob, receiptsRoot } = await deployDefaultToken( admin, receiver, - defaultToken, ERC20, + defaultToken, erc20Messaging, - erc20MessagingContract, - } = await loadFixture(deployERC20MessagingFixture) - const { indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await deployDefaultToken( - admin, - receiver, - ERC20, - defaultToken, - erc20Messaging, - erc20MessagingContract - ) + erc20MessagingContract + ) await expect( - erc20Messaging.execute( - indexOfTxData, - proofBlob, - txRaw, - transactionsRoot - ) + erc20Messaging.execute(proofBlob, receiptsRoot) ).to.be.revertedWithCustomError(erc20Messaging, 'CertNotPresent') }) @@ -361,22 +320,21 @@ describe('ToposMessaging', () => { erc20Messaging, erc20MessagingContract, } = await loadFixture(deployERC20MessagingFixture) - const { indexOfTxData, transactionsRoot, txRaw } = - await deployDefaultToken( - admin, - receiver, - ERC20, - defaultToken, - erc20Messaging, - erc20MessagingContract - ) + const { receiptsRoot } = await deployDefaultToken( + admin, + receiver, + ERC20, + defaultToken, + erc20Messaging, + erc20MessagingContract + ) await toposCore.setNetworkSubnetId(cc.SOURCE_SUBNET_ID_2) const certificate = testUtils.encodeCertParam( cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - transactionsRoot, + receiptsRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -385,14 +343,8 @@ describe('ToposMessaging', () => { ) await toposCore.pushCertificate(certificate, cc.CERT_POS_1) const fakeProofBlob = '0x01' - await expect( - erc20Messaging.execute( - indexOfTxData, - fakeProofBlob, - txRaw, - transactionsRoot - ) - ).to.be.reverted + await expect(erc20Messaging.execute(fakeProofBlob, receiptsRoot)).to.be + .reverted }) it('reverts if the target subnet id is mismatched', async () => { @@ -405,22 +357,21 @@ describe('ToposMessaging', () => { erc20Messaging, erc20MessagingContract, } = await loadFixture(deployERC20MessagingFixture) - const { indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await deployDefaultToken( - admin, - receiver, - ERC20, - defaultToken, - erc20Messaging, - erc20MessagingContract - ) + const { proofBlob, receiptsRoot } = await deployDefaultToken( + admin, + receiver, + ERC20, + defaultToken, + erc20Messaging, + erc20MessagingContract + ) await toposCore.setNetworkSubnetId(cc.SOURCE_SUBNET_ID_1) // target subnet id = SOURCE_SUBNET_ID_2 const certificate = testUtils.encodeCertParam( cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - transactionsRoot, + receiptsRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -429,12 +380,7 @@ describe('ToposMessaging', () => { ) await toposCore.pushCertificate(certificate, cc.CERT_POS_1) await expect( - erc20Messaging.execute( - indexOfTxData, - proofBlob, - txRaw, - transactionsRoot - ) + erc20Messaging.execute(proofBlob, receiptsRoot) ).to.be.revertedWithCustomError(erc20Messaging, 'InvalidSubnetId') }) @@ -448,22 +394,21 @@ describe('ToposMessaging', () => { erc20Messaging, erc20MessagingContract, } = await loadFixture(deployERC20MessagingFixture) - const { indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await deployDefaultToken( - admin, - receiver, - ERC20, - defaultToken, - erc20Messaging, - erc20MessagingContract - ) + const { proofBlob, receiptsRoot } = await deployDefaultToken( + admin, + receiver, + ERC20, + defaultToken, + erc20Messaging, + erc20MessagingContract + ) await toposCore.setNetworkSubnetId(cc.SOURCE_SUBNET_ID_2) const certificate = testUtils.encodeCertParam( cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - transactionsRoot, + receiptsRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -471,19 +416,9 @@ describe('ToposMessaging', () => { cc.DUMMY_SIGNATURE ) await toposCore.pushCertificate(certificate, cc.CERT_POS_1) - await erc20Messaging.execute( - indexOfTxData, - proofBlob, - txRaw, - transactionsRoot - ) + await erc20Messaging.execute(proofBlob, receiptsRoot) await expect( - erc20Messaging.execute( - indexOfTxData, - proofBlob, - txRaw, - transactionsRoot - ) + erc20Messaging.execute(proofBlob, receiptsRoot) ).to.be.revertedWithCustomError( erc20Messaging, 'TransactionAlreadyExecuted' @@ -499,7 +434,7 @@ describe('ToposMessaging', () => { cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - txc.UNKNOWN_TOKEN_TRANSACTION.txRoot, + txc.UNKNOWN_TOKEN_TRANSACTION.receiptRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -509,10 +444,8 @@ describe('ToposMessaging', () => { await toposCore.pushCertificate(certificate, cc.CERT_POS_1) await expect( erc20Messaging.execute( - txc.INDEX_OF_TX_DATA_36, txc.UNKNOWN_TOKEN_TRANSACTION.proofBlob, - txc.UNKNOWN_TOKEN_TRANSACTION.txRaw, - txc.UNKNOWN_TOKEN_TRANSACTION.txRoot + txc.UNKNOWN_TOKEN_TRANSACTION.receiptRoot ) ).to.be.revertedWithCustomError(erc20Messaging, 'TokenDoesNotExist') }) @@ -527,7 +460,7 @@ describe('ToposMessaging', () => { cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - txc.MINT_EXCEED_TRANSACTION.txRoot, + txc.MINT_EXCEED_TRANSACTION.receiptRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -537,10 +470,8 @@ describe('ToposMessaging', () => { await toposCore.pushCertificate(certificate, cc.CERT_POS_1) await expect( erc20Messaging.execute( - txc.INDEX_OF_TX_DATA_36, txc.MINT_EXCEED_TRANSACTION.proofBlob, - txc.MINT_EXCEED_TRANSACTION.txRaw, - txc.MINT_EXCEED_TRANSACTION.txRoot + txc.MINT_EXCEED_TRANSACTION.receiptRoot ) ).to.be.revertedWithCustomError(erc20Messaging, 'ExceedDailyMintLimit') }) @@ -555,7 +486,7 @@ describe('ToposMessaging', () => { cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - txc.ZERO_ADDRESS_TRANSACTION.txRoot, + txc.ZERO_ADDRESS_TRANSACTION.receiptRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -565,12 +496,10 @@ describe('ToposMessaging', () => { await toposCore.pushCertificate(certificate, cc.CERT_POS_1) await expect( erc20Messaging.execute( - txc.INDEX_OF_TX_DATA_36, txc.ZERO_ADDRESS_TRANSACTION.proofBlob, - txc.ZERO_ADDRESS_TRANSACTION.txRaw, - txc.ZERO_ADDRESS_TRANSACTION.txRoot + txc.ZERO_ADDRESS_TRANSACTION.receiptRoot ) - ).to.be.revertedWith('ERC20: mint to the zero address') + ).to.be.revertedWithCustomError(erc20Messaging, 'TokenDoesNotExist') }) it('emits the Transfer success event', async () => { @@ -583,21 +512,20 @@ describe('ToposMessaging', () => { erc20Messaging, erc20MessagingContract, } = await loadFixture(deployERC20MessagingFixture) - const { erc20, indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await deployDefaultToken( - admin, - receiver, - ERC20, - defaultToken, - erc20Messaging, - erc20MessagingContract - ) + const { erc20, proofBlob, receiptsRoot } = await deployDefaultToken( + admin, + receiver, + ERC20, + defaultToken, + erc20Messaging, + erc20MessagingContract + ) await toposCore.setNetworkSubnetId(cc.SOURCE_SUBNET_ID_2) const certificate = testUtils.encodeCertParam( cc.PREV_CERT_ID_0, cc.SOURCE_SUBNET_ID_1, cc.STATE_ROOT_MAX, - transactionsRoot, + receiptsRoot, [cc.SOURCE_SUBNET_ID_2], cc.VERIFIER, cc.CERT_ID_1, @@ -605,14 +533,7 @@ describe('ToposMessaging', () => { cc.DUMMY_SIGNATURE ) await toposCore.pushCertificate(certificate, cc.CERT_POS_1) - await expect( - erc20Messaging.execute( - indexOfTxData, - proofBlob, - txRaw, - transactionsRoot - ) - ) + await expect(erc20Messaging.execute(proofBlob, receiptsRoot)) .to.emit(erc20, 'Transfer') .withArgs( ethers.constants.AddressZero, @@ -739,9 +660,11 @@ describe('ToposMessaging', () => { tokenAddress ) - const { indexOfTxData, proofBlob, transactionsRoot, txRaw } = - await getMptProof(sendToken, ethers.provider) - return { erc20, indexOfTxData, proofBlob, transactionsRoot, txRaw } + const { proofBlob, receiptsRoot } = await getReceiptMptProof( + sendToken, + ethers.provider + ) + return { erc20, proofBlob, receiptsRoot } } async function sendTokenTx( diff --git a/test/topos-core/shared/constants/certificates.ts b/test/topos-core/shared/constants/certificates.ts index 4b62b68..9c9ce7d 100644 --- a/test/topos-core/shared/constants/certificates.ts +++ b/test/topos-core/shared/constants/certificates.ts @@ -30,6 +30,6 @@ export const TARGET_SUBNET_ID_5 = '0x0000000000000000000000000000000000000000000000000000000000000005' export const TARGET_SUBNET_ID_6 = '0x0000000000000000000000000000000000000000000000000000000000000006' -export const TX_ROOT_MAX = +export const RECEIPT_ROOT_MAX = '0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff' export const VERIFIER = 1 diff --git a/test/topos-core/shared/constants/transactions.ts b/test/topos-core/shared/constants/transactions.ts index 869e448..884bf43 100644 --- a/test/topos-core/shared/constants/transactions.ts +++ b/test/topos-core/shared/constants/transactions.ts @@ -1,38 +1,26 @@ -export const INDEX_OF_TX_DATA_36 = 36 - class TransactionData { proofBlob: string - txRaw: string - txRoot: string + receiptRoot: string optionalData?: string[] - constructor( - proofBlob: string, - txRaw: string, - txRoot: string, - optionalData?: string[] - ) { + constructor(proofBlob: string, receiptRoot: string, optionalData?: string[]) { this.proofBlob = proofBlob - this.txRaw = txRaw - this.txRoot = txRoot + this.receiptRoot = receiptRoot this.optionalData = optionalData } } export const MINT_EXCEED_TRANSACTION: TransactionData = new TransactionData( - '0xf8f80180f8f4f8f2822080b8edf8eb078451e864ab83010e6494dc64a140aa3e981100a9beca4e685f962f0cf6c980b8845c914ec6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000007d8794cc292c8d25e410f33c53fa4341ab9365df000000000000000000000000000000000000000000000000000000000000006d82f4f5a020f0caf4045fed9afea707d5715f5367ad3ea1c3c4f1b5c3a98f9a100bee3e3aa07ff71319969fdb6c500588b1a67301de9e63f011a2ed646e7d0cd619dced3f28', - '0xf8eb078451e864ab83010e6494dc64a140aa3e981100a9beca4e685f962f0cf6c980b8845c914ec6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000007d8794cc292c8d25e410f33c53fa4341ab9365df000000000000000000000000000000000000000000000000000000000000006d82f4f5a020f0caf4045fed9afea707d5715f5367ad3ea1c3c4f1b5c3a98f9a100bee3e3aa07ff71319969fdb6c500588b1a67301de9e63f011a2ed646e7d0cd619dced3f28', - '0x1d8a23e1a34d5b71d5e0567dea7d426fbb82d05cdce65405e159d64c8ad2d4e8' + '0xf903530180f9034ef9034b822080b90345f903420183010489b9010004000000000000000000000000000000000000000000000000000000004000000000001000000000400000000000080000000000000000000000000000200001000000000000000800000008000000000000000000000001000000000000000000000000020000000000000100000800000000000000000000000010000000000000000008000000000000000000000000000000000000000000000000000000020000000000000000000100080000000000000000000000000000000000000000000002000000200001000000000000000000002000000000000000000020000410000000000000000000000000000000000000008080000000000000000000f90237f89b947d8794cc292c8d25e410f33c53fa4341ab9365dff863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a0000000000000000000000000dc64a140aa3e981100a9beca4e685f962f0cf6c9a00000000000000000000000000000000000000000000000000000000000000000f89b947d8794cc292c8d25e410f33c53fa4341ab9365dff863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000000000000000000000000000000000000000000000a0000000000000000000000000000000000000000000000000000000000000006df8fb94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0fc206599322fdabaf4a42cd93b837734408b6a1ea6117cb9040c87d728a67d54a00000000000000000000000000000000000000000000000000000000000000002b8a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000007d8794cc292c8d25e410f33c53fa4341ab9365df000000000000000000000000000000000000000000000000000000000000006d', + '0xa0d907da3ad053132deb276aff73c40f6737ed4f6e31dd7c979d5eff83ef12c2' ) export const UNKNOWN_TOKEN_TRANSACTION: TransactionData = new TransactionData( - '0xf8f80180f8f4f8f2822080b8edf8eb078451d6ca388301141c94dc64a140aa3e981100a9beca4e685f962f0cf6c980b8845c914ec6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c800000000000000000000000084ca534d36b5d544251db6722e245409d7293bb1000000000000000000000000000000000000000000000000000000000000003282f4f6a06704fe2ef8c355cb750faddb21051d58f3198287ea54b2320c1cf2fcf0f2d4a1a025ffe4da9059821e8944ca10c4f6caaa3a8938ccb98f5c0698ac1d6a55c75030', - '0xf8eb078451d6ca388301141c94dc64a140aa3e981100a9beca4e685f962f0cf6c980b8845c914ec6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c800000000000000000000000084ca534d36b5d544251db6722e245409d7293bb1000000000000000000000000000000000000000000000000000000000000003282f4f6a06704fe2ef8c355cb750faddb21051d58f3198287ea54b2320c1cf2fcf0f2d4a1a025ffe4da9059821e8944ca10c4f6caaa3a8938ccb98f5c0698ac1d6a55c75030', - '0xe62585388b2c91456092920d65cfdf960460198ab64024f91b946f422d6eb401' + '0xf903530180f9034ef9034b822080b90345f903420183010489b9010004000000000000000000000000000000000000000000000000000000004000000000001000000000400000000000080000000000000000000000000000200001000000000000000800000008000000000000000000000001000000000000000000000000020000000000000100000800000000000000000000000010000000000000000008000000000000000000000000000000000000000000000000000000020000000000000000000100080000000000000000000000000000000000000000000002000000200001000000000000000000002000000000000000000020000410000000000000000000000000000000000000008080000000000000000000f90237f89b947d8794cc292c8d25e410f33c53fa4341ab9365dff863a08c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925a0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a0000000000000000000000000dc64a140aa3e981100a9beca4e685f962f0cf6c9a00000000000000000000000000000000000000000000000000000000000000000f89b947d8794cc292c8d25e410f33c53fa4341ab9365dff863a0ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3efa0000000000000000000000000f39fd6e51aad88f6f4ce6ab8827279cfffb92266a00000000000000000000000000000000000000000000000000000000000000000a00000000000000000000000000000000000000000000000000000000000000032f8fb94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0fc206599322fdabaf4a42cd93b837734408b6a1ea6117cb9040c87d728a67d54a00000000000000000000000000000000000000000000000000000000000000002b8a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c80000000000000000000000007d8794cc292c8d25e410f33c53fa4341ab9365df0000000000000000000000000000000000000000000000000000000000000032', + '0x17c5f4cfaaaaea9c17a21aae2fbd7ddea134393de5ac87a6e42101fbac670b23' ) export const ZERO_ADDRESS_TRANSACTION: TransactionData = new TransactionData( - '0xf8f80180f8f4f8f2822080b8edf8eb078451e864ab83010d6194dc64a140aa3e981100a9beca4e685f962f0cf6c980b8845c914ec6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000007d8794cc292c8d25e410f33c53fa4341ab9365df000000000000000000000000000000000000000000000000000000000000003282f4f6a0f76828e536baeb87bda95b288e89ff916058ab3b0f3d81237308d853f19f257ca0631bc5c5ab51c696918105ed0c0aca1660adda6ac8a78267d10c43319c3ec476', - '0xf8eb078451e864ab83010d6194dc64a140aa3e981100a9beca4e685f962f0cf6c980b8845c914ec6000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000000000000000000000000000000000000000000000000000000007d8794cc292c8d25e410f33c53fa4341ab9365df000000000000000000000000000000000000000000000000000000000000003282f4f6a0f76828e536baeb87bda95b288e89ff916058ab3b0f3d81237308d853f19f257ca0631bc5c5ab51c696918105ed0c0aca1660adda6ac8a78267d10c43319c3ec476', - '0x374084da2b2c7401d38bd441e8681855d9d717635ec14a77f36185763c75f1dd' + '0xf902170180f90212f9020f822080b90209f9020601828555b9010004000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000080000000000000000000000000000000001000000000000000800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000100000000000000000000000000000000000000000000000000000000000001000000000000000000000000000000000000000000000000000000000000000000000000000000000000008080000000000000000000f8fdf8fb94cf7ed3acca5a467e9e704c703e8d87f634fb0fc9f842a0fc206599322fdabaf4a42cd93b837734408b6a1ea6117cb9040c87d728a67d54a00000000000000000000000000000000000000000000000000000000000000002b8a00000000000000000000000000000000000000000000000000000000000000020000000000000000000000000000000000000000000000000000000000000006000000000000000000000000070997970c51812dc3a010c7d01b50e0d17dc79c800000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032', + '0xbe3ae823d0139b5fa7e339cf0735d9f3f8f25e86cf71627c3e98fe3e12414d20' ) diff --git a/test/topos-core/shared/utils/common.ts b/test/topos-core/shared/utils/common.ts index 4ec91cf..7dd37c6 100644 --- a/test/topos-core/shared/utils/common.ts +++ b/test/topos-core/shared/utils/common.ts @@ -4,7 +4,7 @@ function encodeCertParam( prevId: string, sourceSubnetId: string, stateRoot: string, - txRoot: string, + receiptRoot: string, targetSubnets: string[], verifier: number, certId: string, @@ -27,7 +27,7 @@ function encodeCertParam( prevId, sourceSubnetId, stateRoot, - txRoot, + receiptRoot, targetSubnets, verifier, certId, diff --git a/test/topos-core/shared/utils/mpt_proof.ts b/test/topos-core/shared/utils/mpt_proof.ts index cc3f612..b0f1743 100644 --- a/test/topos-core/shared/utils/mpt_proof.ts +++ b/test/topos-core/shared/utils/mpt_proof.ts @@ -3,7 +3,7 @@ import { RLP } from '@ethereumjs/rlp' import { Trie } from '@ethereumjs/trie' import { BlockWithTransactions } from '@ethersproject/abstract-provider' -export async function getMptProof( +export async function getReceiptMptProof( tx: ethers.providers.TransactionResponse, provider: ethers.providers.JsonRpcProvider ) { @@ -13,44 +13,52 @@ export async function getMptProof( receipt.blockHash, true, ]) - const transactionsRoot = rawBlock.transactionsRoot + const receiptsRoot = rawBlock.receiptsRoot const trie = await createTrie(block) const trieRoot = trie.root() - if ('0x' + trieRoot.toString('hex') !== transactionsRoot) { - throw new Error('Transactions root mismatch') + if ('0x' + trieRoot.toString('hex') !== receiptsRoot) { + throw new Error( + 'Receipts root does not match trie root' + + '\n' + + 'trieRoot: ' + + '0x' + + trieRoot.toString('hex') + + '\n' + + 'receiptsRoot: ' + + receiptsRoot + ) } const indexOfTx = block.transactions.findIndex((_tx) => _tx.hash === tx.hash) const key = Buffer.from(RLP.encode(indexOfTx)) - const txRaw = getRawTransaction(tx) - const indexOfTxData = txRaw.substring(2).indexOf(tx.data.substring(2)) / 2 - const { stack: _stack } = await trie.findPath(key) const stack = _stack.map((node) => node.raw()) const proofBlob = ethers.utils.hexlify(RLP.encode([1, indexOfTx, stack])) - return { indexOfTxData, proofBlob, transactionsRoot, txRaw } + return { proofBlob, receiptsRoot } } async function createTrie(block: BlockWithTransactions) { const trie = new Trie() await Promise.all( block.transactions.map(async (tx, index) => { - const { nonce, gasPrice, gasLimit, to, value, data, v, r, s } = tx + const { /*type,*/ cumulativeGasUsed, logs, logsBloom, status } = + await tx.wait() + // console.log('Tx type: ', type) + // console.log('status: ', status) + // console.log('cumulativeGasUsed: ', cumulativeGasUsed) + // console.log('logsBloom: ', logsBloom) + // console.log('logs: ', logs) + return trie.put( Buffer.from(RLP.encode(index)), Buffer.from( RLP.encode([ - nonce, - gasPrice?.toNumber(), - gasLimit.toNumber(), - to, - value.toNumber(), - data, - v, - r, - s, + status, + cumulativeGasUsed.toNumber(), + logsBloom, + logs.map((l) => [l.address, l.topics, l.data]), ]) ) ) @@ -58,25 +66,3 @@ async function createTrie(block: BlockWithTransactions) { ) return trie } - -function getRawTransaction(tx: ethers.providers.TransactionResponse): string { - function addKey(accum, key) { - if (tx[key as keyof typeof tx]) { - accum[key] = tx[key as keyof typeof tx] - } - return accum - } - const txFields = - 'accessList chainId data gasPrice gasLimit maxFeePerGas maxPriorityFeePerGas nonce to type value'.split( - ' ' - ) - const sigFields = 'v r s'.split(' ') - const raw = ethers.utils.serializeTransaction( - txFields.reduce(addKey, {}), - sigFields.reduce(addKey, {}) - ) - if (ethers.utils.keccak256(raw) !== tx.hash) { - throw new Error('serializing failed!') - } - return raw -}