diff --git a/cairo_programs/get_env.cairo b/cairo_programs/get_env.cairo new file mode 100644 index 0000000..0013e6c --- /dev/null +++ b/cairo_programs/get_env.cairo @@ -0,0 +1,56 @@ +// Represents an integer in the range [0, 2^256). +struct Uint256 { + // The low 128 bits of the value. + low: felt, + // The high 128 bits of the value. + high: felt, +} + +// @notice Store all environment data relevant to the current execution context. +// @param origin The origin of the transaction. +// @param gas_price The gas price for the call. +// @param chain_id The chain id of the current block. +// @param prev_randao The previous RANDAO value. +// @param block_number The block number of the current block. +// @param block_gas_limit The gas limit for the current block. +// @param block_timestamp The timestamp of the current block. +// @param coinbase The address of the miner of the current block. +// @param base_fee The basefee of the current block. +struct Environment { + origin: felt, + gas_price: felt, + chain_id: felt, + prev_randao: Uint256, + block_number: felt, + block_gas_limit: felt, + block_timestamp: felt, + coinbase: felt, + base_fee: felt, +} + +// @notice Populate an Environment with hint +func get_env() -> Environment* { + tempvar env = cast(nondet %{ segments.add() %}, Environment*); + + // The hint should populate env. + %{ get_env %} + + return env; +} + +func main() { + let env = get_env(); + %{ + print(f"{ids.origin=}") + print(f"{ids.gas_price=}") + print(f"{ids.chain_id=}") + print(f"{ids.prev_randao=}") + print(f"{ids.block_number=}") + print(f"{ids.block_gas_limit=}") + print(f"{ids.block_timestamp=}") + print(f"{ids.coinbase=}") + print(f"{ids.base_fee=}") + %} + + return (); +} diff --git a/cairo_programs/get_env.json b/cairo_programs/get_env.json new file mode 100644 index 0000000..d6aa187 --- /dev/null +++ b/cairo_programs/get_env.json @@ -0,0 +1,259 @@ +{ + "attributes": [], + "builtins": [], + "compiler_version": "0.13.1", + "data": [ + "0x40780017fff7fff", + "0x0", + "0x1104800180018000", + "0x7", + "0x10780017fff7fff", + "0x0", + "0x40780017fff7fff", + "0x1", + "0x208b7fff7fff7ffe", + "0x1104800180018000", + "0x800000000000010fffffffffffffffffffffffffffffffffffffffffffffffe", + "0x208b7fff7fff7ffe" + ], + "debug_info": null, + "hints": { + "6": [ + { + "accessible_scopes": ["__main__", "__main__.get_env"], + "code": "memory[ap] = to_felt_or_relocatable(segments.add())", + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 0 + }, + "reference_ids": {} + } + } + ], + "8": [ + { + "accessible_scopes": ["__main__", "__main__.get_env"], + "code": "get_env", + "flow_tracking_data": { + "ap_tracking": { + "group": 2, + "offset": 1 + }, + "reference_ids": { + "__main__.get_env.__temp0": 0, + "__main__.get_env.env": 1 + } + } + } + ], + "11": [ + { + "accessible_scopes": ["__main__", "__main__.main"], + "code": "print(f\"{ids.origin=}\")\nprint(f\"{ids.gas_price=}\")\nprint(f\"{ids.chain_id=}\")\nprint(f\"{ids.prev_randao=}\")\nprint(f\"{ids.block_number=}\")\nprint(f\"{ids.block_gas_limit=}\")\nprint(f\"{ids.block_timestamp=}\")\nprint(f\"{ids.coinbase=}\")\nprint(f\"{ids.base_fee=}\")", + "flow_tracking_data": { + "ap_tracking": { + "group": 3, + "offset": 3 + }, + "reference_ids": { + "__main__.main.env": 2 + } + } + } + ] + }, + "identifiers": { + "__main__.Environment": { + "full_name": "__main__.Environment", + "members": { + "base_fee": { + "cairo_type": "felt", + "offset": 9 + }, + "block_gas_limit": { + "cairo_type": "felt", + "offset": 6 + }, + "block_number": { + "cairo_type": "felt", + "offset": 5 + }, + "block_timestamp": { + "cairo_type": "felt", + "offset": 7 + }, + "chain_id": { + "cairo_type": "felt", + "offset": 2 + }, + "coinbase": { + "cairo_type": "felt", + "offset": 8 + }, + "gas_price": { + "cairo_type": "felt", + "offset": 1 + }, + "origin": { + "cairo_type": "felt", + "offset": 0 + }, + "prev_randao": { + "cairo_type": "__main__.Uint256", + "offset": 3 + } + }, + "size": 10, + "type": "struct" + }, + "__main__.Uint256": { + "full_name": "__main__.Uint256", + "members": { + "high": { + "cairo_type": "felt", + "offset": 1 + }, + "low": { + "cairo_type": "felt", + "offset": 0 + } + }, + "size": 2, + "type": "struct" + }, + "__main__.__end__": { + "pc": 4, + "type": "label" + }, + "__main__.__start__": { + "pc": 0, + "type": "label" + }, + "__main__.get_env": { + "decorators": [], + "pc": 6, + "type": "function" + }, + "__main__.get_env.Args": { + "full_name": "__main__.get_env.Args", + "members": {}, + "size": 0, + "type": "struct" + }, + "__main__.get_env.ImplicitArgs": { + "full_name": "__main__.get_env.ImplicitArgs", + "members": {}, + "size": 0, + "type": "struct" + }, + "__main__.get_env.Return": { + "cairo_type": "__main__.Environment*", + "type": "type_definition" + }, + "__main__.get_env.SIZEOF_LOCALS": { + "type": "const", + "value": 0 + }, + "__main__.get_env.__temp0": { + "cairo_type": "felt", + "full_name": "__main__.get_env.__temp0", + "references": [ + { + "ap_tracking_data": { + "group": 2, + "offset": 1 + }, + "pc": 8, + "value": "[cast(ap + (-1), felt*)]" + } + ], + "type": "reference" + }, + "__main__.get_env.env": { + "cairo_type": "__main__.Environment*", + "full_name": "__main__.get_env.env", + "references": [ + { + "ap_tracking_data": { + "group": 2, + "offset": 1 + }, + "pc": 8, + "value": "[cast(ap + (-1), __main__.Environment**)]" + } + ], + "type": "reference" + }, + "__main__.main": { + "decorators": [], + "pc": 9, + "type": "function" + }, + "__main__.main.Args": { + "full_name": "__main__.main.Args", + "members": {}, + "size": 0, + "type": "struct" + }, + "__main__.main.ImplicitArgs": { + "full_name": "__main__.main.ImplicitArgs", + "members": {}, + "size": 0, + "type": "struct" + }, + "__main__.main.Return": { + "cairo_type": "()", + "type": "type_definition" + }, + "__main__.main.SIZEOF_LOCALS": { + "type": "const", + "value": 0 + }, + "__main__.main.env": { + "cairo_type": "__main__.Environment*", + "full_name": "__main__.main.env", + "references": [ + { + "ap_tracking_data": { + "group": 3, + "offset": 3 + }, + "pc": 11, + "value": "[cast(ap + (-1), __main__.Environment**)]" + } + ], + "type": "reference" + } + }, + "main_scope": "__main__", + "prime": "0x800000000000011000000000000000000000000000000000000000000000001", + "reference_manager": { + "references": [ + { + "ap_tracking_data": { + "group": 2, + "offset": 1 + }, + "pc": 8, + "value": "[cast(ap + (-1), felt*)]" + }, + { + "ap_tracking_data": { + "group": 2, + "offset": 1 + }, + "pc": 8, + "value": "[cast(ap + (-1), __main__.Environment**)]" + }, + { + "ap_tracking_data": { + "group": 3, + "offset": 3 + }, + "pc": 11, + "value": "[cast(ap + (-1), __main__.Environment**)]" + } + ] + } +}