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

[WIP] Support Variables in Syntax #4

Open
wants to merge 87 commits into
base: main
Choose a base branch
from

Conversation

michaeljklein
Copy link
Contributor

Support an assignment-based syntax for manipulating the stack: we compile to the stack-based language by keeping track of a context of variables mapped to the stack.

The result currently looks like this:

input_json = unpack_json(INPUT)

queries = unpack_json(lookup("queries", input_json))
first_query = unpack_json(index("0", queries))

_ = assert(check_eq(unpack_json(lookup("action", first_query)), "tokenbalance"))
_ = assert(check_eq(unpack_json(lookup("contractaddress", first_query)), "0x57d90b64a1a57749b0f932f1a3395792e12e7055"))
_ = assert(check_eq(unpack_json(lookup("result"), unpack_json(lookup("response", first_query))), "135499"))

prompts = unpack_json(lookup("prompts", input_json))
first_prompt = unpack_json(lookup("0", prompts))

_ = assert(check_eq(unpack_json(lookup("action", first_prompt)), "siwe"))
_ = assert(check_eq(unpack_json(lookup("version", first_prompt)), "1.1.0"))
_ = assert(check_eq(unpack_json(lookup("address", unpack_json(lookup("fields", unpack_json(lookup("data", first_prompt)))))), "0xe04f27eb70e025b78871a2ad7eabe85e61212761"))

message_hash = hash_sha256(string_to_bytes(unpack_json(lookup("message", unpack_json(lookup("data", first_prompt))))))
address_hash = hash_sha256(string_to_bytes(unpack_json(lookup("address", unpack_json(lookup("fields", unpack_json(lookup("data", first_prompt))))))))

// Comments look like this
_ = assert(check_eq(hash_sha256(concat(message_hash, address_hash)), "0x35a3b28b7abbab2f2a87afb0f00b0a98e4ee6acd8444504fbc367cf261841f8b"))

…nd of file not being accepted, add integration test, begin converting to untyped instructions
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

Successfully merging this pull request may close these issues.

None yet

1 participant