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

Fix system.set_code index #75

Merged
merged 6 commits into from
Jun 20, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
18 changes: 9 additions & 9 deletions libs/substrate-runtime-proposal-hash/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ pub type CalllHash = [u8; SIZE];
type Prefix = (u8, u8);

/// The PREFIX is prepended to the data before hashing
pub const PREFIX_SYSTEM_SETCODE: Prefix = (0x00, 0x03);
pub const PREFIX_SYSTEM_SETCODE: Prefix = (0x00, 0x02);

const PARACHAIN_PALLET_ID_ENV: &str = "PARACHAIN_PALLET_ID";
const DEFAULT_PARACHAIN_PALLET_ID: &str = "0x01";
Expand All @@ -33,7 +33,7 @@ pub struct SrhResult {
pub hash: CalllHash,

/// Hex encoded proposal hash.
pub encodedd_hash: String,
pub encoded_hash: String,
}

/// Concatenate 2 arrays.
Expand All @@ -47,7 +47,7 @@ pub fn concatenate_arrays<T: Clone>(x: &[T], y: &[T]) -> Vec<T> {
pub fn get_result(prefix: Prefix, buffer: &[u8]) -> Result<SrhResult> {
buffer.using_encoded(|wasm_blob: &[u8]| {
let result = match get_call_hash(prefix, wasm_blob) {
Ok(hash) => Ok(SrhResult { hash, encodedd_hash: hex::encode(hash) }),
Ok(hash) => Ok(SrhResult { hash, encoded_hash: hex::encode(hash) }),
Err(_e) => Err(RuntimePropHashError::HashComputing()),
};
result
Expand Down Expand Up @@ -105,8 +105,8 @@ mod prop_hash_tests {
assert_eq!(
get_proposal_hash(&[1, 2, 42]).unwrap(),
[
156, 244, 243, 93, 21, 8, 113, 238, 186, 17, 20, 52, 240, 236, 140, 15, 108, 26, 86, 5, 152, 148, 91,
162, 108, 168, 3, 65, 254, 162, 114, 46
174, 123, 79, 240, 254, 106, 147, 26, 65, 61, 41, 84, 181, 102, 24, 182, 128, 135, 188, 31, 135, 187,
99, 34, 143, 35, 120, 100, 246, 90, 186, 106
]
);
}
Expand All @@ -116,8 +116,8 @@ mod prop_hash_tests {
assert_eq!(
get_call_hash(PREFIX_SYSTEM_SETCODE, &[1, 2, 42]).unwrap(),
[
156, 244, 243, 93, 21, 8, 113, 238, 186, 17, 20, 52, 240, 236, 140, 15, 108, 26, 86, 5, 152, 148, 91,
162, 108, 168, 3, 65, 254, 162, 114, 46
174, 123, 79, 240, 254, 106, 147, 26, 65, 61, 41, 84, 181, 102, 24, 182, 128, 135, 188, 31, 135, 187,
99, 34, 143, 35, 120, 100, 246, 90, 186, 106
chevdor marked this conversation as resolved.
Show resolved Hide resolved
]
);
}
Expand Down Expand Up @@ -164,13 +164,13 @@ mod prop_hash_tests {
#[test]
fn test_get_result() {
let res = get_result(PREFIX_SYSTEM_SETCODE, &[1, 2, 42]).unwrap();
assert!(res.encodedd_hash == "9388ba11b3f2a5db3ef9bf237f1c88ffb369d77ffa843fc67570c89c09fa9c0e");
assert_eq!(res.encoded_hash, "85233004e044626a6c08e469573369536d8de9b264b08eb6611b76b80148e429");
}

#[test]
fn test_long_input() {
const SIZE_8MB: usize = 8 * 1024 * 1024;
let res = get_result(PREFIX_SYSTEM_SETCODE, &[0; SIZE_8MB]).unwrap();
assert!(res.encodedd_hash == "9348da94fcffe94318313f8ce237211a7fd6c1531ab21b61606a1f7eeb8b2409");
assert_eq!(res.encoded_hash, "44de98eef7227a1f55c5d1cf2b437dc87e60177dc8607538a115773b567ed0d5");
}
}
2 changes: 1 addition & 1 deletion libs/wasm-testbed/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@ impl WasmTestBed {
/// Compute the proposal hash of the runtime
pub fn proposal_hash(&self) -> Result<String> {
let result: SrhResult = get_result(substrate_runtime_proposal_hash::PREFIX_SYSTEM_SETCODE, &self.bytes)?;
Ok(format!("0x{}", &result.encodedd_hash))
Ok(format!("0x{}", &result.encoded_hash))
}

/// Compute the proposal hash of the runtime
Expand Down
Loading