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
Original file line number Diff line number Diff line change
Expand Up @@ -332,7 +332,7 @@ export class GenesisBlockGenerator extends Generator {
proposer,
reward: BigNumber.ZERO,
round: 0,
stateRoot: await this.evm.stateHash(
stateRoot: await this.evm.stateRoot(
commitKey,
options.snapshot?.snapshotHash ??
"0000000000000000000000000000000000000000000000000000000000000000",
Expand Down
2 changes: 1 addition & 1 deletion packages/contracts/source/contracts/evm/instance.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ export interface Instance extends CommitHandler {
calculateRoundValidators(context: CalculateRoundValidatorsContext): Promise<void>;
updateRewardsAndVotes(context: UpdateRewardsAndVotesContext): Promise<void>;
logsBloom(commitKey: CommitKey): Promise<string>;
stateHash(commitKey: CommitKey, currentHash: string): Promise<string>;
stateRoot(commitKey: CommitKey, currentHash: string): Promise<string>;
codeAt(address: string, height?: bigint): Promise<string>;
storageAt(address: string, slot: bigint): Promise<string>;
snapshot(commitKey: CommitKey): Promise<void>;
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-block/source/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
4 + // height
4 + // round
hashByteLength + // previousBlock
hashByteLength + // stateHash
hashByteLength + // stateRoot

Check warning on line 30 in packages/crypto-block/source/index.ts

View check run for this annotation

Codecov / codecov/patch

packages/crypto-block/source/index.ts#L30

Added line #L30 was not covered by tests
256 + // logsBloom
2 + // transactionsCount
4 + // totalGasUsed
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-block/test/helpers/prepare-block.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ export const prepareBlock = async (context) => {
previousBlock: "0000000000000000000000000000000000000000000000000000000000000000",
reward: BigNumber.ZERO,
round: 1,
stateHash: "0000000000000000000000000000000000000000000000000000000000000000",
stateRoot: "0000000000000000000000000000000000000000000000000000000000000000",
timestamp: 1_703_128_709_748,
totalAmount: totals.amount,
totalFee: totals.fee,
Expand Down
2 changes: 1 addition & 1 deletion packages/crypto-block/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const prepareSandbox = async (context) => {
4 + // height
4 + // round
hashByteLength + // previousBlock
hashByteLength + // stateHash
hashByteLength + // stateRoot
256 + // logsBloom
2 + // numberOfTransactions
4 + // totalGasUsed
Expand Down
2 changes: 1 addition & 1 deletion packages/evm-service/source/instances/evm.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -720,7 +720,7 @@ describe<{
const commitKey = { blockNumber: BigInt(0), round: BigInt(0) };
await instance.prepareNextCommit({ commitKey });

const hash = await instance.stateHash(
const hash = await instance.stateRoot(
commitKey,
"0000000000000000000000000000000000000000000000000000000000000000",
);
Expand Down
4 changes: 2 additions & 2 deletions packages/evm-service/source/instances/evm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ export class EvmInstance implements Contracts.Evm.Instance, Contracts.Evm.Storag
return this.#evm.storageAt(address, slot);
}

public async stateHash(commitKey: Contracts.Evm.CommitKey, currentHash: string): Promise<string> {
return this.#evm.stateHash(commitKey, currentHash);
public async stateRoot(commitKey: Contracts.Evm.CommitKey, currentHash: string): Promise<string> {
return this.#evm.stateRoot(commitKey, currentHash);
}

public async logsBloom(commitKey: Contracts.Evm.CommitKey): Promise<string> {
Expand Down
16 changes: 8 additions & 8 deletions packages/evm/bindings/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logs_bloom,
receipt::{TxReceipt, map_execution_result},
state_changes::AccountUpdate,
state_commit, state_hash,
state_commit, state_root,
};
use napi::{JsBigInt, JsObject, JsString, bindgen_prelude::*};
use napi_derive::napi;
Expand Down Expand Up @@ -801,7 +801,7 @@
}
}

pub fn state_hash(
pub fn state_root(

Check warning on line 804 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L804

Added line #L804 was not covered by tests
&mut self,
commit_key: CommitKey,
current_hash: B256,
Expand All @@ -811,12 +811,12 @@
.get_mut(&commit_key)
.expect("pending commit exists");

let result = state_hash::calculate(&mut self.persistent_db, pending_commit, current_hash);
let result = state_root::calculate(&mut self.persistent_db, pending_commit, current_hash);

Check warning on line 814 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L814

Added line #L814 was not covered by tests

match result {
Ok(result) => Ok(result.encode_hex()),
Err(err) => Err(EVMError::Database(
format!("state_hash failed: {}", err).into(),
format!("state_root failed: {}", err).into(),

Check warning on line 819 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L819

Added line #L819 was not covered by tests
)),
}
}
Expand Down Expand Up @@ -1454,7 +1454,7 @@
}

#[napi(ts_return_type = "Promise<string>")]
pub fn state_hash(
pub fn state_root(

Check warning on line 1457 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L1457

Added line #L1457 was not covered by tests
&mut self,
node_env: Env,
commit_key: JsCommitKey,
Expand All @@ -1463,7 +1463,7 @@
let commit_key = CommitKey::try_from(commit_key)?;
let current_hash = utils::convert_string_to_b256(current_hash)?;
node_env.execute_tokio_future(
Self::state_hash_async(self.evm.clone(), commit_key, current_hash),
Self::state_root_async(self.evm.clone(), commit_key, current_hash),

Check warning on line 1466 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L1466

Added line #L1466 was not covered by tests
|&mut node_env, result| Ok(node_env.create_string_from_std(result)?),
)
}
Expand Down Expand Up @@ -1786,13 +1786,13 @@
}
}

async fn state_hash_async(
async fn state_root_async(

Check warning on line 1789 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L1789

Added line #L1789 was not covered by tests
evm: Arc<tokio::sync::Mutex<EvmInner>>,
commit_key: CommitKey,
current_hash: B256,
) -> Result<String> {
let mut lock = evm.lock().await;
let result = lock.state_hash(commit_key, current_hash);
let result = lock.state_root(commit_key, current_hash);

Check warning on line 1795 in packages/evm/bindings/src/lib.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/bindings/src/lib.rs#L1795

Added line #L1795 was not covered by tests

match result {
Ok(result) => Result::Ok(result),
Expand Down
8 changes: 4 additions & 4 deletions packages/evm/core/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ use crate::{
receipt::{TxReceipt, map_execution_result},
state_changes,
state_commit::StateCommit,
state_hash,
state_root,
};

#[derive(Debug)]
Expand Down Expand Up @@ -988,9 +988,9 @@ impl PersistentDB {
rwtxn,
&key.0,
&CommitReceipts {
accounts_hash: state_hash::calculate_accounts_hash(&change_set)?,
contracts_hash: state_hash::calculate_contracts_hash(&change_set)?,
storage_hash: state_hash::calculate_storage_hash(&change_set)?,
accounts_hash: state_root::calculate_accounts_hash(&change_set)?,
contracts_hash: state_root::calculate_contracts_hash(&change_set)?,
storage_hash: state_root::calculate_storage_hash(&change_set)?,
tx_receipts,
},
)?;
Expand Down
2 changes: 1 addition & 1 deletion packages/evm/core/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@ pub mod logs_bloom;
pub mod receipt;
pub mod state_changes;
pub mod state_commit;
pub mod state_hash;
pub mod state_root;
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
pending_commit.built_commit.replace(state_commit);
};

calculate_state_hash(
calculate_state_root(

Check warning on line 23 in packages/evm/core/src/state_root.rs

View check run for this annotation

Codecov / codecov/patch

packages/evm/core/src/state_root.rs#L23

Added line #L23 was not covered by tests
current_hash,
pending_commit
.built_commit
Expand All @@ -31,7 +31,7 @@
)
}

fn calculate_state_hash(
fn calculate_state_root(
current_hash: B256,
state: &StateCommit,
committed_hashes: Option<(B256, B256, B256)>,
Expand Down Expand Up @@ -122,8 +122,8 @@
}

#[test]
fn test_calculate_state_hash() {
let result = calculate_state_hash(B256::ZERO, &Default::default(), None, &None).expect("ok");
fn test_calculate_state_root() {
let result = calculate_state_root(B256::ZERO, &Default::default(), None, &None).expect("ok");
assert_eq!(
result,
revm::primitives::b256!("0722d8002560934d7004b8b849101024bf7ec2aaa2c3396f7292d4ac8cdae5ab")
Expand Down
6 changes: 3 additions & 3 deletions packages/processor/source/block-processor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class BlockProcessor implements Contracts.Processor.BlockProcessor {
this.#verifyTotalFee(block);
await this.#updateRewardsAndVotes(unit);
await this.#calculateRoundValidators(unit);
await this.#verifyStateHash(block);
await this.#verifyStateRoot(block);
await this.#verifyLogsBloom(block);

processResult.success = true;
Expand Down Expand Up @@ -191,7 +191,7 @@ export class BlockProcessor implements Contracts.Processor.BlockProcessor {
}
}

async #verifyStateHash(block: Contracts.Crypto.Block): Promise<void> {
async #verifyStateRoot(block: Contracts.Crypto.Block): Promise<void> {
let previousStateRoot;
if (block.header.number === this.configuration.getGenesisHeight()) {
// Assume snapshot is present if the previous block points to a non-zero hash
Expand All @@ -207,7 +207,7 @@ export class BlockProcessor implements Contracts.Processor.BlockProcessor {
previousStateRoot = previousBlock.header.stateRoot;
}

const stateRoot = await this.evm.stateHash(
const stateRoot = await this.evm.stateRoot(
{
blockHash: block.header.hash,
blockNumber: BigInt(block.header.number),
Expand Down
20 changes: 10 additions & 10 deletions packages/validator/source/validator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,15 @@ export class Validator implements Contracts.Validator.Validator {
const previousBlock = this.stateStore.getLastBlock();
const blockNumber = previousBlock.header.number + 1;

const {
logsBloom,
stateRoot: stateHash,
transactions,
} = await this.#getTransactionsForForging(generatorAddress, timestamp, {
blockNumber: BigInt(blockNumber),
round: BigInt(round),
});
return this.#makeBlock(round, generatorAddress, logsBloom, stateHash, transactions, timestamp);
const { logsBloom, stateRoot, transactions } = await this.#getTransactionsForForging(
generatorAddress,
timestamp,
{
blockNumber: BigInt(blockNumber),
round: BigInt(round),
},
);
return this.#makeBlock(round, generatorAddress, logsBloom, stateRoot, transactions, timestamp);
}

public async propose(
Expand Down Expand Up @@ -250,7 +250,7 @@ export class Validator implements Contracts.Validator.Validator {
}

const logsBloom = await evm.logsBloom(commitKey);
const stateRoot = await evm.stateHash(commitKey, previousBlock.header.stateRoot);
const stateRoot = await evm.stateRoot(commitKey, previousBlock.header.stateRoot);

return {
logsBloom,
Expand Down
2 changes: 1 addition & 1 deletion packages/validator/test/helpers/prepare-sandbox.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ export const prepareSandbox = async (context: { sandbox?: Sandbox }) => {
initializeGenesis: async () => {},
logsBloom: async () => "0".repeat(512),
prepareNextCommit: async () => {},
stateHash: async () => "0000000000000000000000000000000000000000000000000000000000000000",
stateRoot: async () => "0000000000000000000000000000000000000000000000000000000000000000",
updateRewardsAndVotes: async () => {},
snapshot: async () => {},
rollback: async () => {},
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/consensus/config/crypto.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"previousBlock": "0000000000000000000000000000000000000000000000000000000000000000",
"reward": "0",
"round": 0,
"stateHash": "63ab8518cf86b8c81a32612ab69f20da469d46ca1a584a822b4afc3d6b6df135",
"stateRoot": "63ab8518cf86b8c81a32612ab69f20da469d46ca1a584a822b4afc3d6b6df135",
"timestamp": 1742207270525,
"totalAmount": "125000000000000000000000000",
"totalFee": "0",
Expand Down
6 changes: 3 additions & 3 deletions tests/functional/consensus/source/custom-proposal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ export const makeCustomProposal = async (
payloadLength += serialized.length;
}

const stateHash = await transactionValidator.getEvm().stateHash(commitKey, previousBlock.header.stateHash);
const stateRoot = await transactionValidator.getEvm().stateRoot(commitKey, previousBlock.header.stateRoot);

const hashFactory = node.app.get<Contracts.Crypto.HashFactory>(Identifiers.Cryptography.Hash.Factory);
const hashSize = node.app.get<number>(Identifiers.Cryptography.Hash.Size.SHA256);

let byteOffset = 1 + 6 + 4 + 4 + hashSize; // see headerSize

// stateHash
Buffer.from(stateHash, "hex").copy(blockBuffer, byteOffset);
// stateRoot
Buffer.from(stateRoot, "hex").copy(blockBuffer, byteOffset);
byteOffset += hashSize;

// numberOfTransactions
Expand Down
Loading