Repository navigation
Conversation
…act replay in STRK delegation (F-01, F-07)
### Summary of Changes
Addresses **F-01 (Critical)** and **F-07 (High)** from the Starknet Workspace Security Audit in `starkgate-contracts`:
- **Complete `u256` Limb Commitment in EIP-712 Signatures (F-01):**
- Updated `lock_and_delegate_input_hash` in `eip712_utils.cairo` to hash both `amount.low` and `amount.high`.
- Previously, only `amount.low` was hashed, allowing an attacker with a signature for amount $X$ to forge a valid delegation transaction for $X + k \cdot 2^{128}$.
- Updated the EIP-712 type string to `LockAndDelegateRequest(delegatee:felt,amount:u256,nonce:felt,expiry:felt)` and recomputed `LOCK_AND_DELEGATE_TYPE_HASH` to `0x34747b0d2887193758ab94a43ee8a024d452a894901af5ca548b220fab47397`.
- **Verifying Contract Address Binding in Domain Separator (F-07):**
- Included `get_contract_address().into()` in `calc_domain_hash()` to bind the EIP-712 domain to the specific deployed contract instance.
- Prevents cross-contract and cross-chain replay of lock-and-delegate signatures across testnets, forks, or different deployments.
- Recomputed `STARKNET_DOMAIN_TYPE_HASH` to `0xca98cfb7dd7f8905a216be4121e5183d688a00106289a1547b8bc15b38461`.
- **Spender Validation Hardening (F-20):**
- Added `assert(spender.is_non_zero(), Errors::ZERO_ADDRESS);` in `approve_l1_address` to prevent zero-address approvals during rescue operations.
- **Allowance Saturation:**
- In `_increase_account_allowance`, saturated the allowance to `Bounded::MAX` if `current_allowance + amount` exceeds `u256::MAX`.
### Operational & Deployment Notice
> **Breaking Change:** This update alters both the message and domain hashes. Existing signatures issued under the old scheme will fail validation. Contract redeployment is required because `domain_hash` is initialized in the constructor and stored immutably in contract storage. Off-chain keepers and front-end signers must be updated in lockstep.
### Affected Files
- `packages/strk/src/eip712_utils.cairo`
- `packages/strk/src/erc20_lockable.cairo`
### Verification
```bash
# Verify build and integration tests
scarb --release build
snforge test
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary of Changes
Addresses F-01 (Critical) and F-07 (High) from the Starknet Workspace Security Audit in
starkgate-contracts:Complete
u256Limb Commitment in EIP-712 Signatures (F-01):lock_and_delegate_input_hashineip712_utils.cairoto hash bothamount.lowandamount.high.amount.lowwas hashed, allowing an attacker with a signature for amountLockAndDelegateRequest(delegatee:felt,amount:u256,nonce:felt,expiry:felt)and recomputedLOCK_AND_DELEGATE_TYPE_HASHto0x34747b0d2887193758ab94a43ee8a024d452a894901af5ca548b220fab47397.Verifying Contract Address Binding in Domain Separator (F-07):
get_contract_address().into()incalc_domain_hash()to bind the EIP-712 domain to the specific deployed contract instance.STARKNET_DOMAIN_TYPE_HASHto0xca98cfb7dd7f8905a216be4121e5183d688a00106289a1547b8bc15b38461.Spender Validation Hardening (F-20):
assert(spender.is_non_zero(), Errors::ZERO_ADDRESS);inapprove_l1_addressto prevent zero-address approvals during rescue operations.Allowance Saturation:
_increase_account_allowance, saturated the allowance toBounded::MAXifcurrent_allowance + amountexceedsu256::MAX.Operational & Deployment Notice
Affected Files
packages/strk/src/eip712_utils.cairopackages/strk/src/erc20_lockable.cairoVerification