NFT refactor -> replace pk with sk#469
NFT refactor -> replace pk with sk#469andrew-fleming wants to merge 12 commits intoOpenZeppelin:mainfrom
Conversation
|
Important Review skippedAuto incremental reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
WalkthroughThe NonFungibleToken contract's identity scheme was refactored from ChangesNonFungibleToken Identity Migration
Estimated code review effort🎯 4 (Complex) | ⏱️ ~60 minutes Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Comment |
There was a problem hiding this comment.
Actionable comments posted: 2
🧹 Nitpick comments (1)
contracts/src/token/witnesses/test/NonFungibleTokenWitnesses.test.ts (1)
81-89: ⚡ Quick winAssert that
wit_NonFungibleTokenSKreturns a defensive copy.These cases only verify equality and shape. They would still pass if the witness returned
context.privateState.secretKeydirectly, which would let callers mutate the stored key through the witness result.Proposed test addition
describe('wit_NonFungibleTokenSK', () => { it('should return a tuple of [privateState, secretKey]', () => { const state = NonFungibleTokenPrivateState.withSecretKey(SECRET_KEY); const ctx = makeContext(state); const [returnedState, returnedSK] = witnesses.wit_NonFungibleTokenSK(ctx); expect(returnedState).toBe(state); expect(returnedSK).toEqual(SECRET_KEY); }); + + it('should return a defensive copy of the secret key', () => { + const state = NonFungibleTokenPrivateState.withSecretKey(SECRET_KEY); + const ctx = makeContext(state); + + const [, returnedSK] = witnesses.wit_NonFungibleTokenSK(ctx); + returnedSK.fill(0xff); + + expect(state.secretKey).toEqual(SECRET_KEY); + });Also applies to: 99-116
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@contracts/src/token/witnesses/test/NonFungibleTokenWitnesses.test.ts` around lines 81 - 89, Update the test for wit_NonFungibleTokenSK to assert the function returns defensive copies instead of references: after calling wit_NonFungibleTokenSK(ctx) (using NonFungibleTokenPrivateState.withSecretKey and makeContext), verify that returnedSK is equal in value to SECRET_KEY but not the same reference (e.g., mutating returnedSK does not change state.secretKey), and similarly assert returnedState is not the identical object as the context private state (mutating returnedState does not alter ctx.privateState); focus on wit_NonFungibleTokenSK, NonFungibleTokenPrivateState.withSecretKey, and makeContext to locate the code under test.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@contracts/src/token/NonFungibleToken.compact`:
- Around line 798-816: The approve flow stores a non-canonical zero when
Utils_canonicalize preserves a right-branch zero, causing getApproved to return
a different value than ZERO(); in _approve, after computing canonTo (from
Utils_canonicalize<Bytes<32>, ContractAddress>(to)) normalize any zero approval
to the canonical ZERO() representation before inserting into _tokenApprovals:
detect the zero case (compare disclose(canonTo) to the zero contract/bytes) and
set the value to ZERO() so _tokenApprovals.insert(disclose(tokenId), ...) always
stores canonical ZERO(), keeping getApproved, _isAuthorized and external API
consistent.
- Around line 145-149: The exported circuit ZERO() is declared without purity,
causing a pure caller (MockNonFungibleToken's export pure circuit ZERO() which
calls NonFungibleToken_ZERO()) to violate Compact's purity rules; change the
declaration of ZERO in NonFungibleToken.compact to be pure (i.e., export pure
circuit ZERO()) so that the symbol ZERO / NonFungibleToken_ZERO() is marked pure
and can be called from MockNonFungibleToken's pure ZERO() and accessed via
this.circuits.pure.ZERO() without compilation errors.
---
Nitpick comments:
In `@contracts/src/token/witnesses/test/NonFungibleTokenWitnesses.test.ts`:
- Around line 81-89: Update the test for wit_NonFungibleTokenSK to assert the
function returns defensive copies instead of references: after calling
wit_NonFungibleTokenSK(ctx) (using NonFungibleTokenPrivateState.withSecretKey
and makeContext), verify that returnedSK is equal in value to SECRET_KEY but not
the same reference (e.g., mutating returnedSK does not change state.secretKey),
and similarly assert returnedState is not the identical object as the context
private state (mutating returnedState does not alter ctx.privateState); focus on
wit_NonFungibleTokenSK, NonFungibleTokenPrivateState.withSecretKey, and
makeContext to locate the code under test.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: 7f7ee2b0-423e-410b-ac30-cce92af5c2cb
📒 Files selected for processing (6)
contracts/src/token/NonFungibleToken.compactcontracts/src/token/test/mocks/MockNonFungibleToken.compactcontracts/src/token/test/nonFungibleToken.test.tscontracts/src/token/test/simulators/NonFungibleTokenSimulator.tscontracts/src/token/witnesses/NonFungibleTokenWitnesses.tscontracts/src/token/witnesses/test/NonFungibleTokenWitnesses.test.ts
Types of changes
What types of changes does your code introduce to OpenZeppelin Midnight Contracts?
Put an
xin the boxes that applyFixes #456
Summary by CodeRabbit
New Features
Bug Fixes