← COMP5565 全部讲次
Q12

期末练习|B 短题

期末自拟练习,英文题干,逐题折叠中文解析、英文参考答案与课件页码。

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

使用边界:期末自拟练习,非官方材料。没有往年期末卷可对照,题型、分值和时长只是练习安排;正式范围、题型、时长和开闭卷要求以讲师通知为准。题干全部自拟;课件与官方文档说法不同时按课件作答,并在解析里注明差异。

复习资料:范围与以太坊、Solidity 要点 · Fabric 与选型要点 · 必背与闪卡

先做题再看解析:A 单选题 · B 短题 · C 长题

统一约定:Solidity 为 0.8.x,默认检查算术溢出;Fabric 题按课件的读写集与版本模型。页码一律用 PDF 页序。

练习安排:10 题共 36 分,建议 45 分钟。

自查分值仅供练习,不代表教师评分标准;先作答,再展开每题答案。

来源代号:L02 = Lecture2.pdf;L03 = Lecture3.pdf;L04b = Lecture 4.1.pdf;L05 = Lecture 5.pdf;L06 = Lecture 6 - v3.pdf;L07 = Lecture 7.pdf;L08 = Lecture 8.pdf。来源为对应逐讲注解。

B · 短题

共 36 分。用 point form 英文作答,每题标分值;先写出课件里的关键词。

B1 · The Fabric ledger · 3 marks

A Fabric ledger has two components. Name them, state what each holds, and say which one determines the other.

B1 · 查看答案与解析

Suggested answer:

  • World state: a database of the current value of each key, stored as key-value pairs with a version.
  • Blockchain: the transaction log, an append-only chain of blocks recording every transaction that led to the current state.
  • The blockchain determines the world state; the world state can be rebuilt by replaying the blockchain.

推理过程:世界状态回答「现在是多少」,区块链回答「怎么变成这样」。世界状态丢了可以从区块链重放出来,反过来不行。

自查分值:三点各 1 分。回查:L06 p.32–36。

B2 · Block structure · 3 marks

List the three fields of a Fabric block header, and state what the block metadata contains according to the slides.

B2 · 查看答案与解析

Suggested answer:

  • Block number
  • Current block hash: hash of all transactions in this block
  • Previous block header hash
  • Block metadata: the certificate and signature of the block creator (the orderer)

推理过程:区块头只哈希交易和上一块的头,前一块头哈希把区块串成链。课件 vs 官方:课件只写元数据含出块者证书和签名;官方文档里每笔交易的 valid/invalid 标记也记在元数据里。

自查分值:三个头字段共 2 分,元数据 1 分。回查:L06 p.39–41。

B3 · Two checks at validation · 4 marks

In the validate phase, a committing peer runs two checks on each transaction. Name both, say what each compares, and state what happens to a transaction that fails either check.

B3 · 查看答案与解析

Suggested answer:

  • Endorsement policy check: the endorsers’ signatures are valid and the set of endorsing organisations satisfies the endorsement policy.
  • Version (MVCC) check: every key in the read set still has the same version in the current world state.
  • A transaction that fails either check is marked invalid. It stays in the block but its writes are not applied.

推理过程:第一项查「背书够不够、真不真」,第二项查「读到的数据有没有过期」。两项都由每个 peer 在验证阶段独立做,排序节点不做。

自查分值:每项检查 1.5 分,失败后果 1 分。回查:L06 p.23、p.54、p.77、p.89。

B4 · Non-determinism and EOV · 4 marks

  1. A chaincode is non-deterministic. Explain what happens with a single endorser and with several endorsers. (2)
  2. Give two other advantages of execute-order-validate over order-execute. (2)
B4 · 查看答案与解析

Suggested answer:

  1. One endorser: its result is accepted, because committers do not re-execute. Several endorsers: their results differ, the endorsements do not match, and the transaction is not submitted.
  2. Any two: general-purpose programming languages; concurrent simulation; committing peers do not re-execute; chaincode confidentiality (only endorsers need the code); flexible trust; pluggable consensus.

推理过程:先执行后排序时,非确定性只会在背书节点之间暴露;只有一个背书方时没有比较对象,结果被直接采用。

自查分值:第 1 问每种情形 1 分,第 2 问每点 1 分。回查:L06 p.84–86。

B5 · Verifying a certificate · 4 marks

A peer receives a certificate from another party. List four checks it should make before trusting the public key inside.

B5 · 查看答案与解析

