← COMP5521 全部讲次
Q01

Lab Test 英文自测|S1-S22

现有材料范围内的非官方复习,含英文术语、成立条件与自拟练习解析。

手机上宽表格可左右滑动;自测答案默认收起,点击题目下方按钮查看。

非官方自拟练习,考试安排与范围以讲师通知为准。 先用英文作答,再逐题展开解析。

测验类型与范围边界

非官方 Lab Test 复习资料,不是 Midterm 真题。 现有课程信息列 Lab 9 Test:11-13,20:20-21:20,一小时、开卷、占 10%。最新考试安排、可携带资料和范围以讲师通知为准;“开卷”不自动等于允许联网、使用 AI 或相互讨论。

当前覆盖 Lab 1、Lab 2、Lab 3 及 HTLC 项目说明中的基础:部署与调用、回执与状态、ERC-20 授权、哈希锁与时间锁;11-07 补入 Lab 5(密码算法与应用)、Lab 6(Bitcoin Regtest)、Lab 7(Stablecoin,11-06 上课)的开卷速查:命令、函数签名、公式、常量、错误名与易错点。项目用于机制练习,不据此断言项目全部内容进入 Lab Test。讲师尚未正式公布范围,Lab 5–7 按可能考到整理,正式范围以讲师通知为准。

资料是定位索引,不是把操作截图背下来。每个实验都练“输入是什么、哪一步改状态、失败在哪里、用什么证据确认”。只用本地链或课程指定测试环境,使用独立测试账户,不公开密钥,不把测试脚本指向主网。

复习资料 · 英文自测 1

英文自测

S1 · ABI and bytecode

Can an ABI JSON document alone deploy a contract? State the missing type of artifact.

S1 · 查看答案与解析

No. “Deployment requires creation bytecode, with any required constructor arguments; the ABI describes encoding and interfaces.” ABI 不是机器码,运行时代码和创建代码也应区分。

S2 · Simulation

A state-changing function succeeds in eth_call. Does this permanently change chain state or guarantee that a later transaction succeeds?

S2 · 查看答案与解析

Neither. “eth_call simulates against a selected state; it does not persist state, and the later execution context may differ.” 不产生此次模拟的链上费,不意味着 RPC 服务必然无成本。

S3 · Revert

An included top-level transaction updates a variable, emits an event and then reverts. Which effects remain: storage update, event log, consumed transaction nonce, used-gas charge?

S3 · 查看答案与解析

The consumed nonce and used-gas charge remain. “The storage update and emitted log are rolled back.” 题目明确已经入块,不能写成提交前被拒绝;日志不出现在这笔失败交易的有效收据日志中。

S4 · Counter trace

Start with counter=5. Three separate included transactions are increment(4) successfully, increment(20) followed by an uncaught revert, and reset() successfully. Give the counter after each transaction.

S4 · 查看答案与解析

9, 9, 0. 三笔交易分别结算;第二笔回滚不抹去第一笔已经提交的加 4。先写每笔前状态,再画回滚边界。

S5 · Approval

Alice owns 70 tokens. She successfully sets an allowance of 25 for a spender. The spender then transfers 10 tokens from Alice using that finite allowance. Give Alice’s balance and remaining allowance, assuming ordinary ERC-20 finite-allowance semantics.

S5 · 查看答案与解析

Balance 60; allowance 15. Approve 后仍有 70,转走 10 后才变 60;额度由 25 减为 15。题目排除无限授权不递减等实现口径。

S6 · Call routing

A contract has both receive and a payable fallback. A call has nonempty calldata with an unknown selector and attaches ETH. Which entry is selected, assuming enough gas and a normally returning fallback?

S6 · 查看答案与解析

Fallback. “Nonempty unmatched calldata selects fallback, not receive.” 不能只看是否携带 ETH;题设已保证入口 payable、gas 和执行条件。

S7 · Deadline equality

Use claim when t<T and refund when t≥T. At t=T, the swap is active and the caller is the original funder. Is refund allowed? Can the receiver claim at the same timestamp with the right secret?

S7 · 查看答案与解析

Refund is allowed; claim is not. “Equality belongs to the refund branch under the stated convention.” 比较符的边界需显式测试,其他前提仍包括状态和调用者。

S8 · Caller authorization

Under the project specification, an attacker learns the correct preimage but is not the designated receiver. Is the attacker entitled to claim the HTLC?

S8 · 查看答案与解析

No. “The hash condition does not replace the designated-receiver check.” Attacker 是攻击者;原像只提供满足哈希条件的输入。

S9 · Two deadlines

Alice locks first on chain A and claims first on chain B. Which deadline should be later, and why is merely a one-second difference not a general safety guarantee?

S9 · 查看答案与解析

T_A should be later than T_B. “Bob needs time to observe Alice’s revelation and get his claim included and sufficiently confirmed on A.” 延迟和确认等待没有通用一秒上界;实际缓冲依网络假设。

S10 · Evidence and terminal states

A swap has already been claimed. After its deadline, may the original funder refund it? Name two additional negative tests besides this case.

S10 · 查看答案与解析

No. “Claimed is a terminal state; the funds cannot be consumed again.” 可补错秘密、错调用者、过早退款、过期领取或重复领取中的任意两项,并验证余额和交换状态未被失败调用改变。

S11 · Hash label

The Lab 5 hash script prints a line labelled “SHA-1 hash” that contains 56 hexadecimal characters. Which function was actually called, and how many hexadecimal characters does a real SHA-1 digest have?

S11 · 查看答案与解析

hashlib.sha224(); 40. 56 个十六进制字符乘 4 是 224 位,所以那一行是 SHA-224。SHA-1 输出 160 位,即 40 个十六进制字符;改成 hashlib.sha1() 才是真 SHA-1。

S12 · RSA-OAEP limit

A 2048-bit RSA key with OAEP padding (MGF1 and hash both SHA-256) encrypts a 32-byte message. How long is the ciphertext in bytes? Would a 191-byte message encrypt successfully?

S12 · 查看答案与解析

256 bytes; no. “The OAEP-SHA256 limit for a 2048-bit key is 256 − 2 × 32 − 2 = 190 bytes.” 191 字节报 ValueError: Encryption failed。长数据用 AES 加密,RSA 只加密那把 AES 密钥。

S13 · Proof-of-work check

The check is int(hash_res, 16) < 2**(256 - bits) with bits set to 10. Two candidate hashes begin with the hex prefixes 003f and 0040. Which one passes, and what is the expected number of tries at this difficulty?

S13 · 查看答案与解析

003f passes; 0040 fails; about 1024 tries. 003f 是 0000 0000 0011 1111,10 个前导 0;0040 是 0000 0000 0100 0000,只有 9 个。期望尝试次数 2^10 = 1024。只数十六进制的 0 会误判,要换成二进制数。

S14 · Merkle padding

Using the Lab 5 padding rule, a Merkle tree is built from 5 leaves. How many empty strings are added, how many parent hashes are computed, and how many sibling hashes does a membership proof need?

S14 · 查看答案与解析

3 empty strings, 7 parent hashes, 3 sibling hashes. 不超过 5 的最大 2 的幂是 4,补 2 × 4 − 5 = 3 个,共 8 个叶子;父节点哈希 4 + 2 + 1 = 7 次;证明要 log₂8 = 3 个兄弟哈希,还要写明左右顺序。

S15 · Wallet fee and change

In regtest, the wallet’s only spendable UTXO is 25 BTC. You call sendtoaddress for 7 BTC with fee_rate 12 sat/vB, and the transaction has vsize 141 vB. Assuming the fee is exactly fee_rate times vsize, what fee in satoshis and what change amount appear after one block is mined?

S15 · 查看答案与解析

1692 sat; change 17.99998308 BTC. 12 × 141 = 1692 sat = 0.00001692 BTC;25 − 7 − 0.00001692 = 17.99998308。课件原题是 50、12、37.99998590,反算得 1410 sat,费率 10 sat/vB。

S16 · Raw transaction fee

createrawtransaction spends one 5 BTC UTXO with two outputs: 3.2 BTC to the receiver and 1.7995 BTC to your change address. What is the fee? What would the fee be if the change output were omitted, and what is likely to happen at broadcast?

S16 · 查看答案与解析

0.0005 BTC (50000 sat); without change the fee becomes 1.8 BTC. 5 − 3.2 − 1.7995 = 0.0005。输出里不写找零,输入减输出的 1.8 BTC 全部成为手续费;费率远超默认上限 0.1 BTC/kvB,sendrawtransaction 会拒绝。

S17 · Coinbase maturity

After generatetoaddress 101 to your mining address, getbalances shows trusted 50 and immature 5000. You mine one more block to the same address with no other transactions. What are trusted and immature now?

