-
Notifications
You must be signed in to change notification settings - Fork 353
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
cw20-merkle-airdrop: change hashing to sha256 #374
Conversation
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.
Good stuff. Some nit-pick comments to improve coding style, but it looks good.
Glad to see the test vector. Can you just document the command you use in the TS code to generate that test data?
``` | ||
|
||
**Generate proof:** | ||
```shell | ||
merkle-airdrop-cli generateProofs --file ../testdata/airdrop_stage_2.json \ | ||
merkle-airdrop-cli generateProofs --file ../testdata/airdrop_stage_2_list.json \ |
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.
Ah, did you use the output of these as input to rust tests?
It does look like you have a place to generate test vectors.
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.
Yep exactly
if (hashBuf < proofBuf) { | ||
hashBuf = keccak256(Buffer.concat([hashBuf, proofBuf])); | ||
hashBuf = Buffer.from(sha256(Buffer.concat([hashBuf, proofBuf]).toString())); |
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.
why type does sha256 return? Why Buffer.from(sha256(a).toString())
?
Seems like there may be an easier way to transform it.
(Also if using Buffer.from, I think best to specify the input type. I think the default is hex
, but let's be specific)
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.
sha256 returns CryptoJS/WordArray
which is hard to work with. Only toString
method available.
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.
Well, best you could do with what you got.
@@ -16,6 +15,7 @@ use crate::msg::{ | |||
MerkleRootResponse, MigrateMsg, QueryMsg, | |||
}; | |||
use crate::state::{Config, CLAIM, CONFIG, LATEST_STAGE, MERKLE_ROOT}; | |||
use sha2::Digest; |
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'd move this up, same line where sha3 was
@@ -359,9 +360,33 @@ mod tests { | |||
); | |||
} | |||
|
|||
const TEST_DATA_1: &str = "./testdata/airdrop_stage_1_test_data.json"; |
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 like it!
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.
Looking above, I don't see the command that generates these test data.
Can you please add this to the README of the ts side (or a comment here)?
proofs: Vec<String>, | ||
} | ||
|
||
fn read_test_data(path: &str) -> Encoded { |
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.
There is a nice trick you can use...
Replace:
const TEST_DATA_1: &str = "./testdata/airdrop_stage_1_test_data.json";
let test_data = read_test_data(TEST_DATA_1);
with
const TEST_DATA_1: &[u8] = include_bytes!("./testdata/airdrop_stage_1_test_data.json");
let test_data: Encoded = from_slice(TEST_DATA_1).unwrap();
Then you can remove read_test_data
.
"280777995d054081cbf208bccb70f8d736c1766b81d90a1fd21cd97d2d83a5cc".to_string(), | ||
"3946ea1758a5a2bf55bae1186168ad35aa0329805bc8bff1ca3d51345faec04a".to_string(), | ||
], | ||
proof: test_data.proofs, |
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.
Nice to use this from those files.
Merging now, helper.ts works contract works. I will leave the rest to CosmJS DevRel person for learning content! |
No description provided.