Suggested answer:

  • Verify the CA’s signature on the certificate with the issuer’s public key.
  • Follow the chain of trust up to a trusted root CA.
  • Check that the current time is within the validity period.
  • Check the issuing CA’s CRL to confirm the certificate has not been revoked.

推理过程:签名证明内容没改、确实由该 CA 签发;链条证明这个 CA 本身可信;有效期和 CRL 排除过期与吊销。四关是综合几页得出的,课件没有单页列成清单。

自查分值:每点 1 分。回查:L07 p.12–13、p.17–18、p.58。

B6 · Fabric CA identities · 4 marks

  1. Distinguish register from enroll in Fabric CA. (2)
  2. Compare the effect of an expired organisation CA admin certificate with an expired peer enrollment certificate. (2)
B6 · 查看答案与解析

Suggested answer:

  1. Register: a CA admin creates an identity record with an enrollment ID, a secret and a type; no certificate is issued yet. Enroll: the identity uses the ID and secret, generates its private key locally, and receives a CA-signed certificate.
  2. Expired CA admin certificate: the admin cannot register new identities, but transaction traffic continues. Expired peer enrollment certificate: production outage; the peer cannot start or endorse.

推理过程:register 由管理员做,只建记录;enroll 由身份自己做,私钥不离开本地。过期影响看证书用途:管理员证书只管注册新身份,peer 证书每次背书都要用。

自查分值:每小问 2 分。回查:L07 p.48、p.51、p.55。

B7 · Data locations · 3 marks

For storage, memory and calldata, state where the data lives and whether it can be modified.

B7 · 查看答案与解析

Suggested answer:

  • storage: state variables, kept on chain, modifiable.
  • memory: function arguments and temporary variables, not on chain, modifiable, discarded after the call.
  • calldata: input data of external calls, not on chain, cannot be modified, cheapest in gas.

推理过程:先问「上不上链」,再问「能不能改」。引用类型的参数要显式写数据位置。

自查分值:每种 1 分。回查:L04b p.17。

B8 · Upgrading behind a proxy · 4 marks

A proxy forwards calls to Logic V1 by delegatecall. The team deploys Logic V2 and points the proxy to it.

  1. Whose storage does V2’s code write? (1)
  2. Why must V2 keep V1’s state variables in the same order? (2)
  3. What does EIP-1967 do with the implementation address? (1)
B8 · 查看答案与解析

Suggested answer:

  1. The proxy’s storage.
  2. Storage slots are assigned by declaration order. V2’s code reads and writes slots by position, so reordering or inserting variables makes V2 misread old data. New variables go after the old ones.
  3. It stores the implementation address in a special slot so that it does not clash with the logic contract’s variables.

推理过程:delegatecall 在代理的上下文里执行,数据一直留在代理里,换掉的只有代码。新代码按槽位号读旧数据,布局一变就会读错槽。

自查分值:1 + 2 + 1。回查:L05 p.16–17、p.25。

B9 · Error handling · 3 marks

When should a contract use require, assert and a custom error? What happens to state changes when one of them fails?

B9 · 查看答案与解析

Suggested answer:

  • require: validate external input and conditions (the caller made a mistake).
  • assert: check internal invariants that should never fail (the code has a bug).
  • Custom error with revert: cheapest in gas and can carry parameters (since 0.8).
  • On failure, all state changes of the call and its sub-calls are reverted; gas already used is not refunded.

推理过程:三者分工按「谁错了」区分。回滚保证原子性,但已经花掉的 gas 不退。

自查分值:三种用法共 2 分,回滚 1 分。回查:L04b p.55–59。

B10 · Signature replay · 4 marks

A contract pays whoever submits a message signed by the owner.

  1. Describe the two kinds of replay attack in the slides. (2)
  2. Give a defence, and the checks the contract itself must enforce for it to work. (2)
B10 · 查看答案与解析

Suggested answer:

  1. Ordinary replay: the same signed message is submitted again to the same contract. Cross-chain replay: the same signed message is used on another chain where the contract is also deployed.
  2. Include a nonce and the chain id in the signed message, or record used signatures. The contract must check that the nonce is unused and mark it used after success, and check the chain id against the current chain.

推理过程:签名有效只说明 owner 签过,不说明这次授权还没被用过。EIP-712 让消息结构化、可读,但标准本身不带重放保护,nonce 要由应用设计、由合约检查。

自查分值:每小问 2 分。回查:L05 p.60–64。

作答后怎么复盘

对照参考答案逐点打勾,缺的关键词用英文补写一遍。分值只是练习安排,重点看漏掉了哪个课件术语。

下一页 →
Q13 期末练习|C 长题

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