@@ -188,66 +188,57 @@ contract FluiDexDemo is AccessControl, IFluiDex, Ownable, ReentrancyGuard {
188188 }
189189
190190 /**
191- * @notice to test a block can be submitted or not, this require the block itself
192- * is valid, and be consistent with state root list
193- * @param _public_inputs the public inputs of this block
194- * @param _serialized_proof the serialized proof of this block
195- * @param _public_data the serialized tx data inside this block (data availability)
196- * @return true if the block can be submitted
191+ * @notice request to submit a new l2 block, same parameters with verifySubmitting
192+ * @return true if the block was accepted
197193 */
198- function verifySubmitting (
194+ function submitBlock (
199195 uint256 _block_id ,
200196 uint256 [] memory _public_inputs ,
201197 uint256 [] memory _serialized_proof ,
202198 bytes memory _public_data
203- ) public view returns (bool ) {
204- // _public_inputs[0] is previous_state_root
205- // _public_inputs[1] is new_state_root
199+ ) external override returns (bool ) {
206200 require (_public_inputs.length >= 2 );
207201 if (_block_id == 0 ) {
208202 assert (_public_inputs[0 ] == GENESIS_ROOT);
209203 } else {
210204 assert (_public_inputs[0 ] == state_roots[_block_id - 1 ]);
211205 }
212206
213- return verifyBlock (_public_inputs, _serialized_proof, _public_data);
214- }
215-
216- /**
217- * @notice request to submit a new l2 block, same parameters with verifySubmitting
218- * @return true if the block was accepted
219- */
220- function submitBlock (
221- uint256 _block_id ,
222- uint256 [] memory _public_inputs ,
223- uint256 [] memory _serialized_proof ,
224- bytes memory _public_data
225- ) external override returns (bool ) {
226- require (
227- block_states[_block_id] != BlockState.Verified,
228- "Block must not be submitted twice "
229- );
230- if (_block_id > 0 ) {
231- require (
232- block_states[_block_id - 1 ] == BlockState.Verified,
233- "Previous block must be verified "
207+ if (_serialized_proof.length != 0 ) {
208+ bool ret = verifyBlock (
209+ _public_inputs,
210+ _serialized_proof,
211+ _public_data
234212 );
235- }
236213
237- bool ret = verifySubmitting (
238- _block_id,
239- _public_inputs,
240- _serialized_proof,
241- _public_data
242- );
214+ if (! ret) {
215+ return ret;
216+ }
243217
244- if (! ret) {
245- return ret;
218+ if (_block_id > 0 ) {
219+ require (
220+ block_states[_block_id - 1 ] == BlockState.Verified,
221+ "Previous block must be verified "
222+ );
223+ }
224+ require (
225+ block_states[_block_id] != BlockState.Verified,
226+ "Block must not be submitted twice "
227+ );
228+ block_states[_block_id] = BlockState.Verified;
229+ } else {
230+ // mark a block as Committed directly, because we may
231+ // temporarily run out of proving resource.
232+ // note: Committing a block without a rollback/revert mechanism should
233+ // only happen in demo version!
234+ if (_block_id > 0 ) {
235+ assert (block_states[_block_id - 1 ] != BlockState.Empty);
236+ }
237+ assert (block_states[_block_id] == BlockState.Empty);
238+ block_states[_block_id] = BlockState.Committed;
246239 }
247240
248241 state_roots[_block_id] = _public_inputs[1 ];
249- block_states[_block_id] = BlockState.Verified;
250-
251242 return true ;
252243 }
253244
0 commit comments