Skip to content
On this page

S2C3: Access Key

1. Problem

The contract requires the caller to provide an "access key" to call mintFlag. The access key is generated by a specific computation.

2. Cause

The contract's access key verification logic has a vulnerability — the key computation depends on predictable on-chain data (such as block.timestamp, blockhash, etc.), and these values are known at transaction execution time.

3. Solution

Deploy an attack contract that computes the access key in its constructor and immediately calls mintFlag. Since the computation and usage in the constructor occur within the same transaction, all on-chain state is consistent.

4. Pitfalls Encountered

Timing Dependency: The key may depend on block.timestamp and similar values, requiring computation and usage within the same transaction.

5. Why the Pitfall Occurred

The contract's key generation depends on certain attributes of the current block. If split across two transactions, block attributes may change, causing the key to not match.

6. How to Resolve

Complete all operations in a single transaction (deploy + compute key + call mintFlag), ensuring all on-chain state is consistent.

7. Technical Takeaways

PointExplanation
AtomicityDeployment and attack completed in the same transaction, ensuring state consistency
On-chain Data Predictabilityblock.timestamp, blockhash, etc. can be known by the attacker at transaction execution time

Built with AiAda