Podlog language v1 (#225)

* Initial commit for Podlog language

* Spell-checker thinks that 'lits' is a bad abbreviation for 'literals'

* Enable SetContains/SetNotContains

* Update language based on review feedback

* Typo/comment fix

* Make native predicates case-sensitive

* Enforce max batch size in CustomPredicateBatchBuilder

* Remove some unnecessary checks for things handled by the grammar

* Clean up more unnecessary error-checking

* Typo

* Simplify hex processing

* Replace various errors with unreachable!()

* Translate from big-endian hex string to little-endian RawValue

* Update hex en/decoding functions
This commit is contained in:
Rob Knight 2025-06-07 07:17:23 +02:00 committed by GitHub
parent e8edbbc1c5
commit 541c264586
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
11 changed files with 2259 additions and 29 deletions

View file

@ -190,15 +190,22 @@ impl fmt::Display for Hash {
impl FromHex for Hash {
type Error = FromHexError;
// TODO make it dependant on backend::Value len
fn from_hex<T: AsRef<[u8]>>(hex: T) -> Result<Self, Self::Error> {
// In little endian
// The input `hex` is a big-endian hex string.
let bytes = <[u8; 32]>::from_hex(hex)?;
let mut buf: [u8; 8] = [0; 8];
let mut inner = [F::ZERO; HASH_SIZE];
for i in 0..HASH_SIZE {
buf.copy_from_slice(&bytes[8 * i..8 * (i + 1)]);
inner[i] = F::from_canonical_u64(u64::from_le_bytes(buf));
let start = i * 8;
let end = start + 8;
let chunk: [u8; 8] = bytes[start..end]
.try_into()
.expect("slice with incorrect length");
// We read big-endian chunks from a big-endian string,
// and place them into a little-endian limb array.
let u64_val = u64::from_be_bytes(chunk);
inner[HASH_SIZE - 1 - i] = F::from_canonical_u64(u64_val);
}
Ok(Self(inner))
}