Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
789 changes: 159 additions & 630 deletions frontend/package-lock.json

Large diffs are not rendered by default.

5 changes: 1 addition & 4 deletions frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
"@qrlwallet/connect-ui": "0.3.0",
"@radix-ui/react-slot": "^1.1.2",
"@radix-ui/react-tabs": "^1.1.1",
"@theqrl/web3": "^1.0.3",
"@theqrl/web3": "^2.0.0",
"class-variance-authority": "^0.7.1",
"clsx": "^2.1.1",
"lucide-react": "^0.562.0",
Expand Down Expand Up @@ -59,9 +59,6 @@
"node": ">=22.22.0"
},
"overrides": {
"@theqrl/mldsa87": "2.2.0",
"@theqrl/qrl-cryptography": "0.3.3",
"@theqrl/wallet.js": "6.3.0",
"brace-expansion@1": "1.1.18",
"brace-expansion@5": "5.0.9",
"esbuild": "0.28.1",
Expand Down
6 changes: 4 additions & 2 deletions frontend/src/stores/poolStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1206,8 +1206,10 @@ export class PoolStore {
`${event.name}(${event.inputs.map((input) => input.type).join(",")})`,
);
const topics = nativeEventTopics(signature, beneficiary);
// The SDK's getPastEvents filter still assumes narrower log topics. The
// unmodified native node uses VM64 topics; keep its native ABI decoder.
// The unmodified native node uses VM64 topics. @theqrl/web3 1.x's filter
// validator accepted only 32-byte topics, so this request went out raw.
// 2.0.0 validates 64-byte topics; the raw request stays because it sends
// exactly the filter checked below, and the native ABI decoder reads it.
const response = await fetch(this.network.rpcUrl, {
method: "POST",
headers: { "content-type": "application/json" },
Expand Down
38 changes: 34 additions & 4 deletions frontend/src/utils/nativeLogs.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,28 @@ import { Web3 } from "@theqrl/web3";
import { nativeEventTopics, matchesNativeTopics } from "./nativeLogs.ts";
import { NativeQrlPoolABI } from "../abi/NativeQrlPool.ts";

const signature =
// keccak256("DepositQueued(address,uint256,uint256)") and its VM64 topic,
// the hash in the high 32 bytes and zeros in the low 32 bytes.
const hash =
"0xff465791f48805b0254fc0e26cc605e27ef7706d8ee0cf018f8696f58db83679";
const signature = hash + "00".repeat(32);
const beneficiary = "Q" + "12".repeat(32) + "ab".repeat(32);

void test("native event filters retain complete 64-byte addresses and high-aligned signature hashes", () => {
const topics = nativeEventTopics(signature, beneficiary);
assert.equal(topics[0], signature + "00".repeat(32));
assert.equal(topics[0], signature);
assert.equal(topics[1], "0x" + "12".repeat(32) + "ab".repeat(32));
assert(!matchesNativeTopics([signature, topics[1]], topics));
assert.deepEqual(
nativeEventTopics(
signature.toUpperCase().replace(/^0X/, "0x"),
beneficiary,
),
topics,
);
assert(!matchesNativeTopics([hash, topics[1]], topics));
assert(
!matchesNativeTopics(
["0x" + "00".repeat(32) + signature.slice(2), topics[1]],
["0x" + "00".repeat(32) + hash.slice(2), topics[1]],
topics,
),
);
Expand All @@ -34,10 +44,16 @@ void test("native ABI decoder reads the deployed DepositQueued word layout witho
(item) => item.type === "event" && item.name === "DepositQueued",
);
assert(event);
// @theqrl/web3 2.0.0 returns the VM64 topic itself; 1.x returned the bare
// 32-byte hash, which nativeEventTopics now refuses.
assert.equal(
web3.qrl.abi.encodeEventSignature("DepositQueued(address,uint256,uint256)"),
signature,
);
assert.equal(
web3.utils.keccak256("DepositQueued(address,uint256,uint256)"),
hash,
);
const words = nativeEventTopics(signature, beneficiary);
const data = "0x" + (20000n * 10n ** 18n).toString(16).padStart(128, "0");
const decoded = web3.qrl.abi.decodeLog([...event.inputs], data, [
Expand All @@ -57,6 +73,20 @@ void test("legacy-width and malformed native log filters reject before RPC", ()
assert.throws(() =>
nativeEventTopics(signature + "00", "Q" + "11".repeat(64)),
);
// The bare 32-byte hash that @theqrl/web3 1.x returned.
assert.throws(() => nativeEventTopics(hash, beneficiary), {
message: "Invalid native event filter",
});
// A 64-byte word that is not a high-aligned hash.
assert.throws(() =>
nativeEventTopics("0x" + "00".repeat(32) + hash.slice(2), beneficiary),
);
assert.throws(() =>
nativeEventTopics(hash + "00".repeat(31) + "01", beneficiary),
);
assert.throws(() =>
nativeEventTopics("0X" + signature.slice(2), beneficiary),
);
assert(!matchesNativeTopics(null, []));
assert(!matchesNativeTopics(["0x"], []));
});
16 changes: 12 additions & 4 deletions frontend/src/utils/nativeLogs.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,23 @@
import { isQrlAddress } from "./qrlAddress.ts";
import { isArray } from "./guards.ts";

/** Native VM64 topics: bytes32 signatures occupy the high bytes; addresses use all 64 bytes. */
/**
* Native VM64 topics: an event signature topic holds the 32-byte keccak hash
* in its high bytes and zeros in its low 32 bytes, the 64-byte form that
* `abi.encodeEventSignature` returns since @theqrl/web3 2.0.0 (1.x returned
* the bare 32-byte hash). Addresses use all 64 bytes.
*/
export function nativeEventTopics(
signature: string,
signatureTopic: string,
beneficiary: string,
): [string, string] {
if (!/^0x[0-9a-fA-F]{64}$/.test(signature) || !isQrlAddress(beneficiary))
if (
!/^0x[0-9a-fA-F]{64}0{64}$/.test(signatureTopic) ||
!isQrlAddress(beneficiary)
)
throw new Error("Invalid native event filter");
return [
signature.toLowerCase().padEnd(130, "0"),
signatureTopic.toLowerCase(),
`0x${beneficiary.slice(1).toLowerCase()}`,
];
}
Expand Down
75 changes: 74 additions & 1 deletion frontend/src/utils/poolStoreTransactions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import test from "node:test";
import { buildSync } from "esbuild";
import { Web3 } from "@theqrl/web3";
import { nativePoolMethods } from "./web3/nativePool.ts";
import { NativeQrlPoolABI } from "../abi/NativeQrlPool.ts";
import { nativeEventTopics } from "./nativeLogs.ts";
import { requireRecord } from "./guards.ts";
import type { PoolStore, TxStatus } from "../stores/poolStore";
Expand Down Expand Up @@ -191,6 +192,56 @@ void test("older pending refunds become visible after the latest 64 deposits are
assert.deepEqual(reads, [0n]);
});

void test("pending deposits accept the checksummed beneficiary the installed web3 decodes", async () => {
const f = fixture();
// Hex letters make the QIP-55 checksum casing visible.
const account = `Q${"ab".repeat(32)}${"12".repeat(32)}`;
f.connect(account);
const getPending = NativeQrlPoolABI.find(
(item) => item.type === "function" && item.name === "getPending",
);
assert(getPending?.type === "function");
const [output] = getPending.outputs;
assert(output);
const record = offlineWeb3.qrl.abi.decodeParameter(
output,
offlineWeb3.qrl.abi.encodeParameter(output, {
beneficiary: account,
amount: 100n,
requestedBlock: 5n,
cancelled: false,
}),
);
// Since @theqrl/web3 2.0.0 the decoder returns the checksummed spelling,
// so the beneficiary check meets a mixed-case address; 1.x returned the
// lowercase body.
const beneficiary = String(requireRecord(record).beneficiary);
assert.notEqual(beneficiary, account);
assert.equal(beneficiary.toLowerCase(), account.toLowerCase());
f.internal.queryNativeEvents = async (name) =>
name === "DepositQueued"
? [
{
blockNumber: 1n,
transactionHash: oldHash,
returnValues: { id: 0n, amount: 100n },
},
]
: [];
f.internal.getContracts = async () => ({
pool: {
pendingHead: () => ({ call: async () => 0n }),
getPending: () => ({ call: async () => record }),
},
});

await f.internal.fetchActivity(account);
assert.equal(f.store.activityError, null);
assert.deepEqual(f.store.pendingDeposits, [
{ id: 0n, amount: 100n, requestBlock: 5n },
]);
});

for (const outcome of ["hash", "error"] as const) {
void test(`old wallet ${outcome} cannot replace a newer same-account request`, async () => {
const f = fixture();
Expand Down Expand Up @@ -693,8 +744,12 @@ void test("position and request response guards reject malformed fields", async
});
});

const eventSignature =
// The VM64 topic of DepositQueued(address,uint256,uint256) as
// encodeEventSignature returns it since @theqrl/web3 2.0.0: the keccak hash in
// the high 32 bytes and zeros in the low 32 bytes.
const eventHash =
"0xff465791f48805b0254fc0e26cc605e27ef7706d8ee0cf018f8696f58db83679";
const eventSignature = eventHash + "00".repeat(32);
const nativeLog = {
address: poolAddress,
topics: [
Expand Down Expand Up @@ -741,6 +796,24 @@ void test("native event RPC preserves complete topics and exact decoded values",
);
});

void test("native event RPC refuses a 32-byte event signature before any request", async (t) => {
const f = fixture();
// The width @theqrl/web3 1.x returned. Padding it here would hide a change
// in the library's topic layout, so the filter fails closed.
f.internal.getWeb3 = async () => ({
qrl: { abi: { encodeEventSignature: () => eventHash } },
});
const fetched = t.mock.method(
globalThis,
"fetch",
async () => new Response(JSON.stringify({ result: [nativeLog] })),
);
await assert.rejects(f.internal.queryNativeEvents("DepositQueued", address), {
message: "Invalid native event filter",
});
assert.equal(fetched.mock.callCount(), 0);
});

void test("native event RPC drops malformed envelopes, logs and decoded records", async (t) => {
const f = fixture();
f.internal.getWeb3 = async () => offlineWeb3;
Expand Down
Loading
Loading