pub struct AxiomAPI<'a> {
pub builder: &'a mut RlcCircuitBuilder<Fr>,
pub range: &'a RangeChip<Fr>,
/* private fields */
}Expand description
Axiom Circuit API for making both subquery calls (e.g. get_account, get_header, etc.) and for more general ZK primitives (e.g. add, mul, etc.).
Fields§
§builder: &'a mut RlcCircuitBuilder<Fr>The halo2-lib struct used to construct the circuit
range: &'a RangeChip<Fr>The main chip for ZK primitives
Implementations§
source§impl<'a> AxiomAPI<'a>
impl<'a> AxiomAPI<'a>
pub fn new( builder: &'a mut RlcCircuitBuilder<Fr>, range: &'a RangeChip<Fr>, subquery_caller: Arc<Mutex<SubqueryCaller<Http, Fr>>> ) -> Self
sourcepub fn subquery_caller(&self) -> Arc<Mutex<SubqueryCaller<Http, Fr>>>
pub fn subquery_caller(&self) -> Arc<Mutex<SubqueryCaller<Http, Fr>>>
Returns a thread-safe SubqueryCaller object.
sourcepub fn ctx(&mut self) -> &mut Context<Fr>
pub fn ctx(&mut self) -> &mut Context<Fr>
Returns a mutable reference to the Context of a gate thread. Spawns a new thread for the given phase, if none exists.
phase: The challenge phase (as an index) of the gate thread.
Examples found in repository?
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn compute(
api: &mut AxiomAPI,
assigned_inputs: AccountAgeCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
let zero = api.ctx().load_zero();
let one = api.ctx().load_constant(Fr::one());
let prev_block = api
.range
.gate()
.sub(api.ctx(), assigned_inputs.claimed_block_number, one);
let account_prev_block = api.get_account(prev_block, assigned_inputs.addr);
let prev_nonce = account_prev_block.call(AccountField::Nonce);
let prev_nonce = api.from_hi_lo(prev_nonce);
api.ctx().constrain_equal(&prev_nonce, &zero);
let account = api.get_account(assigned_inputs.claimed_block_number, assigned_inputs.addr);
let curr_nonce = account.call(AccountField::Nonce);
let curr_nonce = api.from_hi_lo(curr_nonce);
api.range.check_less_than(api.ctx(), zero, curr_nonce, 40);
vec![
assigned_inputs.addr.into(),
assigned_inputs.claimed_block_number.into(),
]
}More examples
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn from_hi_lo(&mut self, hilo: HiLo<AssignedValue<Fr>>) -> AssignedValue<Fr>
pub fn from_hi_lo(&mut self, hilo: HiLo<AssignedValue<Fr>>) -> AssignedValue<Fr>
Returns an AssignedValue<Fr> from a HiLo<AssignedValue<Fr>>.
NOTE: this can fail if the hi-lo pair is greater than the Fr modulus. See check_hi_lo for what is constrained.
hilo- TheHiLo<AssignedValue<Fr>>object to convert.
Examples found in repository?
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn compute(
api: &mut AxiomAPI,
assigned_inputs: AccountAgeCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
let zero = api.ctx().load_zero();
let one = api.ctx().load_constant(Fr::one());
let prev_block = api
.range
.gate()
.sub(api.ctx(), assigned_inputs.claimed_block_number, one);
let account_prev_block = api.get_account(prev_block, assigned_inputs.addr);
let prev_nonce = account_prev_block.call(AccountField::Nonce);
let prev_nonce = api.from_hi_lo(prev_nonce);
api.ctx().constrain_equal(&prev_nonce, &zero);
let account = api.get_account(assigned_inputs.claimed_block_number, assigned_inputs.addr);
let curr_nonce = account.call(AccountField::Nonce);
let curr_nonce = api.from_hi_lo(curr_nonce);
api.range.check_less_than(api.ctx(), zero, curr_nonce, 40);
vec![
assigned_inputs.addr.into(),
assigned_inputs.claimed_block_number.into(),
]
}sourcepub fn to_hi_lo(&mut self, val: AssignedValue<Fr>) -> HiLo<AssignedValue<Fr>>
pub fn to_hi_lo(&mut self, val: AssignedValue<Fr>) -> HiLo<AssignedValue<Fr>>
Returns a 256-bit HiLo<AssignedValue<Fr>> from a AssignedValue<Fr>.
See check_hi_lo for what is constrained.
val- TheAssignedValue<Fr>object to convert.
sourcepub fn to_bytes_be(
&mut self,
uint: AssignedValue<Fr>,
num_bytes: usize
) -> Vec<AssignedValue<Fr>>
pub fn to_bytes_be( &mut self, uint: AssignedValue<Fr>, num_bytes: usize ) -> Vec<AssignedValue<Fr>>
Decomposes a AssignedValue<Fr> into bytes, in big-endian, and returns the bytes.
uint- TheAssignedValue<Fr>object to convert.num_bytes- The number of bytes inuint.
sourcepub fn get_account(
&mut self,
block_number: AssignedValue<Fr>,
addr: AssignedValue<Fr>
) -> Account<'_>
pub fn get_account( &mut self, block_number: AssignedValue<Fr>, addr: AssignedValue<Fr> ) -> Account<'_>
Returns an Account builder given block number and address.
block_number- The block number as anAssignedValue<Fr>.addr- The address as anAssignedValue<Fr>.
Examples found in repository?
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
fn compute(
api: &mut AxiomAPI,
assigned_inputs: AccountAgeCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
let zero = api.ctx().load_zero();
let one = api.ctx().load_constant(Fr::one());
let prev_block = api
.range
.gate()
.sub(api.ctx(), assigned_inputs.claimed_block_number, one);
let account_prev_block = api.get_account(prev_block, assigned_inputs.addr);
let prev_nonce = account_prev_block.call(AccountField::Nonce);
let prev_nonce = api.from_hi_lo(prev_nonce);
api.ctx().constrain_equal(&prev_nonce, &zero);
let account = api.get_account(assigned_inputs.claimed_block_number, assigned_inputs.addr);
let curr_nonce = account.call(AccountField::Nonce);
let curr_nonce = api.from_hi_lo(curr_nonce);
api.range.check_less_than(api.ctx(), zero, curr_nonce, 40);
vec![
assigned_inputs.addr.into(),
assigned_inputs.claimed_block_number.into(),
]
}More examples
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn get_header(&mut self, block_number: AssignedValue<Fr>) -> Header<'_>
pub fn get_header(&mut self, block_number: AssignedValue<Fr>) -> Header<'_>
Returns a Header builder given block number.
block_number- The block number as anAssignedValue<Fr>.
Examples found in repository?
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn get_mapping(
&mut self,
block_number: AssignedValue<Fr>,
addr: AssignedValue<Fr>,
mapping_slot: HiLo<AssignedValue<Fr>>
) -> SolidityMapping<'_>
pub fn get_mapping( &mut self, block_number: AssignedValue<Fr>, addr: AssignedValue<Fr>, mapping_slot: HiLo<AssignedValue<Fr>> ) -> SolidityMapping<'_>
Returns a SolidityMapping builder given block number, address, and mapping slot.
block_number- The block number as anAssignedValue<Fr>.addr- The address as anAssignedValue<Fr>.mapping_slot- The mapping slot as aHiLo<AssignedValue<Fr>.
Examples found in repository?
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn get_receipt(
&mut self,
block_number: AssignedValue<Fr>,
tx_idx: AssignedValue<Fr>
) -> Receipt<'_>
pub fn get_receipt( &mut self, block_number: AssignedValue<Fr>, tx_idx: AssignedValue<Fr> ) -> Receipt<'_>
Returns a Receipt builder given block number and transaction index.
block_number- The block number as anAssignedValue<Fr>.tx_idx- The transaction index as anAssignedValue<Fr>.
Examples found in repository?
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn get_storage(
&mut self,
block_number: AssignedValue<Fr>,
addr: AssignedValue<Fr>
) -> Storage<'_>
pub fn get_storage( &mut self, block_number: AssignedValue<Fr>, addr: AssignedValue<Fr> ) -> Storage<'_>
Returns a Storage builder given block number and address.
block_number- The block number as anAssignedValue<Fr>.addr- The address as anAssignedValue<Fr>.
Examples found in repository?
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn get_tx(
&mut self,
block_number: AssignedValue<Fr>,
tx_idx: AssignedValue<Fr>
) -> Tx<'_>
pub fn get_tx( &mut self, block_number: AssignedValue<Fr>, tx_idx: AssignedValue<Fr> ) -> Tx<'_>
Returns a Tx builder given block number and transaction index.
block_number- The block number as anAssignedValue<Fr>.tx_idx- The transaction index as anAssignedValue<Fr>.
Examples found in repository?
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101
fn compute(
api: &mut AxiomAPI,
assigned_inputs: QuickstartCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
// fetch block header data
// access the timestamp field
let _timestamp = api
.get_header(assigned_inputs.block)
.call(HeaderField::Timestamp);
// access the gasLimit field
let _gas_limit = api
.get_header(assigned_inputs.block)
.call(HeaderField::GasLimit);
// fetch account data
// access the account balance
let _balance = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Balance);
// access the account nonce
let _nonce = api
.get_account(assigned_inputs.block, assigned_inputs.addr)
.call(AccountField::Nonce);
//fetch storage data
let storage = api.get_storage(assigned_inputs.block, assigned_inputs.addr);
let _slot_val = storage.slot(assigned_inputs.slot);
//fetch Solidity mapping data
let key = [0, 3].map(|i| api.ctx().load_constant(Fr::from(i)));
let mapping = api.get_mapping(
assigned_inputs.block,
assigned_inputs.addr,
assigned_inputs.mapping_slot,
);
let _mapping_val = mapping.key(HiLo::from_hi_lo(key));
// fetch transaction data, example is for the transaction below:
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc
// get the 4-byte function selector that was called
let _function_selector = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.call(TxField::FunctionSelector);
// access bytes [32, 64) of calldata
let calldata_idx = api.ctx().load_constant(Fr::from(1));
let _calldata = api
.get_tx(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.calldata(calldata_idx);
// fetch receipt data, example is for the first event log in the transaction below
// Transfer (index_topic_1 address from, index_topic_2 address to, uint256 tokens)
// https://sepolia.etherscan.io/tx/0xf518bd931eae8dc4178e1f8a3b64d6312af33f8c5df0c2cd4a38b72f4fb2d7dc#eventlog
// eventSchema = keccak(Transfer(address,address,uint256))
let event_schema =
H256::from_str("0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef")
.unwrap();
let log_idx = api.ctx().load_constant(Fr::from(0));
let topic_idx = api.ctx().load_constant(Fr::from(1));
let data_idx = api.ctx().load_constant(Fr::from(0));
// access the address that emitted the log event at index 0
let _addr = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.address();
// access the topic at index 1 of the log event at index 0 and check it has schema eventSchema
// because `address` is indexed in the event, this corresponds to `address`
let _topic = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.topic(topic_idx, Some(event_schema));
// access the first 32 bytes of data in the log event at index 0
// because `amt` is not indexed, this corresponds to `amt`
let _data = api
.get_receipt(assigned_inputs.tx_block_number, assigned_inputs.tx_idx)
.log(log_idx)
.data(data_idx, Some(event_schema));
vec![]
}sourcepub fn keccak_fix_len(
&mut self,
bytes: Vec<AssignedValue<Fr>>
) -> HiLo<AssignedValue<Fr>>
pub fn keccak_fix_len( &mut self, bytes: Vec<AssignedValue<Fr>> ) -> HiLo<AssignedValue<Fr>>
Examples found in repository?
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn compute(
api: &mut AxiomAPI,
assigned_inputs: KeccakCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
let a = api.keccak_fix_len(vec![
assigned_inputs.a,
assigned_inputs.b,
assigned_inputs.c,
]);
let b = api.keccak_var_len(
vec![assigned_inputs.a, assigned_inputs.b, assigned_inputs.c],
assigned_inputs.len,
3,
);
vec![a.into(), b.into()]
}sourcepub fn keccak_var_len(
&mut self,
bytes: Vec<AssignedValue<Fr>>,
len: AssignedValue<Fr>,
max_len: usize
) -> HiLo<AssignedValue<Fr>>
pub fn keccak_var_len( &mut self, bytes: Vec<AssignedValue<Fr>>, len: AssignedValue<Fr>, max_len: usize ) -> HiLo<AssignedValue<Fr>>
Examples found in repository?
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
fn compute(
api: &mut AxiomAPI,
assigned_inputs: KeccakCircuitInput<AssignedValue<Fr>>,
) -> Vec<AxiomResult> {
let a = api.keccak_fix_len(vec![
assigned_inputs.a,
assigned_inputs.b,
assigned_inputs.c,
]);
let b = api.keccak_var_len(
vec![assigned_inputs.a, assigned_inputs.b, assigned_inputs.c],
assigned_inputs.len,
3,
);
vec![a.into(), b.into()]
}pub fn keccak_fix_len_unsafe( &mut self, bytes: Vec<AssignedValue<Fr>> ) -> HiLo<AssignedValue<Fr>>
pub fn keccak_var_len_unsafe( &mut self, bytes: Vec<AssignedValue<Fr>>, len: AssignedValue<Fr>, max_len: usize ) -> HiLo<AssignedValue<Fr>>
Auto Trait Implementations§
impl<'a> Freeze for AxiomAPI<'a>
impl<'a> !RefUnwindSafe for AxiomAPI<'a>
impl<'a> Send for AxiomAPI<'a>
impl<'a> !Sync for AxiomAPI<'a>
impl<'a> Unpin for AxiomAPI<'a>
impl<'a> !UnwindSafe for AxiomAPI<'a>
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> FmtForward for T
impl<T> FmtForward for T
source§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self to use its Binary implementation when Debug-formatted.source§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self to use its Display implementation when
Debug-formatted.source§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self to use its LowerExp implementation when
Debug-formatted.source§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self to use its LowerHex implementation when
Debug-formatted.source§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self to use its Octal implementation when Debug-formatted.source§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self to use its Pointer implementation when
Debug-formatted.source§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self to use its UpperExp implementation when
Debug-formatted.source§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self to use its UpperHex implementation when
Debug-formatted.source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Instrument for T
impl<T> Instrument for T
source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
source§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
source§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self and passes that borrow into the pipe function. Read moresource§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
source§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R ) -> R
source§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self, then passes self.as_ref() into the pipe function.source§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self, then passes self.as_mut() into the pipe
function.source§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self, then passes self.deref() into the pipe function.source§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<F, Fp, Pt, FC> Selectable<F, Reduced<Pt, Fp>> for FC
impl<F, Fp, Pt, FC> Selectable<F, Reduced<Pt, Fp>> for FC
source§impl<T> Tap for T
impl<T> Tap for T
source§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B> of a value. Read moresource§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B> of a value. Read moresource§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R> view of a value. Read moresource§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R> view of a value. Read moresource§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target of a value. Read moresource§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target of a value. Read moresource§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap() only in debug builds, and is erased in release builds.source§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut() only in debug builds, and is erased in release
builds.source§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow() only in debug builds, and is erased in release
builds.source§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut() only in debug builds, and is erased in release
builds.source§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref() only in debug builds, and is erased in release
builds.source§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut() only in debug builds, and is erased in release
builds.source§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref() only in debug builds, and is erased in release
builds.