Skip to content
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

Architecture: Rename ClientApi -> SystemApi + Move CryptoUtils into VM Layer #1804

Merged
merged 7 commits into from May 13, 2024

Conversation

talekhinezh
Copy link
Member

  • Rename ClientApi -> SystemApi
  • Move CryptoUtils from System Layer into VM Layer

Copy link

github-actions bot commented May 8, 2024

Docker tags
docker.io/radixdlt/private-scrypto-builder:00d71f3b5e

Copy link

github-actions bot commented May 8, 2024

Benchmark for 00d71f3

Click to view benchmark
Test Base PR %
costing::bench_prepare_wasm 66.2±0.13ms 65.7±0.17ms -0.76%
costing::decode_sbor 11.1±0.06µs 11.1±0.04µs 0.00%
costing::decode_sbor_bytes 29.1±0.03µs 29.7±0.03µs +2.06%
costing::deserialize_wasm 1290.2±2.84µs 1311.4±3.45µs +1.64%
costing::instantiate_flash_loan 4.0±0.61ms 3.8±0.46ms -5.00%
costing::instantiate_radiswap 5.8±0.08ms 5.8±0.08ms 0.00%
costing::spin_loop 21.5±0.04ms 21.6±0.04ms +0.47%
costing::validate_sbor_payload 30.4±0.04µs 26.2±0.09µs -13.82%
costing::validate_sbor_payload_bytes 259.3±0.91ns 240.2±0.80ns -7.37%
costing::validate_secp256k1 76.6±0.06µs 76.6±0.14µs 0.00%
costing::validate_wasm 37.1±0.06ms 36.7±0.04ms -1.08%
decimal::add/0 8.4±0.00ns 8.4±0.01ns 0.00%
decimal::add/rust-native 9.8±0.00ns 9.8±0.00ns 0.00%
decimal::add/wasmer 112.6±0.06ns 114.2±0.36ns +1.42%
decimal::add/wasmer-call-native 452.2±0.33ns 451.4±0.38ns -0.18%
decimal::add/wasmi 612.5±4.76ns 627.7±0.92ns +2.48%
decimal::add/wasmi-call-native 5.5±0.01µs 5.4±0.01µs -1.82%
decimal::div/0 191.2±0.34ns 190.6±0.13ns -0.31%
decimal::from_string/0 150.6±0.19ns 152.1±0.08ns +1.00%
decimal::mul/0 142.2±0.16ns 141.5±0.09ns -0.49%
decimal::mul/rust-native 137.8±0.11ns 138.5±0.28ns +0.51%
decimal::mul/wasmer 1518.4±3.18ns 1480.8±0.71ns -2.48%
decimal::mul/wasmer-call-native 571.9±0.54ns 574.5±0.86ns +0.45%
decimal::mul/wasmi 42.2±0.07µs 42.1±0.12µs -0.24%
decimal::mul/wasmi-call-native 5.6±0.01µs 5.5±0.02µs -1.79%
decimal::pow/0 655.2±0.49ns 653.8±0.92ns -0.21%
decimal::pow/rust-native 633.2±0.23ns 633.2±0.46ns 0.00%
decimal::pow/wasmer 6.6±0.01µs 6.9±0.01µs +4.55%
decimal::pow/wasmer-call-native 1022.3±0.31ns 1019.9±0.95ns -0.23%
decimal::pow/wasmi 198.8±0.55µs 194.6±0.49µs -2.11%
decimal::pow/wasmi-call-native 5.4±0.01µs 5.3±0.01µs -1.85%
decimal::root/0 8.0±0.01µs 7.9±0.01µs -1.25%
decimal::sub/0 8.5±0.00ns 8.5±0.01ns 0.00%
decimal::to_string/0 444.7±1.55ns 442.1±3.47ns -0.58%
precise_decimal::add/0 9.5±0.51ns 10.0±0.00ns +5.26%
precise_decimal::add/rust-native 11.6±0.00ns 11.6±0.00ns 0.00%
precise_decimal::add/wasmer 119.6±0.27ns 119.6±0.37ns 0.00%
precise_decimal::add/wasmer-call-native 505.4±0.39ns 506.6±0.79ns +0.24%
precise_decimal::add/wasmi 779.2±0.89ns 788.9±0.67ns +1.24%
precise_decimal::add/wasmi-call-native 7.0±0.02µs 7.0±0.02µs 0.00%
precise_decimal::div/0 303.1±0.19ns 300.6±0.42ns -0.82%
precise_decimal::from_string/0 196.2±0.72ns 195.6±0.16ns -0.31%
precise_decimal::mul/0 346.2±0.63ns 344.5±1.73ns -0.49%
precise_decimal::mul/rust-native 314.0±1.28ns 304.0±0.33ns -3.18%
precise_decimal::mul/wasmer 3.5±0.00µs 3.5±0.00µs 0.00%
precise_decimal::mul/wasmer-call-native 843.4±0.95ns 826.0±0.84ns -2.06%
precise_decimal::mul/wasmi 107.9±0.22µs 107.8±0.50µs -0.09%
precise_decimal::mul/wasmi-call-native 7.7±0.01µs 7.3±0.02µs -5.19%
precise_decimal::pow/0 1888.0±8.23ns 1893.1±3.66ns +0.27%
precise_decimal::pow/rust-native 1480.2±1.84ns 1476.3±3.88ns -0.26%
precise_decimal::pow/wasmer 16.1±0.00µs 16.1±0.00µs 0.00%
precise_decimal::pow/wasmer-call-native 2.1±0.00µs 2.1±0.00µs 0.00%
precise_decimal::pow/wasmi 522.7±1.12µs 519.6±1.46µs -0.59%
precise_decimal::pow/wasmi-call-native 13.3±0.02µs 13.3±0.12µs 0.00%
precise_decimal::root/0 57.4±0.19µs 56.4±0.04µs -1.74%
precise_decimal::sub/0 9.5±0.00ns 9.5±0.01ns 0.00%
precise_decimal::to_string/0 753.6±3.89ns 758.4±1.89ns +0.64%
schema::validate_payload 355.5±0.54µs 343.7±0.39µs -3.32%
transaction::radiswap 5.5±0.03ms 5.4±0.03ms -1.82%
transaction::transfer 1787.0±6.78µs 1788.8±2.93µs +0.10%
transaction_processing::prepare 2.2±0.00ms 2.2±0.00ms 0.00%
transaction_processing::prepare_and_decompile 6.0±0.01ms 6.0±0.01ms 0.00%
transaction_processing::prepare_and_decompile_and_recompile 24.0±0.30ms 24.6±1.20ms +2.50%
transaction_validation::validate_manifest 42.3±0.05µs 42.3±0.05µs 0.00%
transaction_validation::verify_bls_2KB 999.8±5.90µs 999.5±3.95µs -0.03%
transaction_validation::verify_bls_32B 1054.5±16.93µs 1001.8±11.62µs -5.00%
transaction_validation::verify_ecdsa 74.5±0.08µs 74.6±0.06µs +0.13%
transaction_validation::verify_ed25519 55.3±0.13µs 55.0±0.07µs -0.54%

Copy link
Contributor

@mstrug-rdx mstrug-rdx left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When removing crypto bls related functions, you also removed trace_resource macro which was used to calculate costing coefficients. I've added comments to that macros to move them to lower layer functions in case we need to run costing evaluation again.

Also I saw in couple places that KernelNodeApi + ClientApi was changed to SystemApi, this is probably intentional but just wanted to point that out.

}
}

#[trace_resources(log=message.len(), log=public_keys.len())]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace_resource macro should be moved to fast_aggregate_verify_bls12381_v1() function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!

}

// Trace average message length and number of public_keys
#[trace_resources(log={pub_keys_and_msgs.iter().flat_map(|(_, msg)| msg).count()/pub_keys_and_msgs.len()},log=pub_keys_and_msgs.len())]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace_resource macro should be moved to aggregate_verify_bls12381_v1() function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!

Y: KernelApi<System<V>>,
V: SystemCallbackObject,
{
#[trace_resources(log=message.len())]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace_resource macro should be moved to verify_bls12381_v1() function.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point!

}
}

#[trace_resources(log=signatures.len())]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace_resource macro should be moved to Bls12381G2Signature::aggregate() function.

}
}

#[trace_resources(log=data.len())]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

trace_resource macro should be moved to keccak256_hash() function.

Ok(result)
if pub_keys_and_msgs.is_empty() {
return Err(InvokeError::SelfError(WasmRuntimeError::InputDataEmpty));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this a breaking change?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No it should be the same logic it just changes the logic into the "Return early" pattern. Unless you mean for something else?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't see where we do this non-empty check before.

If it's not new, the order of the non-empty check and costing also matters? Transaction fails with different costs.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The check was in the api.bls12381_v1_aggregate_verify() call, the logic of which has now moved into this function.

Ok(result)
if public_keys.is_empty() {
return Err(InvokeError::SelfError(WasmRuntimeError::InputDataEmpty));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

let agg_sig = self.api.bls12381_g2_signature_aggregate(&signatures)?;
if signatures.is_empty() {
return Err(InvokeError::SelfError(WasmRuntimeError::InputDataEmpty));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ditto

@talekhinezh talekhinezh merged commit 3d4f0e5 into develop May 13, 2024
28 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants