Skip to content

Commit 5c63d89

Browse files
update README with new command version, refine oracle descriptions, and adjust checkpoint numbering; add note on unstaking in StakingOracle contract
1 parent 3d751a5 commit 5c63d89

File tree

2 files changed

+53
-53
lines changed

2 files changed

+53
-53
lines changed

README.md

Lines changed: 51 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Oracles are bridges between blockchains and the external world. They solve a fun
5656

5757
```sh
5858

59-
npx [email protected].4 -e scaffold-eth/se-2-challenges:challenge-oracles challenge-oracles
59+
npx create-eth@1.0.2 -e scaffold-eth/se-2-challenges:challenge-oracles challenge-oracles
6060

6161
cd challenge-oracles
6262

@@ -102,33 +102,7 @@ yarn start
102102

103103
💰 The implementation we'll be looking at is a **price** oracle. Price oracles are one of the most common and critical types of oracles in DeFi, as they enable smart contracts to make decisions based on real-world asset prices. Our whitelist price oracle collects price reports from multiple trusted sources (instances of `SimpleOracle`) and returns their median value.
104104

105-
🗂️ The whitelist oracle contracts are located in `packages/hardhat/contracts/00_Whitelist/`. Go check them out and reference the following descriptions.
106-
107-
### Core Components
108-
109-
1. 🔗 **SimpleOracle (`SimpleOracle.sol`)**
110-
111-
- Basic oracle contract that allows price updates from the contract owner (We have commented out the onlyOwner modifier to allow you to impersonate the owner)
112-
113-
- Each SimpleOracle instance represents one trusted data source
114-
115-
2. 🏛️ **WhitelistOracle (`WhitelistOracle.sol`)**
116-
117-
- Central contract that aggregates multiple SimpleOracle contracts
118-
119-
- Only the owner can add/remove SimpleOracle contracts from the whitelist (We have commented out the onlyOwner modifier to allow you to impersonate the owner)
120-
121-
- Uses median calculation for consensus among whitelisted sources
122-
123-
- Filters out stale data to ensure freshness
124-
125-
- Simple architecture but requires trust in the whitelist authority
126-
127-
---
128-
129-
## Checkpoint 2: 🔗 Simple Oracle & Whitelist Oracle - Building Blocks & Aggregation
130-
131-
🧭 Let's understand how oracle systems are built from simple components and then aggregated for better reliability. We'll examine both the basic building block (SimpleOracle) and how multiple simple oracles can be combined into a more robust system (WhitelistOracle).
105+
🧭 Let's understand how this oracle system works. We'll examine both the basic building block (SimpleOracle) and how multiple simple oracles can be combined into a more robust system (WhitelistOracle).
132106

133107
### 🔗 Simple Oracle - The Building Block
134108

@@ -278,7 +252,7 @@ WhitelistOracle → getPrice() → [100, 102, 98] → median(100) → 100
278252

279253
</details>
280254

281-
👊 **Manual Testing**: Try manually changing the price of individual SimpleOracle contracts and adding new oracle nodes to see how the aggregated price changes:
255+
👊 **Manual Testing**: Notice how the onlyOwner modifiers are commented out to allow you to have full control. Try manually changing the price of individual SimpleOracle contracts and adding new oracle nodes to see how the aggregated price changes:
282256

283257
1. **Change Prices**: Use the frontend to modify individual oracle prices
284258

@@ -304,7 +278,7 @@ yarn simulate:whitelist
304278
- Look at these examples "in the wild" from early DeFi: [Simple Oracle](https://github.com/dapphub/ds-value), [Whitelist Oracle](https://github.com/sky-ecosystem/medianizer)
305279
---
306280

307-
## Checkpoint 3: 💰 Staking Oracle - Economic Incentives
281+
## Checkpoint 2: 💰 Staking Oracle - Economic Incentives
308282

309283
🧭 Now let's explore a decentralized oracle that uses economic incentives to ensure honest behavior. Nodes stake ETH to participate and can be slashed for bad behavior. We will also issue rewards in the form of an ERC20 token called ORA to incentivise participation in the system.
310284

@@ -407,13 +381,26 @@ yarn simulate:staking
407381
- Understand how economic incentives drive honest behavior
408382
- See how slashing mechanisms enforce data freshness
409383
- Observe the decentralized nature of the system
410-
- Recognize the trade-offs and risks associated with type of oracle
384+
- Recognize the trade-offs and risks associated with this type of oracle
385+
- Oracles that require staking include [Chainlink](https://chain.link) and [PYTH](https://www.pyth.network/)
411386

412387
---
413388

414-
## Checkpoint 4: 🧠 Optimistic Oracle Architecture
389+
## Checkpoint 3: 🧠 Optimistic Oracle Architecture
390+
391+
🤿 Now let's dive into the most sophisticated of this challenge's three designs: the **Optimistic Oracle**. Unlike the previous two designs that focus on price data, this one will handle any type of binary (true/false) question about real-world events.
392+
393+
🎯 **What makes it "optimistic"?** The system assumes proposals are correct unless someone disputes them. This creates a game-theoretic mechanism where economic incentives encourage honest behavior while providing strong security guarantees through dispute resolution.
394+
395+
💡 **Key Innovation**: Instead of requiring constant active participation from multiple parties (like staking oracles), optimistic oracles only require intervention when something goes wrong. This makes them highly efficient for events that don't need frequent updates.
396+
397+
🔍 **Real-World Applications**:
398+
- **Cross-chain bridges**: "Did transaction X happen on chain Y?"
399+
- **Insurance claims**: "Did flight ABC get delayed by more than 2 hours?"
400+
- **Prediction markets**: "Did candidate X win the election?"
401+
- **DeFi protocols**: "Did token X reach price Y on date Z?"
415402

416-
🧭 Before coding, understand the flow at a glance.
403+
🧭 Before coding, let's understand the flow at a glance.
417404

418405
**Roles**:
419406
- **asserter**: posts an assertion + reward
@@ -429,23 +416,28 @@ yarn simulate:staking
429416
- Reward + bonds flow to the winner; a fixed fee goes to the decider in disputes
430417

431418
```mermaid
419+
432420
sequenceDiagram
433421
participant A as Asserter
434422
participant P as Proposer
435423
participant D as Disputer
436424
participant C as Decider
437425
participant O as OptimisticOracle
438-
439426
A->>O: assertEvent(description, startTime, endTime) + reward
440427
Note over O: Wait until startTime
441-
P->>O: proposeOutcome(assertionId, outcome) + bond
442-
Note over O: Start dispute window
443-
alt No dispute before deadline
444-
O-->>P: Claim undisputed rewards -> reward + proposer bond
445-
else Dispute filed in window
446-
D->>O: disputeOutcome(assertionId) + bond
447-
C->>O: settleAssertion(assertionId, resolvedOutcome)
448-
O-->>Winner: claimDisputedReward() -> reward + both bonds - decider fee
428+
alt No proposal before endTime
429+
A->>O: claimRefund(assertionId)
430+
O-->>A: refund reward
431+
else Proposal received
432+
P->>O: proposeOutcome(assertionId, outcome) + bond
433+
Note over O: Start dispute window
434+
alt No dispute before deadline
435+
O-->>P: Claim undisputed rewards -> reward + proposer bond
436+
else Dispute filed in window
437+
D->>O: disputeOutcome(assertionId) + bond
438+
C->>O: settleAssertion(assertionId, resolvedOutcome)
439+
O-->>Winner: claimDisputedReward() -> reward + both bonds - decider fee
440+
end
449441
end
450442
```
451443

@@ -455,19 +447,25 @@ sequenceDiagram
455447
- Before a specific deadline
456448
- With a reward
457449

450+
🦗 If no one answers before the end of the assertion window, the asserter can claim a refund.
451+
458452
💡 If someone knows the answer within the correct time then they **propose** the answer, posting a bond. This bond is a risk to them because if their answer is thought to be wrong by someone else then they might lose it. This keeps people economically tied to the **proposals** they make.
459453

460-
⏳ Then if no one **disputes** the proposal before the dispute window is over then the proposal is considered to be true. The dispute window should give anyone ample time to submit a dispute.
454+
⏳ Then if no one **disputes** the proposal before the dispute window is over then the proposal is considered to be true, and the proposer may claim the reward and their bond. The dispute window should give anyone ample time to submit a dispute.
461455

462456
⚖️ If someone does **dispute** during the dispute window then they must also post a bond equal to the proposer's bond. This kicks the assertion out of any particular timeline and puts it in a state where it is waiting for a decision from the **decider**. Once the decider contract has **settled** the assertion, the winner can claim the reward and both of the bonds that were posted, subtracting a small fee that goes to the decider.
463457

464458
🧑‍⚖️ Now, as we mentioned earlier, this oracle has a role called the **decider**. For this example it is just a simple contract that anyone can call to settle disputes. One could imagine in a live oracle you would want something more robust such as a group of people who vote to settle disputes.
465459

466460
🔗 Look at how [UMA](https://uma.xyz/) does this with their Optimistic Oracle (OO). **This contract is based UMA's OO design**.
467461

468-
## Checkpoint 5: ⚡ Optimistic Oracle - Dispute Resolution
462+
## Checkpoint 4: ⚡ Optimistic Oracle - Dispute Resolution
463+
464+
👩‍💻 Now it's (finally) time to build! Unlike the previous checkpoints where you explored existing implementations, this section challenges you to implement the optimistic oracle system from scratch. You'll write the core functions that handle assertions, proposals, disputes, and settlements.
465+
466+
🎯 **Your Mission**: Complete the missing function implementations in the `OptimisticOracle.sol` contract. The contract skeleton is already provided with all the necessary structs, events, and modifiers - you just need to fill in the logic.
469467

470-
⚙️ Now let's implement the most sophisticated oracle design: the optimistic oracle. This system allows anyone to propose outcomes and others to dispute them, with a decider contract resolving disputes. This is the main implementation challenge where you'll build the core functionality from scratch.
468+
🧪 **Testing Strategy**: Each function you implement can be tested individually using the provided test suite. Run `yarn test` after implementing each function to verify your solution works correctly.
471469

472470
🔍 Open the `packages/hardhat/contracts/02_Optimistic/OptimisticOracle.sol` file to implement the optimistic oracle functionality.
473471

@@ -971,7 +969,7 @@ yarn simulate:optimistic
971969

972970
```
973971

974-
🤖 This will start automated bots that create assertions, propose outcomes, dispute proposals, and settle via the decider, so you can observe rewards, bonds, fees, and timing windows in a realistic flow.
972+
🤖 This will start automated bots that create assertions, propose outcomes, and dispute proposals, so you can observe rewards, bonds, fees, and timing windows in a realistic flow. It is up to you to settle disputes!
975973

976974
### 🥅 Goals:
977975

@@ -983,7 +981,7 @@ yarn simulate:optimistic
983981
- Bond amounts are properly validated
984982
---
985983

986-
## Checkpoint 6: 🔍 Oracle Comparison & Trade-offs
984+
## Checkpoint 5: 🔍 Oracle Comparison & Trade-offs
987985

988986
🧠 Now let's analyze the strengths and weaknesses of each oracle design.
989987

@@ -992,7 +990,7 @@ yarn simulate:optimistic
992990
|--------|------------------|----------------|-------------------|
993991
| **Speed** | Fast | Medium | Slow |
994992
| **Security** | Low (trusted authority) | Medium (economic incentives) | High (dispute resolution) |
995-
| **Decentralization** | Low | High | Medium |
993+
| **Decentralization** | Low | High | Depends on Decider Implementation |
996994
| **Cost** | Low | Medium | High |
997995
| **Complexity** | Simple | Medium | Complex |
998996

@@ -1024,7 +1022,7 @@ yarn simulate:optimistic
10241022

10251023
- ✅ Can be used for any type of data (not just prices)
10261024

1027-
- ✴️ Decider role is the weakest link and should be carefully implemented
1025+
- ✴️ Decider role is the weakest link and should be carefully implemented though it is up to the consuming application whether it wants to wait for a resolution or post another assertion and hope a proposal passes without dispute
10281026

10291027
- ❌ Higher latency
10301028

@@ -1040,7 +1038,7 @@ Each oracle design solves different problems:
10401038

10411039
---
10421040

1043-
## Checkpoint 7: 💾 Deploy your contracts! 🛰
1041+
## Checkpoint 6: 💾 Deploy your contracts! 🛰
10441042

10451043
🎉 Well done on building the optimistic oracle system! Now, let's get it on a public testnet.
10461044

@@ -1058,7 +1056,7 @@ Each oracle design solves different problems:
10581056
10591057
---
10601058

1061-
## Checkpoint 8: 🚢 Ship your frontend! 🚁
1059+
## Checkpoint 7: 🚢 Ship your frontend! 🚁
10621060

10631061
✏️ Edit your frontend config in `packages/nextjs/scaffold.config.ts` to change the `targetNetwork` to `chains.sepolia` (or your chosen deployed network).
10641062

@@ -1091,7 +1089,7 @@ For production-grade applications, it's recommended to obtain your own API keys
10911089
10921090
---
10931091

1094-
## Checkpoint 9: 📜 Contract Verification
1092+
## Checkpoint 8: 📜 Contract Verification
10951093

10961094
📝 Run the `yarn verify --network your_network` command to verify your optimistic oracle contracts on Etherscan 🛰.
10971095

@@ -1105,7 +1103,7 @@ For production-grade applications, it's recommended to obtain your own API keys
11051103
11061104
> 💬 Problems, questions, comments on the stack? Post them to the [🏗 scaffold-eth developers chat](https://t.me/joinchat/F7nCRK3kI93PoCOk)
11071105
1108-
## Checkpoint 10: More On Oracles
1106+
## Checkpoint 9: More On Oracles
11091107

11101108
Oracles are fundamental infrastructure for the decentralized web. They enable smart contracts to interact with real-world data, making blockchain applications truly useful beyond simple token transfers.
11111109

packages/hardhat/contracts/01_Staking/StakingOracle.sol

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,4 +185,6 @@ contract StakingOracle {
185185
function getNodeAddresses() public view returns (address[] memory) {
186186
return nodeAddresses;
187187
}
188+
189+
// Notably missing a way to unstake and exit your node but not needed for the challenge
188190
}

0 commit comments

Comments
 (0)