Skip to content

Conversation

@mmackz
Copy link
Contributor

@mmackz mmackz commented May 11, 2025

Description

Allows for 4-byte function signatures in incentive criteria. This is so it is consistent with the claimant and actionsteps signature which also allows 4-byte format. Anytime a 4-byte function signature is provided, we automatically pad it to the required 32-bytes.

Related PR:
Allow 4-byte signature in claimant and actionsteps: #375

Summary by CodeRabbit

  • Bug Fixes

    • Improved encoding to accept 4-byte function selectors in incentive criteria, ensuring reliable deployment and correct on-chain representation for ERC20-based variable criteria incentives.
  • Tests

    • Added coverage verifying successful deployment and that encoded signatures are 32-byte values ending with the provided 4-byte selector.
  • Chores

    • Published a patch version of the SDK with a changeset entry describing the update.

@changeset-bot
Copy link

changeset-bot bot commented May 11, 2025

🦋 Changeset detected

Latest commit: 055e8cd

The changes in this PR will be included in the next version bump.

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

💥 An error occurred when fetching the changed packages and changesets in this PR
Some errors occurred when validating the changesets config:
The package or glob expression "@boostxyz/test" is specified in the `ignore` option but it is not found in the project. You may have misspelled the package name or provided an invalid glob expression. Note that glob expressions must be defined according to https://www.npmjs.com/package/micromatch.

@github-actions github-actions bot added the SDK label May 11, 2025
@mmackz mmackz changed the title Matthew/boost 5517 allow 4byte selectors in criteria [BOOST-5517] allow 4byte function selectors in incentive criteria May 11, 2025
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 52e07b2

1 similar comment
@sammccord
Copy link
Contributor

Warnings
⚠️

Are you sure you want to be submitting a change without including a changeset? If you're just changing docs or tests, you probably don't need to. See the publishing section of the README for more info.

Generated by 🚫 dangerJS against 52e07b2

@coderabbitai
Copy link

coderabbitai bot commented Sep 9, 2025

Walkthrough

Patched incentive payload encoding to pad criteria.signature to 32 bytes, enabling 4‑byte function selectors in ERC20 variable/pegged criteria (V1 and V2). Added tests validating deployment and stored signature format/suffix. Added a changeset to bump @boostxyz/sdk with a patch note. No public APIs changed.

Changes

Cohort / File(s) Summary
Incentive payload encoding (pad signature)
packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts, .../ERC20PeggedVariableCriteriaIncentiveV2.ts, .../ERC20VariableCriteriaIncentive.ts, .../ERC20VariableCriteriaIncentiveV2.ts
Import pad from viem and apply pad(criteria.signature) when building criteria, changing encoded signature to a 32‑byte padded value. No exported signatures modified.
Tests for 4‑byte selector support
packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.test.ts, .../ERC20VariableCriteriaIncentiveV2.test.ts
Add tests that deploy incentives using a 4‑byte function selector, then assert deployed criteria.signature is 32‑byte hex and ends with the provided selector.
Changeset
.changeset/chilly-buses-itch.md
Add patch release note for @boostxyz/sdk describing allowance of 4‑byte function selectors in criteria.

Sequence Diagram(s)

sequenceDiagram
  participant Dev as SDK caller
  participant SDK as SDK Incentive Builder
  participant viem as viem.pad
  participant Chain as Chain/Contracts

  Dev->>SDK: prepare...CriteriaIncentive(V1/V2) with 4-byte selector
  SDK->>viem: pad(criteria.signature)
  viem-->>SDK: 32-byte padded signature
  SDK->>Chain: deploy Boost with encoded criteria (padded signature)
  Chain-->>Dev: deployed incentive address
  Dev->>Chain: read incentive criteria
  Chain-->>Dev: criteria.signature (0x + 64 hex, ends with 4-byte selector)
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10–15 minutes

