Skip to content
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

(Contracts): Handle Proofs #176

Open
memarin opened this issue Jan 16, 2025 · 1 comment
Open

(Contracts): Handle Proofs #176

memarin opened this issue Jan 16, 2025 · 1 comment

Comments

@memarin
Copy link

memarin commented Jan 16, 2025

Once Fossil is ready to send proofs, adjust client contract as needed.

Pt1

The expected flow is that Fossil will first send the results through a verifier. If the proof verification is a success, the data is then transferred to the client (and then the correct vault). This means we can remove all references of proofs in the Client contract (since they will be handled before the data reaches this contract). We should also adjust the naming of the variables in the contract from fossil_processor to fossil_verifier to better reflect this logic.

Pt2

We will also need to make an adjustment to the callback logic. Currently, the Client::fossil_callback(request, result) function takes in the (serialized) request & result objects like so:

fn fossil_callback(request: Span<felt252>, result: Span<felt252>);

struct JobRequest {
    vault_address: ContractAddress, // Which vault is this request for
    timestamp: u64, // The timestamp the results are for
    program_id: felt252, // // 'PITCH_LAKE_V1' 
} // serialized is: [vault_address, timestamp, program_id]

struct FossilResult {
    l1_data: L1Data, // TWAP, volatility, reserve price
    ~~proof: Span<felt252>~~, // Was for proof data but can remove now
} 

struct L1Data {
    twap: u256,
    volatility: u128,
    reserve_price: u256,
} // serialized is: [TWAP.low, TWAP.high, volatility, reserve_price.low, reserve_price.high]

The fossil_callback function verifies that the program_id matches whats expected, then sends the L1 data and timestamp to the corresponding vault address like this:

fn fossil_client_callback(l1_data: L1Data, timestamp: u64);

This allows the vault to verify that the L1 data is ok (timestamp matches the expected to_timestamp) before it is saved for round settlement. The issue with this approach is that the L1 data (3 data points) is calculated on various intervals (TWAP is a calculated over 1 month, reserve price and vol are both calculated over 3 months). This means the vault can verify the L1 data’s to_timestamp, but cannot verify the L1 data’s from_timestamps.

This means we need to modify the structs so that Fossil sends the from timestamps (not just the to timestamp) to the client contract. Then we need to modify the Vault::fossil_client_callback function to accept these new params, and check them in the functions assertions. This will also require an update to the off chain processing repo as well.

  • We can also probably simplify the structs since we no longer need to wrap the L1Data and proof into the same struct.

Tasks:

@memarin
Copy link
Author

memarin commented Jan 16, 2025

@0xDegenDeveloper let me know which repo should I add contracts related issues

@dhruv035 dhruv035 transferred this issue from OilerNetwork/pitchlake-ui-new Jan 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant