-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
"flow" op code sanity benchmarks #1433
Changes from 15 commits
d912246
c7e318f
1f47b1d
de5f327
590bd77
c5cc553
1aa43d7
baf119c
10f4b29
52607e2
3b66c7a
ed2cc12
10fc114
45f895d
f85e595
278d056
c92da04
bebd99a
e874e0b
e84ee99
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
use crate::*; | ||
// use crate::utils::generate_linear_costs; | ||
|
||
pub fn run_contract(_group: &mut BenchmarkGroup<WallTime>) { | ||
// This breaks the benchmarking | ||
// for i in generate_linear_costs() { | ||
// let id = format!("flow/retd_contract opcode {:?}", i); | ||
// run( | ||
// &id, | ||
// group, | ||
// vec![ | ||
// op::movi(0x10, i), | ||
// op::retd(RegId::ONE, 0x10), | ||
// op::jmpb(RegId::ZERO, 0), | ||
// ] | ||
// .to_vec(), | ||
// vec![], | ||
// ); | ||
// } | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
use crate::{ | ||
utils::generate_linear_costs, | ||
*, | ||
}; | ||
use rand::{ | ||
rngs::StdRng, | ||
SeedableRng, | ||
}; | ||
|
||
// ECK1: Secp251k1 signature recovery | ||
// ECR1: Secp256r1 signature recovery | ||
// ED19: edDSA curve25519 verification | ||
// K256: keccak-256 | ||
// S256: SHA-2-256 | ||
pub fn run_crypto(group: &mut BenchmarkGroup<WallTime>) { | ||
let rng = &mut StdRng::seed_from_u64(2322u64); | ||
|
||
let message = Message::new(b"foo"); | ||
|
||
let eck1_secret = SecretKey::random(rng); | ||
let eck1_signature = Signature::sign(&eck1_secret, &message); | ||
run( | ||
"crypto/eck1 opcode valid", | ||
group, | ||
[ | ||
op::gtf_args(0x20, 0x00, GTFArgs::ScriptData), | ||
op::addi( | ||
0x21, | ||
0x20, | ||
eck1_signature.as_ref().len().try_into().unwrap(), | ||
), | ||
op::movi(0x10, PublicKey::LEN.try_into().unwrap()), | ||
op::aloc(0x10), | ||
op::eck1(RegId::HP, 0x20, 0x21), | ||
op::jmpb(RegId::ZERO, 0), | ||
] | ||
.to_vec(), | ||
eck1_signature | ||
.iter() | ||
.chain(message.iter()) | ||
.copied() | ||
.collect(), | ||
); | ||
|
||
let wrong_message = Message::new(b"bar"); | ||
|
||
run( | ||
"crypto/eck1 opcode invalid", | ||
group, | ||
[ | ||
op::gtf_args(0x20, 0x00, GTFArgs::ScriptData), | ||
op::addi( | ||
0x21, | ||
0x20, | ||
eck1_signature.as_ref().len().try_into().unwrap(), | ||
), | ||
op::movi(0x10, PublicKey::LEN.try_into().unwrap()), | ||
op::aloc(0x10), | ||
op::eck1(RegId::HP, 0x20, 0x21), | ||
op::jmpb(RegId::ZERO, 0), | ||
] | ||
.to_vec(), | ||
eck1_signature | ||
.iter() | ||
.chain(wrong_message.iter()) | ||
.copied() | ||
.collect(), | ||
); | ||
|
||
let message = fuel_core_types::fuel_crypto::Message::new(b"foo"); | ||
let ecr1_secret = p256::ecdsa::SigningKey::random(&mut rand::thread_rng()); | ||
let ecr1_signature = secp256r1::sign_prehashed(&ecr1_secret, &message) | ||
.expect("Failed to sign with secp256r1"); | ||
|
||
run( | ||
"crypto/ecr1 opcode", | ||
group, | ||
[ | ||
op::gtf_args(0x20, 0x00, GTFArgs::ScriptData), | ||
op::addi( | ||
0x21, | ||
0x20, | ||
ecr1_signature.as_ref().len().try_into().unwrap(), | ||
), | ||
op::movi(0x10, PublicKey::LEN.try_into().unwrap()), | ||
op::aloc(0x10), | ||
op::move_(0x11, RegId::HP), | ||
op::ecr1(0x11, 0x20, 0x21), | ||
op::jmpb(RegId::ZERO, 0), | ||
] | ||
.to_vec(), | ||
ecr1_signature | ||
.as_ref() | ||
.iter() | ||
.chain(message.as_ref()) | ||
.copied() | ||
.collect(), | ||
); | ||
|
||
let message = fuel_core_types::fuel_crypto::Message::new(b"foo"); | ||
let ed19_keypair = | ||
ed25519_dalek::Keypair::generate(&mut ed25519_dalek_old_rand::rngs::OsRng {}); | ||
let ed19_signature = ed19_keypair.sign(&*message); | ||
|
||
run( | ||
"crypto/ed19 opcode", | ||
group, | ||
[ | ||
op::gtf_args(0x20, 0x00, GTFArgs::ScriptData), | ||
op::addi( | ||
0x21, | ||
0x20, | ||
ed19_keypair.public.as_ref().len().try_into().unwrap(), | ||
), | ||
op::addi( | ||
0x22, | ||
0x21, | ||
ed19_signature.as_ref().len().try_into().unwrap(), | ||
), | ||
op::addi(0x22, 0x21, message.as_ref().len().try_into().unwrap()), | ||
op::movi(0x10, ed25519_dalek::PUBLIC_KEY_LENGTH.try_into().unwrap()), | ||
op::aloc(0x10), | ||
op::move_(0x11, RegId::HP), | ||
op::ed19(0x20, 0x21, 0x22), | ||
op::jmpb(RegId::ZERO, 0), | ||
] | ||
.to_vec(), | ||
ed19_keypair | ||
.public | ||
.as_ref() | ||
.iter() | ||
.chain(ed19_signature.as_ref()) | ||
.chain(message.as_ref()) | ||
.copied() | ||
.collect(), | ||
); | ||
|
||
for i in generate_linear_costs() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I understand you didn't create There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't really understand the name--I've been trying to think of a new name. But it's used in a number of or benchmarks for dependent costs. The actual values used aren't particularly important as long as they show a good range between 0 -> a lot. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Renaming |
||
let id = format!("crypto/s256 opcode {:?}", i); | ||
run( | ||
&id, | ||
group, | ||
[ | ||
op::movi(0x11, 32), | ||
op::aloc(0x11), | ||
op::movi(0x10, i), | ||
op::s256(RegId::HP, RegId::ZERO, 0x10), | ||
op::jmpb(RegId::ZERO, 0), | ||
] | ||
.to_vec(), | ||
vec![], | ||
) | ||
} | ||
|
||
for i in generate_linear_costs() { | ||
let id = format!("crypto/k256 opcode {:?}", i); | ||
run( | ||
&id, | ||
group, | ||
[ | ||
op::movi(0x11, 32), | ||
op::aloc(0x11), | ||
op::movi(0x10, i), | ||
op::k256(RegId::HP, RegId::ZERO, 0x10), | ||
op::jmpb(RegId::ZERO, 0), | ||
] | ||
.to_vec(), | ||
vec![], | ||
) | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
use crate::*; | ||
|
||
// JMP: Jump | ||
// JI: Jump immediate | ||
// JNE: Jump if not equal | ||
// JNEI: Jump if not equal immediate | ||
// JNZI: Jump if not zero immediate | ||
// JMPB: Jump relative backwards | ||
// JMPF: Jump relative forwards | ||
// JNZB: Jump if not zero relative backwards | ||
// JNZF: Jump if not zero relative forwards | ||
// JNEB: Jump if not equal relative backwards | ||
// JNEF: Jump if not equal relative forwards | ||
// RET: Return from context | ||
pub fn run_flow(group: &mut BenchmarkGroup<WallTime>) { | ||
run( | ||
"flow/jmp opcode", | ||
group, | ||
vec![op::movi(0x10, 0), op::jmp(0x10)], | ||
vec![], | ||
); | ||
|
||
run( | ||
"flow/ji opcode", | ||
group, | ||
vec![op::ji(0), op::jmpb(RegId::ZERO, 0)], | ||
vec![], | ||
); | ||
|
||
run( | ||
"flow/jne opcode", | ||
group, | ||
vec![ | ||
op::movi(0x10, 0), | ||
op::jne(RegId::ZERO, RegId::ONE, 0x10), | ||
op::jmpb(RegId::ZERO, 0), | ||
], | ||
vec![], | ||
); | ||
|
||
run( | ||
"flow/jnei opcode", | ||
group, | ||
vec![ | ||
op::jnei(RegId::ZERO, RegId::ONE, 0), | ||
op::jmpb(RegId::ZERO, 0), | ||
], | ||
vec![], | ||
); | ||
|
||
run( | ||
"flow/jnzi opcode", | ||
group, | ||
vec![op::jnzi(RegId::ONE, 0), op::jmpb(RegId::ZERO, 0)], | ||
vec![], | ||
); | ||
|
||
// Don't know how to test "returning" op codes | ||
// run( | ||
// "flow/ret_script opcode", | ||
// group, | ||
// vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(), | ||
// vec![], | ||
// ); | ||
// | ||
// run( | ||
// "flow/ret_contract opcode", | ||
// group, | ||
// vec![op::ret(RegId::ONE), op::jmpb(RegId::ZERO, 0)].to_vec(), | ||
// vec![], | ||
// ); | ||
Comment on lines
+174
to
+187
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, You can skip it for now, but create an issue to write a benchmark later that: the scenario either calls another contract and returns with a lot of data or runs a lot of transactions with this opcode. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I added it as a subtask to the parent issue, like we did with |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,7 @@ | ||
pub mod alu; | ||
|
||
pub mod crypto; | ||
|
||
pub mod flow; | ||
|
||
pub mod contract; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this file?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll probably just keep it since we're gonna add it soon anyway.