← COMP5565 全部讲次
Q07

期中模拟卷 B|单选题 9-15

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

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

非官方自拟模拟卷 B,正式考试范围、题型、时长和开闭卷要求以讲师通知为准。 按现有期中前密码学基础、L01-L05 与 Lab 1 编写,借鉴所提供往年期末卷的可见设问结构;不加入期中后专题。本卷不是往年期中真题或押题。

全卷 100 分,建议练习 100 分钟。Part A 为自拟单选 15 题共 30 分;Part B 共 70 分。原参考文件没有选择题正文,不能据此预测实际选择规则。每题答案和给分点默认收起,自评分不等于教师评分。

统一前提:Solidity 0.8.30、默认 checked arithmetic;采用普通 EOA 交易模型,不讨论账户代码委托。代码仅用于教学;除题目说明外,gas 充足、无隐藏操作、无额外费用。计算按题面精确数值。

读题词:attacker = 攻击者;justify = 给出原因;at least = 至少;strictly = 严格;resulting state = 结果状态。问题中的“攻击者”不是哈希性质的名称。

来源代号:C01 是密码学基础;L01-L05 对应逐讲注解。答案回查页码均为原 PDF 页序。英文同义表达与机制正确的替代答案可以成立。

B 卷导航:单选题 1-8 · 单选题 9-15 · 机制与应用 16-20 · 重入推演 21 · 升级 状态与钱包 22-24

前一套复习题入口 · 复习资料

单选题 9-15

B9 · Q9 Slashing conditions [2 marks]

Consider two attestations by the same validator, with source/target epoch pairs (3, 9) and (3, 7). Looking only at the double-vote and strict surround-vote conditions, which statement is correct?

A. They are a double vote because the source epochs match.
B. Neither of these two conditions is met by the stated pairs.
C. They are a surround vote because 9 is greater than 7.
D. Both conditions are met.

B9 · 查看答案与解析

Q9 · B · Equal source epochs do not strictly surround

推理过程:逐条验条件:① double vote(双重投票)需要相同 target epoch,但 9 ≠ 7,不满足。② surround vote(包围投票)需要外层起点严格更早且终点严格更晚;两条票的起点都是 3,第一项不满足。因此选 B。A 比错了端点,C 漏检起点,D 同时犯这两个错误。

English: The targets differ, so these are not a double vote. A surround vote requires strict containment of source/target intervals; equal source epochs fail that condition.

中文:(3, 9) 与 (3, 7) 的左端相等。不能仅看到 9 > 7 就判 surround;也不能把本题结果升级为“这两个证明满足一切其他有效性规则”。回查:L02 p.109-110 及校订。

B10 · Q10 Weighted support [2 marks]

Six out of eight validators support a checkpoint link. Their effective balances sum to 192 ETH; total active effective balance is 320 ETH. The link requires at least two thirds of the total weight. Is this threshold met?

A. Yes, because six out of eight is 75%.
B. Yes, because 192 is greater than half of 320.
C. No, because 3 × 192 is less than 2 × 320.
D. It depends only on the proposer’s personal balance.

B10 · 查看答案与解析

Q10 · C · Count weight, not heads

推理过程:题设用 effective balance(有效余额)计权,所以分子取支持者权重 192,分母取总权重 320。192 ÷ 320 = 60%,小于三分之二,选 C。A 用了人数比例,B 降低门槛到过半,D 把全体权重替换成提议者自己的余额,都改变了题意。

Working: 192 / 320 = 60%; 3 × 192 = 576 < 640 = 2 × 320. The stated threshold is not met.

中文:人数 75% 不能代替有效余额权重 60%;简单过半也不是至少三分之二。这里仅判该链接的门槛,不把“过门槛”直接等同 finalized。回查:L02 p.100-104、p.122 及校订。

B11 · Q11 Dynamic-array storage [2 marks]

An isolated contract declares uint128 a; uint128 b; uint256[] data; in this order. There is no inheritance or custom storage base. What occupies slot 1?

A. The first element of data.
B. b by itself.
C. The hash of the first element.
D. The array length; elements begin at the hash-derived location.

B11 · 查看答案与解析

Q11 · D · The main slot stores length

推理过程:按声明顺序排:a 占 16 字节,b 也占 16,正好填满容量 32 字节的 slot 0。动态数组另开主槽 1,主槽记 length(长度),所以选 D;首元素位置要按主槽号哈希计算,不是简单的下一槽。B 忘了紧凑打包,A、C 则把主槽和元素数据位置混在一起。

English: The two uint128 values fit in slot 0. The dynamic array’s main slot is 1 and stores its length. For uint256 elements, data[i] is at the hash-derived base plus i.

