Skip to content

Commit

Permalink
Revert "Update ecdsa-authority spec (#1022)"
Browse files Browse the repository at this point in the history
This reverts commit 3c07f7b.
  • Loading branch information
Guantong committed Mar 22, 2023
1 parent da97997 commit 2b1a07b
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 34 deletions.
11 changes: 7 additions & 4 deletions pallet/ecdsa-authority/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -486,7 +486,7 @@ pub mod pallet {
),
}
};
let message = Sign::signable_message(
let message = Sign::eth_signable_message(
T::ChainId::get(),
T::Version::get().spec_name.as_ref(),
&ethabi::encode(&[
Expand Down Expand Up @@ -552,9 +552,12 @@ pub mod pallet {
}

fn on_new_message_root(at: T::BlockNumber, message_root: Hash) {
let commitment =
Commitment { block_number: at, message_root, nonce: <Nonce<T>>::get() };
let message = Sign::signable_message(
let commitment = Commitment {
block_number: at.saturated_into::<u32>(),
message_root,
nonce: <Nonce<T>>::get(),
};
let message = Sign::eth_signable_message(
T::ChainId::get(),
T::Version::get().spec_name.as_ref(),
&ethabi::encode(&[
Expand Down
33 changes: 13 additions & 20 deletions pallet/ecdsa-authority/src/primitives.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,16 +52,12 @@ impl Sign {
hashing::keccak_256(data)
}

pub fn domain_separator(chain_id: u64, spec_name: &[u8]) -> [u8; 32] {
Self::hash(&[&chain_id.to_be_bytes(), spec_name, b"::ecdsa-authority"].concat())
}

// \x19\x01 + keccack256(ChainIDSpecName::ecdsa-authority) + struct_hash
pub(crate) fn signable_message(chain_id: u64, spec_name: &[u8], data: &[u8]) -> Hash {
pub(crate) fn eth_signable_message(chain_id: u64, spec_name: &[u8], data: &[u8]) -> Hash {
// \x19\x01 + keccack256(ChainIDSpecName::ecdsa-authority) + struct_hash
Hash(Self::hash(
&[
b"\x19\x01".as_slice(),
&Self::domain_separator(chain_id, spec_name),
&Self::hash(&[&chain_id.to_le_bytes(), spec_name, b"::ecdsa-authority"].concat()),
&Self::hash(data),
]
.concat(),
Expand Down Expand Up @@ -173,23 +169,20 @@ where
}

#[test]
fn signable_message() {
fn eth_signable_message() {
assert_eq!(
array_bytes::bytes2hex("0x", Sign::domain_separator(46, b"Darwinia").as_ref()),
"0xc494742e979bd6ab2dca4950fddd8809e1502ab8ef7b8d749364ec32cb6e1b3e"
array_bytes::bytes2hex("0x", Sign::eth_signable_message(46, b"Darwinia", &[0; 32])),
"0xb492857010088b0dff298645e9105549d088aab7bcb20cf5a3d0bc17dce91045"
);
assert_eq!(
array_bytes::bytes2hex("0x", Sign::domain_separator(43, b"Pangolin2").as_ref()),
"0xe97c73e46305f3bca2279f002665725cd29e465c6624e83a135f7b2e6b1a8134"
array_bytes::bytes2hex("0x", Sign::hash(b"46Darwinia::ecdsa-authority")),
"0xf8a76f5ceeff36d74ff99c4efc0077bcc334721f17d1d5f17cfca78455967e1e"
);

let data = array_bytes::hex2bytes_unchecked("0x30a82982a8d5050d1c83bbea574aea301a4d317840a8c4734a308ffaa6a63bc8cb76085b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000068898db1012808808c903f390909c52d9f7067490000000000000000000000004cdc1dbbd754ea539f1ffaea91f1b6c4b8dd14bd");
assert_eq!(
array_bytes::bytes2hex("0x", Sign::signable_message(46, b"Darwinia", &[0; 32])),
"0xe52c7ebc7e478b623a16cc38469eca4aa1255bed6cd2599e529080d27ecaed32"
);
assert_eq!(
array_bytes::bytes2hex("0x", Sign::signable_message(45, b"Pangoro", &array_bytes::hex2bytes_unchecked("0x30a82982a8d5050d1c83bbea574aea301a4d317840a8c4734a308ffaa6a63bc8cb76085b00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000060000000000000000000000000000000000000000000000000000000000000000100000000000000000000000068898db1012808808c903f390909c52d9f7067490000000000000000000000004cdc1dbbd754ea539f1ffaea91f1b6c4b8dd14bd"))),
"0x9688cfb794c97094994409ed1c7c7caad076ae53ec13af8a370b55654f7bcb36"
array_bytes::bytes2hex("0x", Sign::eth_signable_message(45, b"Pangoro", &data)),
"0x4bddffe492f1091c1902d1952fc4673b12915f4b22822c6c84eacad574f11f2e"
);

let operation = Operation::SwapMembers {
Expand All @@ -208,7 +201,7 @@ fn signable_message() {
ethabi::Token::Uint(0.into()),
]);
assert_eq!(
array_bytes::bytes2hex("0x", Sign::signable_message(45, b"Pangoro", &encoded)),
"0x2ca922116daa8c7fec2b58362b58764e83f3b24e906fb50f58e3e1a2e208fb77"
array_bytes::bytes2hex("0x", Sign::eth_signable_message(45, b"Pangoro", &encoded)),
"0xe328aa10278425238407d49104ac5a55fd68e7f378b327c902d4d5035cfcfedf"
);
}
20 changes: 10 additions & 10 deletions pallet/ecdsa-authority/src/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ fn add_authority() {
assert_eq!(EcdsaAuthority::next_authorities(), vec![a_0]);
assert_eq!(EcdsaAuthority::nonce(), 0);
let message = array_bytes::hex_n_into_unchecked(
"0x5dcc31dcd194f2ccb42e13ed80001e37492f796d6d62514525fcf66de6f955c8",
"0x5c883184c9c53c59857253454df1b4813e8b3fb28648beb85555d58d1e801e14",
);
assert_eq!(
EcdsaAuthority::authorities_change_to_sign().unwrap(),
Expand Down Expand Up @@ -123,7 +123,7 @@ fn remove_authority() {
assert_eq!(EcdsaAuthority::next_authorities(), vec![a_2]);
assert_eq!(EcdsaAuthority::nonce(), 0);
let message = array_bytes::hex_n_into_unchecked(
"0xb59076c5054bc451c964b47af005b7b807b3501c36ef4d4375cb39637baea13b",
"0x76139aa9d1c7b35fc744b10444898ee5703e3f77406b926f903006436b7930c7",
);
assert_eq!(
EcdsaAuthority::authorities_change_to_sign().unwrap(),
Expand Down Expand Up @@ -182,7 +182,7 @@ fn swap_authority() {
assert_eq!(EcdsaAuthority::next_authorities(), vec![a_2]);
assert_eq!(EcdsaAuthority::nonce(), 0);
let message = array_bytes::hex_n_into_unchecked(
"0x0f9863685b4ef59a98fc26a063dad4713698af2d10af5f2ea921fed3f39fac71",
"0x30effc17a3fcf9b3079168c2c2be54b6d9fbdfd7077c9d844ec241dd70dd0507",
);
assert_eq!(
EcdsaAuthority::authorities_change_to_sign().unwrap(),
Expand Down Expand Up @@ -237,7 +237,7 @@ fn sync_interval_and_max_pending_period() {
});
run_to_block(sync_interval);
let message = array_bytes::hex_n_into_unchecked(
"0x7eba5c34eb163661830babd9d52b674f80812b4cde832429635352eb6f9225af",
"0x742776a31e49b3f5a2a15a6781eb99f96e8116bfc67aae652a08b9b1235146d2",
);
assert_eq!(
EcdsaAuthority::message_root_to_sign().unwrap(),
Expand Down Expand Up @@ -279,7 +279,7 @@ fn sync_interval_and_max_pending_period() {
});
run_to_block(offset + <<Runtime as Config>::MaxPendingPeriod as Get<BlockNumber>>::get());
let message = array_bytes::hex_n_into_unchecked(
"0x3e5c445233cc9d281c4fde6ffc5d1c57701d932afba5e6cea07f9b1e88d41fc6",
"0xafd9fc3dc135079be23746b4beb27255e5d3b4c5f3d05db766af751c0ed97920",
);
assert_eq!(
EcdsaAuthority::message_root_to_sign().unwrap(),
Expand Down Expand Up @@ -338,7 +338,7 @@ fn submit_authorities_change_signature() {
assert_ok!(EcdsaAuthority::add_authority(RuntimeOrigin::root(), a_3));
let operation = Operation::AddMember { new: a_3 };
let message = array_bytes::hex_n_into_unchecked(
"0x7c2560e894619daa9e7369148a97b05d16e1c439c2467b08f64af578aba9cb4a",
"0x3ad89c7824d6e83c180482c888a0af99baa95ce17a39285d6f943df5d95e7759",
);
assert_eq!(
EcdsaAuthority::authorities_change_to_sign().unwrap(),
Expand Down Expand Up @@ -400,7 +400,7 @@ fn submit_authorities_change_signature() {
},
Event::CollectingNewMessageRootSignatures {
message: array_bytes::hex_n_into_unchecked(
"0x1a8ed5724cc495c64b46b43c079e82e299aaac24f79deae23bbfea88e2e1abdc"
"0xe7bded73843f446f46b42ee0e0cc435f4f66fbcedf36c635c437a4d63bb44696"
)
}
]
Expand All @@ -426,7 +426,7 @@ fn submit_new_message_root_signature() {

run_to_block(<<Runtime as Config>::SyncInterval as Get<BlockNumber>>::get());
let message = array_bytes::hex_n_into_unchecked(
"0x7eba5c34eb163661830babd9d52b674f80812b4cde832429635352eb6f9225af",
"0x742776a31e49b3f5a2a15a6781eb99f96e8116bfc67aae652a08b9b1235146d2",
);
assert_eq!(
EcdsaAuthority::message_root_to_sign().unwrap(),
Expand Down Expand Up @@ -516,7 +516,7 @@ fn tx_fee() {
.for_each(|n| run_to_block(n));
run_to_block(<<Runtime as Config>::SyncInterval as Get<BlockNumber>>::get());
let message = array_bytes::hex_n_into_unchecked(
"0x7eba5c34eb163661830babd9d52b674f80812b4cde832429635352eb6f9225af",
"0x742776a31e49b3f5a2a15a6781eb99f96e8116bfc67aae652a08b9b1235146d2",
);

// Free for first-correct signature.
Expand All @@ -539,7 +539,7 @@ fn tx_fee() {

assert_ok!(EcdsaAuthority::remove_authority(RuntimeOrigin::root(), a_1));
let message = array_bytes::hex_n_into_unchecked(
"0x9c9af6df8ad32bce1fe3e8e4a1c638843786b2cc7f7932ff4d3f2de7b29b2632",
"0x24956af4b0842e1caec63782602c5a94089ba7c8ab8bd12d4243bb1a893b8af0",
);

// Free for first-correct signature.
Expand Down

0 comments on commit 2b1a07b

Please sign in to comment.