Skip to content

Commit

Permalink
Set prevarandao when block updated (#101)
Browse files Browse the repository at this point in the history
  • Loading branch information
zombie-einstein authored Mar 26, 2024
1 parent e50bb9f commit 92d8dc8
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
7 changes: 4 additions & 3 deletions crates/verbs_rs/src/env/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ mod validator;
use crate::contract::{Event, Transaction};
use crate::utils::Eth;
use crate::{ForkDb, LocalDB, RequestCache, DB};
use alloy_primitives::{Address, B256, U256};
use alloy_primitives::{Address, FixedBytes, B256, U256};
use alloy_sol_types::SolCall;
use log::debug;
use rand::Rng;
Expand Down Expand Up @@ -220,11 +220,12 @@ impl<D: DB, V: Validator> Env<D, V> {
}
}

/// Increment block number and time
pub fn increment_time(&mut self, interval: u64) {
/// Increment block number, time and prevarando
pub fn increment_time<R: Rng>(&mut self, rng: &mut R, interval: u64) {
let state = self.evm_state();
state.context.evm.env.block.timestamp += U256::from(interval);
state.context.evm.env.block.number += U256::from(1);
state.context.evm.env.block.prevrandao = Some(FixedBytes(rng.gen::<[u8; 32]>()));
}

/// Insert a user account into the DB
Expand Down
2 changes: 1 addition & 1 deletion crates/verbs_rs/src/sim_runner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ pub fn run<S: SimState, D: DB, V: Validator>(
// Update all agents
let transactions = agents.call_agents(&mut rng, env);
// Update the block-time and number
env.increment_time(BLOCK_INTERVAL);
env.increment_time(&mut rng, BLOCK_INTERVAL);
// Process calls in order
env.process_transactions(transactions, &mut rng, i);
// Record data from agents
Expand Down
2 changes: 1 addition & 1 deletion rust/src/sim/base_env.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ impl<V: Validator> BaseEnv<ForkDb, V> {
impl<D: DB, V: Validator> BaseEnv<D, V> {
pub fn process_block(&mut self) {
// Update the block-time and number
self.env.increment_time(BLOCK_INTERVAL);
self.env.increment_time(&mut self.rng, BLOCK_INTERVAL);
// Clear events from last block
self.env.clear_events();
// Shuffle and process calls
Expand Down

0 comments on commit 92d8dc8

Please sign in to comment.