中文:基址为 uint256(keccak256(abi.encode(uint256(1)))),不是 slot 2;data 不是被挤进 slot 0 的指针。槽地址在 256 位空间内计算。回查:L05 p.7-15。

B12 · Q12 Delegated execution [2 marks]

An EOA calls Router. Router makes a normal call to Proxy, which uses delegatecall to Logic. While Logic’s code is running, what are msg.sender and address(this)?

A. Router; Proxy
B. EOA; Logic
C. Proxy; Logic
D. EOA; Router

B12 · 查看答案与解析

Q12 · A · Router; Proxy

推理过程:画出两种箭头:EOA CALL Router → Router CALL Proxy → Proxy DELEGATECALL Logic。第二步普通调用让 Proxy 看到 msg.sender = Router;第三步委托调用借代码、保留该现场,所以 sender 仍为 Router,address(this) 仍为 Proxy。答案是 A,不是把最外层 EOA 或代码提供方 Logic 填进去。

English: Delegation preserves the sender seen by Proxy, which is Router. Logic’s code executes in Proxy’s address and storage context.

中文:“保留 msg.sender”不等于“永远是最外层 EOA”。CALL 先把 Proxy 看到的 sender 设成 Router;DELEGATECALL 再保留这个值。回查:L05 p.16-23;调用上下文补充。

B13 · Q13 Copy versus alias [2 marks]

A state array initially contains [4, 5]. A function sets its first element to 8 through a storage alias, then copies the resulting array into memory and sets the copy’s second element to 9. The function succeeds without writing the copy back. What is the state array?

A. [4, 9]
B. [8, 9]
C. [8, 5]
D. [4, 5]

B13 · 查看答案与解析

Q13 · C · [8, 5]

推理过程:按两份数据列状态:原件 [4, 5] → storage 引用修改后 [8, 5];接着 memory 复制得到 [8, 5] → 副本修改后 [8, 9]。题目问链上原件,且没有写回副本,所以选 C。A、B 把副本修改写回了原件;D 忽略了第一步确实改了 storage。

English: The storage alias changes persistent state. The later memory assignment changes only a copy, so the second state element remains 5.

中文:若整笔执行回滚则另当别论,但本题明确成功且没有把副本写回。回查:L04b p.17。

B14 · Q14 Selecting an entry point [2 marks]

A contract has both a payable receive and a payable fallback. A call carries ETH and nonempty calldata whose selector matches no function. Both handlers would succeed. Which entry point runs?

A. fallback.
B. Both handlers, in declaration order.
C. receive, because ETH is attached.
D. The constructor.

B14 · 查看答案与解析

Q14 · A · Fallback

推理过程:依次检查:calldata 非空 → selector 不匹配任何函数 → 选择 fallback,故 A 正确。payable 表示该入口允许随调用收 ETH,并不让 receive 自动优先;所以 C 错。分派不会把两个入口都执行,B 错;constructor 在部署时执行,D 也不符。

English: The nonempty calldata does not match a function selector, so fallback is selected. Having receive does not redirect this nonempty call to receive.

中文:不能只看“带 ETH”。本题已给 fallback payable、执行成功、gas 足够,排除了接收失败的其他因素。回查:L04b p.29-31。

B15 · Q15 One-time authorization [2 marks]

An application correctly verifies an EIP-712 signer and domain. The signed message contains an authorization nonce, but the contract never checks or records whether it was used. Which change directly addresses repeated use of the same authorization?

A. Keep only the signature; remove the message fields.
B. Add a private keyword to the signature variable.
C. Rely on each relayer transaction having a fresh transaction nonce.
D. Check and consume the application’s authorization nonce before unsafe external interactions, while retaining signer and domain checks.

B15 · 查看答案与解析

Q15 · D · Enforce freshness in the application

推理过程:重放者每次可用新交易序号发送交易,却夹带同一份旧业务授权。若合约仍不查授权编号,旧签名还会通过。D 直接补上“核验编号、成功路径记为已用”;A 删除字段不补使用记录,B private 不提供一次性,C 混淆交易 nonce 与应用授权 nonce。

English: The contract must enforce the signed authorization’s nonce and consume it on the successful path before unsafe interactions. A fresh relayer transaction nonce does not make the enclosed authorization fresh.

中文:EIP-712 提供类型化签名与域分隔,不会自动创建业务一次性语义。签了 nonce 却不核对/记录,仍能重放;若本次交易回滚,nonce 消费也回滚。回查:L05 p.56-62 及补充。

下一页 →
Q08 期中模拟卷 B|机制与应用 16-20

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