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

cw20-ics20 incorrectly encodes ack_success. #759

Closed
0xekez opened this issue Jul 20, 2022 · 1 comment
Closed

cw20-ics20 incorrectly encodes ack_success. #759

0xekez opened this issue Jul 20, 2022 · 1 comment

Comments

@0xekez
Copy link
Contributor

0xekez commented Jul 20, 2022

The ICS 20 spec imagines the ACK success type to be JSON encoding of "binary 0x01 base64 encoded". They then suggest this to be the string "AQ==".

The ics20 implementation seems to do the JSON encoding of the ASCII character '1' (ASCII codepoint 49) wrapped in an enum.

fn ack_success() -> Binary {
let res = Ics20Ack::Result(b"1".into());
to_binary(&res).unwrap()
}

The result is that ack_success yields [123, 34, 114, 101, 115, 117, 108, 116, 34, 58, 34, 77, 81, 61, 61, 34, 125], whereas (I think) it ought to yield [34, 65, 81, 61, 61, 34]. The expected output is an array of bytes corresponding to ASCII character codes of AQ== surrounded by quotation marks (ASCII codepoint 34).

@0xekez
Copy link
Contributor Author

0xekez commented Jul 22, 2022

Looks like this is well tested. Figure this is more likely me misreading the spec, or some difference in the practical implementation.

#[test]
fn check_ack_json() {
let success = Ics20Ack::Result(b"1".into());
let fail = Ics20Ack::Error("bad coin".into());
let success_json = String::from_utf8(to_vec(&success).unwrap()).unwrap();
assert_eq!(r#"{"result":"MQ=="}"#, success_json.as_str());
let fail_json = String::from_utf8(to_vec(&fail).unwrap()).unwrap();
assert_eq!(r#"{"error":"bad coin"}"#, fail_json.as_str());
}

@0xekez 0xekez closed this as completed Jul 22, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant