-
Notifications
You must be signed in to change notification settings - Fork 324
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: benchmark sha256 number of instructions executed in AVM (#11253)
Also move hash stuff into another AVM test contract. This lets us get stats like below, although note that this isn't directly an output from the yarn tests: For a `sha256` of N bytes, how many AVM/Brillig instructions are executed and how much gas does it consume? ```N= 10 bytes: 3998 instructions, 69006 L2 Gas N= 20 bytes: 4513 instructions, 77778 L2 Gas N= 30 bytes: 5328 instructions, 91326 L2 Gas N= 40 bytes: 5843 instructions, 100098 L2 Gas N= 50 bytes: 6672 instructions, 113877 L2 Gas N= 60 bytes: 7490 instructions, 127626 L2 Gas N= 70 bytes: 8662 instructions, 147936 L2 Gas N= 80 bytes: 9207 instructions, 157368 L2 Gas N= 90 bytes: 10052 instructions, 171576 L2 Gas N= 100 bytes: 10597 instructions, 181008 L2 Gas N= 255 bytes: 23046 instructions, 392055 L2 Gas N= 256 bytes: 23022 instructions, 392121 L2 Gas N= 511 bytes: 43107 instructions, 732336 L2 Gas N= 512 bytes: 42978 instructions, 731004 L2 Gas N=2048 bytes: 162801 instructions, 2765820 L2 Gas```
- Loading branch information
Showing
6 changed files
with
177 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
noir-projects/noir-contracts/contracts/avm_gadgets_test_contract/Nargo.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
name = "avm_gadgets_test_contract" | ||
authors = [""] | ||
compiler_version = ">=0.25.0" | ||
type = "contract" | ||
|
||
[dependencies] | ||
aztec = { path = "../../../aztec-nr/aztec" } |
93 changes: 93 additions & 0 deletions
93
noir-projects/noir-contracts/contracts/avm_gadgets_test_contract/src/main.nr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
use dep::aztec::macros::aztec; | ||
|
||
#[aztec] | ||
contract AvmGadgetsTest { | ||
use dep::aztec::macros::functions::public; | ||
|
||
#[public] | ||
fn keccak_hash(data: [u8; 10]) -> [u8; 32] { | ||
std::hash::keccak256(data, data.len() as u32) | ||
} | ||
|
||
#[public] | ||
fn keccak_f1600(data: [u64; 25]) -> [u64; 25] { | ||
std::hash::keccak::keccakf1600(data) | ||
} | ||
|
||
#[public] | ||
fn poseidon2_hash(data: [Field; 10]) -> Field { | ||
std::hash::poseidon2::Poseidon2::hash(data, data.len()) | ||
} | ||
|
||
#[public] | ||
fn sha256_hash_10(data: [u8; 10]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_20(data: [u8; 20]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_30(data: [u8; 30]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_40(data: [u8; 40]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_50(data: [u8; 50]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_60(data: [u8; 60]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_70(data: [u8; 70]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_80(data: [u8; 80]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_90(data: [u8; 90]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_100(data: [u8; 100]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_255(data: [u8; 255]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_256(data: [u8; 256]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_511(data: [u8; 511]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
#[public] | ||
fn sha256_hash_512(data: [u8; 512]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
|
||
#[public] | ||
fn sha256_hash_2048(data: [u8; 2048]) -> [u8; 32] { | ||
std::hash::sha256(data) | ||
} | ||
|
||
#[public] | ||
fn pedersen_hash(data: [Field; 10]) -> Field { | ||
std::hash::pedersen_hash(data) | ||
} | ||
|
||
#[public] | ||
fn pedersen_hash_with_index(data: [Field; 10]) -> Field { | ||
std::hash::pedersen_hash_with_separator(data, /*index=*/ 20) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters