Merge pull request #1750 from AleoHQ/address-check

Address check
This commit is contained in:
Collin Chin 2022-04-19 12:56:27 -07:00 committed by GitHub
commit 645b5a2be7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
10 changed files with 665 additions and 218 deletions

821
Cargo.lock generated

File diff suppressed because it is too large Load Diff

View File

@ -38,6 +38,10 @@ version = "1.5.3"
path = "../../leo/span"
version = "1.5.3"
[dependencies.snarkvm-dpc]
git = "https://github.com/AleoHQ/snarkVM.git"
rev = "85b7a79"
[dependencies.indexmap]
version = "1.8"

View File

@ -17,10 +17,11 @@
use crate::tokenizer::{Char, Token};
use leo_errors::{ParserError, Result};
use leo_span::{Span, Symbol};
use snarkvm_dpc::{prelude::*, testnet2::Testnet2};
use serde::{Deserialize, Serialize};
use std::{fmt, iter::Peekable};
use std::{fmt, iter::Peekable, str::FromStr};
///
/// Returns a new `StrTendril` string if an identifier can be eaten, otherwise returns [`None`].
@ -458,16 +459,8 @@ impl fmt::Debug for SpannedToken {
}
///
/// Returns true if the given string looks like Aleo address.
/// This method DOES NOT check if the address is valid on-chain.
/// Returns true if the given string is a valid Aleo address.
///
pub(crate) fn check_address(address: &str) -> bool {
// "aleo1" (LOWERCASE_LETTER | ASCII_DIGIT){58}
if !address.starts_with("aleo1") || address.len() != 63 {
return false;
}
address
.chars()
.skip(5)
.all(|x| x.is_ascii_lowercase() || x.is_ascii_digit())
Address::<Testnet2>::from_str(address).is_ok()
}

View File

@ -3,6 +3,7 @@ type str = [char; _];
function main(y: bool) -> bool {
let s = "abc";
let a: address = aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9;
return (first_el(s) == 'a') == y;
}

View File

@ -3,9 +3,6 @@ namespace: Token
expectation: Pass
outputs:
- "'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9' @ 1:1-64"
- "'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9' @ 1:1-64"
- "'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d9' @ 1:1-64"
- "'aleo1aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st' @ 1:1-64"
- "'ALEO1' @ 1:1-6"
- "'Aleo1' @ 1:1-6"
- "'aleO1' @ 1:1-6"

View File

@ -4,6 +4,7 @@ expectation: Fail
outputs:
- "Error [EPAR0370001]: invalid address literal: 'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d1aleo1'\n --> test:1:1\n |\n 1 | aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d1aleo1\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
- "Error [EPAR0370001]: invalid address literal: 'aleo1qnr4dkkvkgfqph0vzc3y6Z2eu975wnpz2925ntjccd5cfqxtyu8sta57J9'\n --> test:1:1\n |\n 1 | aleo1qnr4dkkvkgfqph0vzc3y6Z2eu975wnpz2925ntjccd5cfqxtyu8sta57J9\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
- "Error [EPAR0370001]: invalid address literal: 'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9'\n --> test:1:1\n |\n 1 | aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
- "Error [EPAR0370001]: invalid address literal: 'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d'\n --> test:1:1\n |\n 1 | aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"
- "Error [EPAR0370001]: invalid address literal: 'aleo1'\n --> test:1:1\n |\n 1 | aleo1\n | ^^^^^"
- "Error [EPAR0370001]: invalid address literal: 'aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st'\n --> test:1:1\n |\n 1 | aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st\n | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^"

View File

@ -12,33 +12,3 @@ outputs:
col_stop: 64
path: ""
content: aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9
- Value:
Address:
- aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9
- span:
line_start: 1
line_stop: 1
col_start: 1
col_stop: 64
path: ""
content: aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9
- Value:
Address:
- aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d9
- span:
line_start: 1
line_stop: 1
col_start: 1
col_stop: 64
path: ""
content: aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d9
- Value:
Address:
- aleo1aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st
- span:
line_start: 1
line_stop: 1
col_start: 1
col_stop: 64
path: ""
content: aleo1aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st

View File

@ -3,9 +3,6 @@ namespace: Token
expectation: Pass
*/
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d9
aleo1aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st
ALEO1
Aleo1

View File

@ -6,6 +6,8 @@ aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d1aleo1
aleo1qnr4dkkvkgfqph0vzc3y6Z2eu975wnpz2925ntjccd5cfqxtyu8sta57J9
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d
aleo1

View File

@ -4,6 +4,3 @@ expectation: Pass
*/
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8s7pyjh9
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57j9
aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8sta57d9
aleo1aleo1qnr4dkkvkgfqph0vzc3y6z2eu975wnpz2925ntjccd5cfqxtyu8st