Pre-merge checks (4 passed, 1 warning)

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Description Check ⚠️ Warning The current description provides a clear summary of the change under the “Description” heading but omits the repository’s contribution guidelines link at the top and the closing thank-you note specified in the template. It also lacks the boilerplate reference to the contributing guidelines that the template requires. Please add the “🚨 Please review the guidelines for contributing” boilerplate at the top of the description and include the “💔 Thank you!” note at the end to fully adhere to the repository’s PR template.
✅ Passed checks (4 passed)
Check name Status Explanation
Title Check ✅ Passed The title “[BOOST-5517] allow 4byte function selectors in incentive criteria” clearly and concisely summarizes the main change by indicating the pull request’s objective of supporting four-byte selectors in incentive criteria and includes the relevant issue number for traceability. It is specific to the changes made and avoids unnecessary detail.
Linked Issues Check ✅ Passed The changes update the incentive criteria payload functions to pad four-byte signatures to 32 bytes and include corresponding tests, fulfilling the linked issue’s requirement to allow four-byte selectors in criteria for both V1 and V2 incentives (BOOST-5517). All coding requirements specified in the issue are implemented and verified by tests.
Out of Scope Changes Check ✅ Passed All modifications are directly related to padding four-byte function selectors in incentive criteria, including necessary changes in payload encoding and tests, with no unrelated files or logic altered beyond the objective.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

Poem

A nibble of hex and a hop on the chain,
I padded four bytes to a 32-byte lane.
Selectors now cozy, snug in their bed,
Boosts deploy happily—enough said.
Thump goes my paw, tests green and bright,
Onward we bound through the gas-lit night! 🐇✨

Tip

👮 Agentic pre-merge checks are now available in preview!

Pro plan users can now enable pre-merge checks in their settings to enforce checklists before merging PRs.

  • Built-in checks – Quickly apply ready-made checks to enforce title conventions, require pull request descriptions that follow templates, validate linked issues for compliance, and more.
  • Custom agentic checks – Define your own rules using CodeRabbit’s advanced agentic capabilities to enforce organization-specific policies and workflows. For example, you can instruct CodeRabbit’s agent to verify that API documentation is updated whenever API schema files are modified in a PR. Note: Upto 5 custom checks are currently allowed during the preview period. Pricing for this feature will be announced in a few weeks.

Example:

reviews:
  pre_merge_checks:
    custom_checks:
      - name: "Undocumented Breaking Changes"
        mode: "warning"
        instructions: |
          Pass/fail criteria: All breaking changes to public APIs, CLI flags, environment variables, configuration keys, database schemas, or HTTP/GraphQL endpoints must be documented in the "Breaking Change" section of the PR description and in CHANGELOG.md. Exclude purely internal or private changes (e.g., code not exported from package entry points or explicitly marked as internal).

Please share your feedback with us on this Discord post.

✨ Finishing Touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch matthew/boost-5517-allow-4byte-selectors-in-criteria

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (3)
packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.ts (1)

503-509: Only pad for FUNC; avoid silently accepting invalid EVENT signatures.

Unconditionally padding criteria.signature will also “accept” 4-byte values for EVENT criteria, which should remain 32-byte topics. That’s a silent correctness footgun vs. prior behavior (which would reject non-32B EVENT signatures). Pad only for SignatureType.FUNC and pass EVENT signatures through unchanged. Also be explicit about pad size/dir for future viem changes.

Apply:

-          signature: pad(criteria.signature),
+          signature:
+            criteria.criteriaType === SignatureType.FUNC
+              ? pad(criteria.signature, { size: 32, dir: 'left' })
+              : criteria.signature,
packages/sdk/src/Incentives/ERC20VariableCriteriaIncentive.ts (1)

431-437: Do not pad EVENT signatures; restrict padding to FUNC.

Maintain strictness for EVENT topics and pad only FUNC selectors. This restores prior validation behavior and avoids misconfigured criteria slipping through.

-          signature: pad(criteria.signature),
+          signature:
+            criteria.criteriaType === SignatureType.FUNC
+              ? pad(criteria.signature, { size: 32, dir: 'left' })
+              : criteria.signature,
packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts (1)

846-852: Pad only FUNC selectors; preserve strictness for EVENT topics.

Mirrors the required guard in other payload builders.

-          signature: pad(criteria.signature),
+          signature:
+            criteria.criteriaType === SignatureType.FUNC
+              ? pad(criteria.signature, { size: 32, dir: 'left' })
+              : criteria.signature,
🧹 Nitpick comments (3)
.changeset/chilly-buses-itch.md (1)

1-6: Changeset present and scoped correctly.

Patch for @boostxyz/sdk looks good and matches the PR intent. Consider briefly noting “pads 4-byte function selectors to bytes32 in criteria payloads” to make the changelog a touch clearer.

-allow 4-byte function selectors in incentive criteria
+Allow 4-byte function selectors in incentive criteria by padding to bytes32 in payloads
packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.test.ts (1)

275-302: Good coverage for 4-byte selector acceptance.

Nice assertions on length (66) and suffix match; this guards the left-pad invariant without over-constraining. You could factor this into a small helper if duplicated elsewhere.

packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.test.ts (1)

362-390: Test mirrors non-pegged variant well.

Checks are appropriate and keep us honest on the bytes32 padding semantics.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

💡 Knowledge Base configuration:

  • Linear integration is disabled by default for public repositories

You can enable these sources in your CodeRabbit configuration.

📥 Commits

Reviewing files that changed from the base of the PR and between 9115319 and 055e8cd.

📒 Files selected for processing (7)
  • .changeset/chilly-buses-itch.md (1 hunks)
  • packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts (2 hunks)
  • packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.test.ts (1 hunks)
  • packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.ts (2 hunks)
  • packages/sdk/src/Incentives/ERC20VariableCriteriaIncentive.ts (2 hunks)
  • packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.test.ts (1 hunks)
  • packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.ts (2 hunks)
🧰 Additional context used
🧬 Code graph analysis (2)
packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.test.ts (3)
test/src/helpers.ts (1)
  • freshBoost (123-157)
packages/sdk/src/BoostCore.ts (1)
  • ERC20PeggedVariableCriteriaIncentiveV2 (2105-2114)
packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.ts (1)
  • ERC20PeggedVariableCriteriaIncentiveV2 (147-868)
packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.test.ts (3)
test/src/helpers.ts (1)
  • freshBoost (123-157)
packages/sdk/src/BoostCore.ts (1)
  • ERC20VariableCriteriaIncentiveV2 (2082-2091)
packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.ts (1)
  • ERC20VariableCriteriaIncentiveV2 (132-418)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
  • GitHub Check: Use Case Tests / Use Case Tests
  • GitHub Check: Verify / Verify
  • GitHub Check: danger
🔇 Additional comments (4)
packages/sdk/src/Incentives/ERC20VariableCriteriaIncentiveV2.ts (1)

17-17: Import change is fine.

Adding pad from viem is expected for the new behavior.

packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentiveV2.ts (1)

32-32: Import addition looks good.

packages/sdk/src/Incentives/ERC20VariableCriteriaIncentive.ts (1)

16-16: Import addition is appropriate.

packages/sdk/src/Incentives/ERC20PeggedVariableCriteriaIncentive.ts (1)

32-32: Import addition is fine.

Comment on lines 924 to 930
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Guard EVENT topics; pad only FUNC selectors.

Same rationale as the V2 variable file: keep EVENT topics strict 32B; pad 4B only for FUNC. Make pad explicit.

-          signature: pad(criteria.signature),
+          signature:
+            criteria.criteriaType === SignatureType.FUNC
+              ? pad(criteria.signature, { size: 32, dir: 'left' })
+              : criteria.signature,
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature: criteria.signature,
signature: pad(criteria.signature),
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,
maxReward,
criteria: {
criteriaType: criteria.criteriaType,
signature:
criteria.criteriaType === SignatureType.FUNC
? pad(criteria.signature, { size: 32, dir: 'left' })
: criteria.signature,
fieldIndex: criteria.fieldIndex,
targetContract: criteria.targetContract,
valueType: criteria.valueType,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants