Skip to content

Commit a1bdc61

Browse files
authored
add minimum batch size check to updateRange (#49)
* forge install: openzeppelin-contracts-upgradeable v5.0.2 * wip UUPS * forge install: openzeppelin-contracts v5.0.2 * update test and deployment for new proxy pattern * forge fmt * bump blobstream contracts * update manual command address * Add upgradability utils * update docs for ownership commands * remove forge script for maintainability * add println for CLI upgrade * add minimum batch size check to updateRange
1 parent fd94732 commit a1bdc61

File tree

7 files changed

+84
-25
lines changed

7 files changed

+84
-25
lines changed

.env.local

+1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ ETH_ADDRESS=0xe7f1725E7734CE288F8367e1Bb143E90bb3F0512
66
PRIVATE_KEY_HEX=0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80
77

88
BATCH_SIZE=64
9+
MIN_BATCH_SIZE=7
910

1011
TENDERMINT_RPC=https://celestia-testnet.brightlystake.com
1112
TM_HEIGHT=9

cli/src/main.rs

+5
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ struct DeployArgs {
111111
#[clap(long, env)]
112112
tm_block_hash: String,
113113

114+
/// Minimum batch size for head updates. The batch size must be larger than this value.
115+
#[clap(long, env)]
116+
min_batch_size: u64,
117+
114118
/// If deploying verifier, will it deploy the mock verifier
115119
#[clap(long)]
116120
dev: bool,
@@ -207,6 +211,7 @@ async fn main() -> anyhow::Result<()> {
207211
_verifier: verifier_address,
208212
_trustedHash: FixedBytes::<32>::from_hex(deploy.tm_block_hash)?,
209213
_trustedHeight: deploy.tm_height,
214+
_minBatchSize: deploy.min_batch_size,
210215
}
211216
.abi_encode()
212217
.into(),

cli/tests/e2e_test.rs

+1
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ async fn e2e_basic_range() -> anyhow::Result<()> {
101101
_verifier: verifier.address().clone(),
102102
_trustedHash: trusted_block_hash,
103103
_trustedHeight: BATCH_START as u64 - 1,
104+
_minBatchSize: 0,
104105
}
105106
.abi_encode()
106107
.into(),

contracts/artifacts/Blobstream0.json

+57-17
Large diffs are not rendered by default.

contracts/src/Blobstream0.sol

+14-5
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@ contract Blobstream0 is IDAOracle, Initializable, UUPSUpgradeable, Ownable2StepU
5656
/// @notice Trusted block hash does not equal the commitment from the new batch.
5757
error InvalidTrustedHeaderHash();
5858

59+
/// @notice Minimum number of blocks required for a valid batch update. The batch size must be
60+
/// larger than this value.
61+
/// @dev This is to ensure there is no DOS condition from doing single/small batch updates.
62+
uint64 public minBatchSize;
63+
5964
/// @notice RISC Zero verifier contract address.
6065
IRiscZeroVerifier public verifier;
6166

@@ -85,10 +90,13 @@ contract Blobstream0 is IDAOracle, Initializable, UUPSUpgradeable, Ownable2StepU
8590
/// @dev DO NOT REMOVE! It is mandatory for upgradability.
8691
function _authorizeUpgrade(address newImplementation) internal override onlyOwner {}
8792

88-
function initialize(address _admin, IRiscZeroVerifier _verifier, bytes32 _trustedHash, uint64 _trustedHeight)
89-
public
90-
initializer
91-
{
93+
function initialize(
94+
address _admin,
95+
IRiscZeroVerifier _verifier,
96+
bytes32 _trustedHash,
97+
uint64 _trustedHeight,
98+
uint64 _minBatchSize
99+
) public initializer {
92100
__Ownable_init(_admin);
93101
__Ownable2Step_init();
94102
__UUPSUpgradeable_init();
@@ -97,6 +105,7 @@ contract Blobstream0 is IDAOracle, Initializable, UUPSUpgradeable, Ownable2StepU
97105
latestBlockHash = _trustedHash;
98106
latestHeight = _trustedHeight;
99107
imageId = ImageID.LIGHT_CLIENT_GUEST_ID;
108+
minBatchSize = _minBatchSize;
100109

101110
// Proof nonce initialized as 1 to maintain compatibility with existing implementations and
102111
// avoid default value confusion.
@@ -123,7 +132,7 @@ contract Blobstream0 is IDAOracle, Initializable, UUPSUpgradeable, Ownable2StepU
123132
function updateRange(bytes calldata _commitBytes, bytes calldata _seal) external {
124133
RangeCommitment memory commit = abi.decode(_commitBytes, (RangeCommitment));
125134

126-
if (commit.newHeight <= latestHeight) {
135+
if (commit.newHeight <= latestHeight + minBatchSize) {
127136
revert InvalidTargetHeight();
128137
}
129138
if (commit.trustedHeaderHash != latestBlockHash) {

contracts/src/ImageID.sol

+1-1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,5 @@ pragma solidity ^0.8.20;
2020

2121
library ImageID {
2222
bytes32 public constant LIGHT_CLIENT_GUEST_ID =
23-
bytes32(0x30878c4c4fce996894bd391bad03495861edd2381461948834355849c1db637a);
23+
bytes32(0x6dce022c2aea568a4484a24c36aa59bad7b10186205272b4e4f11157c9ad1421);
2424
}

usage-guide.md

+5-2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ RUST_LOG=info cargo run -p blobstream0 -- deploy \
1717
--private-key-hex 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
1818
--tm-height 9 \
1919
--tm-block-hash 5C5451567973D8658A607D58F035BA9078291E33D880A0E6E67145C717E6B11B \
20+
--min-batch-size 7 \
2021
--dev
2122
```
2223

@@ -56,7 +57,8 @@ RUST_LOG=info,blobstream0=debug cargo run -p blobstream0 -- deploy \
5657
--eth-rpc http://127.0.0.1:8545 \
5758
--private-key-hex 0xac0974bec39a17e36ba4a6b4d238ff944bacb478cbed5efcae784d7bf4f2ff80 \
5859
--tm-height 9 \
59-
--tm-block-hash 5C5451567973D8658A607D58F035BA9078291E33D880A0E6E67145C717E6B11B
60+
--tm-block-hash 5C5451567973D8658A607D58F035BA9078291E33D880A0E6E67145C717E6B11B \
61+
--min-batch-size 7
6062
```
6163

6264
### Sepolia
@@ -74,7 +76,8 @@ RUST_LOG=info,blobstream0=debug cargo run -p blobstream0 -- deploy \
7476
--private-key-hex <ADD KEY HERE> \
7577
--tm-height 1802142 \
7678
--tm-block-hash 6D8FD8ADC8FBD5E7765EC557D9DF86041F63F9109202A888D8D246B3BCC3B46A \
77-
--verifier-address 0x925d8331ddc0a1F0d96E68CF073DFE1d92b69187
79+
--verifier-address 0x925d8331ddc0a1F0d96E68CF073DFE1d92b69187 \
80+
--min-batch-size 7
7881
```
7982

8083
Run the service with `RISC0_DEV_MODE=true` if you chose the mock verifier.

0 commit comments

Comments
 (0)