S17 · 查看答案与解析

Trusted 100, immature 5000. 第 102 块挖出后,第 2 块的 coinbase 也满 101 个确认;第 3–102 块共 100 块各 50 BTC 仍未成熟。Regtest 的减半间隔是 150 块,102 块内每块奖励都是 50 BTC(见文末补充)。

S18 · Broadcast and lookup

signrawtransactionwithwallet returns a JSON object with hex and complete set to true. Which hex do you pass to sendrawtransaction? If getblockcount was 102 before broadcasting and you then mine one block, at which height is the raw transaction, and what is the first entry in that block’s tx list?

S18 · 查看答案与解析

The signed hex from the result; height 103; the coinbase transaction. 传 createrawtransaction 的未签名 hex 会被拒;complete 为 false 时说明有输入没签上,也不要广播。每个块 tx 列表第一项都是给矿工的 coinbase。

S19 · Borrowing limit

In the Lab 7 engine, Alice deposits 0.8 WETH while the oracle price is $3,000. What is the largest debt she can hold? Does mint(1600) succeed? Does mint(1601) succeed, and if not, which error is raised and what happens to debt and supply?

S19 · 查看答案与解析

1600; yes; no, BreachesLiquidationThreshold. 0.8 × 3000 = 2400 美元,2400 ÷ 1.5 = 1600。mint(1600) 后 HF 恰好 1.0000,检查是 HF < 1 才 revert;mint(1601) 的 HF 为 2400 ÷ 2401.5 ≈ 0.999375,revert 后债务、totalDebt 和总供应都不变,gas 照付。

S20 · Crash and liquidation

Continue after a successful mint(1600). The ETH price falls to $2,400. Give Alice’s health factor. Bob holds 1,600 LABUSD borrowed from his own position and has approved the engine; he calls liquidate(alice, weth, 1600). What does Bob receive, what does Alice have afterwards (collateral, debt, wallet), and how does total supply change?

S20 · 查看答案与解析

HF 0.80; Bob receives about 0.7333 WETH worth $1,760; Alice keeps about 0.0667 WETH ($160), debt 0, wallet 1,600 LABUSD; total supply falls by 1,600. 0.8 × 2400 = 1920,1920 ÷ 2400 = 0.8。扣押美元 1600 × 1.1 = 1760,1760 ÷ 2400 = 0.733333…,向上取整到 wei。Alice 净资产 1600 + 160 = 1760 美元,比暴跌前的 2400 美元少 640:480 是 ETH 贬值,160 是清算奖励。

S21 · Revert names

Lab position: Alice has 0.5 WETH collateral and 1,000 debt; Bob is funded and has approved the engine. Name the outcome of each separate call: (a) Bob liquidates 1,000 at $3,000; (b) Alice calls liquidate on her own position at $2,400; (c) Bob liquidates 1,000 at $2,100; (d) Alice calls repay(100) without approving the engine.

S21 · 查看答案与解析

(a) PositionIsHealthy; (b) CannotLiquidateSelf; (c) InsufficientCollateral; (d) ERC20InsufficientAllowance. (a) HF 1.00 不小于 1,不可清算;(c) 1100 ÷ 2100 ≈ 0.5238 WETH,超过 0.5;(d) 错误来自 LABUSD 的 transferFrom。四笔都整笔回滚,债务、抵押和总供应不变。

S22 · Yield-bearing collateral

Alice deposits 1,500 mUSD into the ERC-4626 vault, receives 1,500 shares, locks them in the engine and mints 900. The owner then adds 75 mUSD of yield, and later the oracle price of mUSD falls to $0.8. Give the health factor at each of the three points, and state whether the share count or the debt changed.

S22 · 查看答案与解析

About 1.1111, then about 1.1667, then about 0.9333; shares stay 1,500 and debt stays 900. 1500 ÷ 1350,1575 ÷ 1350,1575 × 0.8 = 1260 后 1260 ÷ 1350。收益让每份额对应的底层资产变多,份额数量不变;底层脱锚时 HF 照样跌破 1。链上份额价值不等于真实可变现价值,托管、赎回和估值滞后都是链下风险。

下一页 →
Q02 2025 Final 真题解析(上)|Q16-Q18 RSA、DH 与签名

个人整理的学习笔记,不是官方材料;数字与结论以课件和讲师为准。