Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
85 changes: 22 additions & 63 deletions contracts/artifacts/Blobstream0.json

Large diffs are not rendered by default.

23 changes: 14 additions & 9 deletions contracts/src/Blobstream0.sol
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ contract Blobstream0 is IDAOracle, Ownable2Step {
/// (in this case, checking if a number is even) are considered valid.
bytes32 public imageId = ImageID.LIGHT_CLIENT_GUEST_ID;

/// @notice nonce for mapping block ranges to block merkle roots. This value is used as the key
/// to insert new roots in `merkleRoots`.
uint256 public proofNonce;

/// @notice The latest height validated.
Expand All @@ -78,6 +80,8 @@ contract Blobstream0 is IDAOracle, Ownable2Step {
latestBlockHash = _trustedHash;
latestHeight = _trustedHeight;

// Proof nonce initialized as 1 to maintain compatibility with existing implementations and
// avoid default value confusion.
proofNonce = 1;
}

Expand All @@ -98,27 +102,28 @@ contract Blobstream0 is IDAOracle, Ownable2Step {
}

/// @notice Validate a proof of a new header range, update state.
function updateRange(RangeCommitment memory _commit, bytes calldata _seal) external {
if (_commit.newHeight <= latestHeight) {
function updateRange(bytes calldata _commitBytes, bytes calldata _seal) external {
RangeCommitment memory commit = abi.decode(_commitBytes, (RangeCommitment));

if (commit.newHeight <= latestHeight) {
revert InvalidTargetHeight();
}
if (_commit.trustedHeaderHash != latestBlockHash) {
if (commit.trustedHeaderHash != latestBlockHash) {
revert InvalidTrustedHeaderHash();
}

bytes memory journal = abi.encode(_commit);
bytes memory journal = abi.encode(commit);
verifier.verify(_seal, imageId, sha256(journal));

emit DataCommitmentStored(proofNonce, latestHeight, _commit.newHeight, _commit.merkleRoot);
emit DataCommitmentStored(proofNonce, latestHeight, commit.newHeight, commit.merkleRoot);

// Update latest block in state
latestHeight = _commit.newHeight;
latestBlockHash = _commit.newHeaderHash;
latestHeight = commit.newHeight;
latestBlockHash = commit.newHeaderHash;
emit HeadUpdate(latestHeight, latestBlockHash);

// Set merkle root to monotomically increasing nonce. This is kept as is for compatibility
// with alternative versions.
merkleRoots[proofNonce] = _commit.merkleRoot;
merkleRoots[proofNonce] = commit.merkleRoot;
proofNonce++;
}

Expand Down
2 changes: 1 addition & 1 deletion contracts/src/ImageID.sol
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,5 @@ pragma solidity ^0.8.20;

library ImageID {
bytes32 public constant LIGHT_CLIENT_GUEST_ID =
bytes32(0x875f9439fc8f3867440498d0ff8a7074bd5dc5122f6fb0dfa2431a638b9d0ab6);
bytes32(0x6a4fc32c0f294d805c6e97a6a973775c567bdc586ec19a4c6026edc6f7a19f0c);
}
8 changes: 3 additions & 5 deletions core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ use alloy_sol_types::SolValue;
use anyhow::Context;
use blobstream0_primitives::{
proto::{TrustedLightBlock, UntrustedLightBlock},
IBlobstream::{IBlobstreamInstance, RangeCommitment},
LightBlockProveData,
IBlobstream::IBlobstreamInstance,
LightBlockProveData, RangeCommitment,
};
use light_client_guest::LIGHT_CLIENT_GUEST_ELF;
use risc0_ethereum_contracts::groth16;
Expand Down Expand Up @@ -231,10 +231,8 @@ where
false => groth16::encode(receipt.inner.groth16()?.seal.clone())?,
};

let range_commitment = RangeCommitment::abi_decode(&receipt.journal.bytes, true)?;

let res = contract
.updateRange(range_commitment, seal.into())
.updateRange(receipt.journal.bytes.clone().into(), seal.into())
.send()
.await?
.watch()
Expand Down
2 changes: 1 addition & 1 deletion light-client-guest/guest/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

use alloy_sol_types::SolValue;
use blobstream0_primitives::proto::{TrustedLightBlock, UntrustedLightBlock};
use blobstream0_primitives::IBlobstream::RangeCommitment;
use blobstream0_primitives::RangeCommitment;
use blobstream0_primitives::{build_merkle_root, expect_block_hash, light_client_verify};
use risc0_zkvm::guest::env;
use tendermint_light_client_verifier::{types::Header, Verdict};
Expand Down
3 changes: 3 additions & 0 deletions primitives/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ mod abi {
IBlobstream,
"../contracts/artifacts/Blobstream0.json"
);

sol!("../contracts/src/RangeCommitment.sol");
}
pub use abi::IBlobstream;
pub use abi::RangeCommitment;

mod prove_data;
pub use prove_data::LightBlockProveData;
Expand Down
4 changes: 2 additions & 2 deletions usage-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ Start the service:

```
RISC0_DEV_MODE=true RUST_LOG=blobstream0=debug,info cargo run -p blobstream0 -- service \
--tendermint-rpc https://rpc.celestia-mocha.com \
--tendermint-rpc https://celestia-testnet.brightlystake.com \
--eth-rpc http://127.0.0.1:8545/ \
--eth-address 0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512 \
--private-key-hex 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
Expand Down Expand Up @@ -81,7 +81,7 @@ Run the service with `RISC0_DEV_MODE=true` if you chose the mock verifier.

```
RUST_LOG=blobstream0=debug,info cargo run -p blobstream0 --release -- service \
--tendermint-rpc https://rpc.celestia-mocha.com \
--tendermint-rpc https://celestia-testnet.brightlystake.com \
--eth-rpc https://ethereum-sepolia-rpc.publicnode.com \
--eth-address <BLOBSTREAM ADDRESS FROM DEPLOY> \
--private-key-hex <ADD KEY HERE> \
Expand Down