-
Notifications
You must be signed in to change notification settings - Fork 191
Custom fee detector #1284
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Custom fee detector #1284
Changes from 9 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4a0eb32
hip-0000.md
littletarzan 23a1e0a
Generalized Schedule Contract Call
littletarzan 63e7e1a
Merge branch 'main' into main
littletarzan fd75ffd
Merge branch 'hiero-ledger:main' into main
littletarzan 407ad0e
Merge branch 'hiero-ledger:main' into custom-fee-detector
littletarzan 5953d4e
first draft custom fee
littletarzan ab98b5a
selector
littletarzan b9d3909
fix created and discussions-to
littletarzan 6582ac6
Update and rename hip-0000.md to hip-1284.md and headers
mgarbs a03dd65
threshold and list keys
littletarzan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,91 @@ | ||
| --- | ||
| hip: 1284 | ||
| title: HTS Custom Fee Schedule Detector Precompile | ||
| author: Matthew DeLorenzo (@littletarzan), Michael Tinker (@tinker-michaelj) | ||
| requested-by: Lambdaplex | ||
| type: Standards Track | ||
| category: Service | ||
| needs-hiero-approval: Yes | ||
| needs-hedera-review: Yes | ||
| hedera-review-date: | ||
| hedera-approval-status: | ||
| status: Review | ||
| created: 2025-09-15 | ||
| discussions-to: https://github.com/hiero-ledger/hiero-improvement-proposals/discussions/1271 | ||
| updated: 2025-09-17 | ||
| --- | ||
|
|
||
| ## Abstract | ||
| This HIP proposes a Hedera Smart Contract Service (HSCS) system contract function that allows a smart contract to determine whether a Hedera Token Service (HTS) token contains a `customFeeSchedule` and/or a non-empty `customFeeScheduleKey`. This information is critical for smart contracts to safely interact with tokens without risk of unintended token transfers caused by malicious fee schedules. | ||
|
|
||
| ## Motivation | ||
| While custom fee schedules are a powerful feature of HTS, they may be exploited maliciously in decentralized applications. If a smart contract accepts an HTS token with a complex or malicious fee schedule, and subsequently performs a token transfer via HAPI or precompile, it may unknowingly incur additional fee payments — including the unauthorized transfer of **other unrelated tokens** held by the contract. | ||
|
|
||
| This poses a serious threat to dApps and DeFi protocols which hold multiple tokens in their balance map. For example, if a smart contract accepts a token with a fee schedule that references an unrelated token or imposes a high collector fee, any token transfer operation might inadvertently transfer the unrelated token to a third-party address. | ||
|
|
||
| This HIP enables developers to **proactively reject token associations** that present this threat by allowing contracts to detect `customFeeSchedules` and non-empty `customFeeScheduleKeys`. | ||
|
|
||
| ## Rationale | ||
| This proposal adds support to a `IHederaTokenService.sol` that can be called from smart contracts to query the `customFeeSchedule` and `customFeeScheduleKey` of any HTS token. Any presence of a `customFeeSchedule` or non-empty `customFeeScheduleKey` should be detected and returned. | ||
| The precompile would return the following: | ||
|
|
||
| - Whether the token has a non-empty `customFeeSchedule` | ||
| - Whether the token has a non-zero `customFeeScheduleKey` | ||
|
|
||
| By doing so, developers can build safer and more robust smart contracts that **refuse to interact with unsafe tokens** or alert administrators when unexpected configurations are found. | ||
|
|
||
| ## User Stories | ||
| 1. As a dApp developer, I want to prevent tokens with malicious fee schedules from being deposited into my contract. | ||
| 2. As a protocol admin, I want to audit the fee characteristics of incoming tokens. | ||
| 3. As a security engineer, I want on-chain detection of potentially exploitable token configurations. | ||
|
|
||
| ## Specification | ||
|
|
||
| ### System Contract Interface | ||
| This HIP introduces a new precompile interface: | ||
|
|
||
| ```solidity | ||
| interface IHederaTokenService { | ||
| function detectCustomFees(address token) external view returns ( | ||
| bool hasCustomFeeSchedule, | ||
| bool hasCustomFeeScheduleKey | ||
| ); | ||
| } | ||
| ``` | ||
|
|
||
|
|
||
| ### Selector Table | ||
|
|
||
| | Hash | Selector | | ||
| |---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ||
| | `0x2e0f2625` | `detectCustomFees(address token) returns (bool hasCustomFeeSchedule, bool hasCustomFeeScheduleKey)` | | ||
|
|
||
|
|
||
| ## Backwards Compatibility | ||
| This HIP introduces new functionality via precompile and does not change any existing behavior. | ||
|
|
||
| ## Security Implications | ||
| This precompile is intended to mitigate security risks by enabling better detection of malicious or risky tokens. It does not introduce new risks when implemented correctly. | ||
|
|
||
| ## How to Teach This | ||
| This HIP should be taught as a safety precompile for developers building DeFi and token-interactive smart contracts. Teaching materials should include: | ||
| • Examples of malicious token configurations | ||
| • Walkthrough of how to reject unsafe tokens using this precompile | ||
| • Integration with existing token gating or access control systems | ||
|
|
||
| ## Reference Implementation | ||
| TBD. A sample contract using IHederaTokenService.detectCustomFees() can be provided to show how a contract rejects a token if either boolean is true. | ||
|
|
||
| ## Rejected Ideas | ||
| • Using off-chain detection (not trustless) | ||
| • Whitelisting tokens (not scalable or dynamic) | ||
|
|
||
| ## Open Issues | ||
| • Should this precompile expose full fee schedule data? | ||
| • Should fallback fee info be included for royalty fees? | ||
|
|
||
| ## References | ||
|
|
||
| ## Copyright/license | ||
| This document is licensed under the Apache License, Version 2.0 — | ||
| see [LICENSE](../LICENSE) or <https://www.apache.org/licenses/LICENSE-2.0>. | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using booleans here, it seems like a contract might eagerly reject a token with a reasonable fee schedule. Better safe than sorry, but this might cause other issues for legitimate tokens.
That said, how much information is it appropriate to expose?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@mgh14 A major concern I have is that a legitimate token with a reasonable custom fee schedule can be changed by the fee schedule key to become arbitrarily unreasonable, hence why I am looking for a boolean
hasCustomFeeScheduleKey.IHederaTokenService.sol does return the custom fee schedule, but the boolean would be helpful if the goal is to reject all custom fee tokens (https://github.com/hashgraph/hedera-smart-contracts/blob/2e7c67fe3e0306e660a767028dc2f61379033580/contracts/system-contracts/hedera-token-service/IHederaTokenService.sol#L651)