Transaction Hash:
Block:
19431116 at Mar-14-2024 05:15:59 AM +UTC
Transaction Fee:
0.002844314549549886 ETH
$7.20
Gas Used:
55,923 Gas / 50.861265482 Gwei
Emitted Events:
261 |
MemoryPageFactRegistry.LogMemoryPageFactContinuous( factHash=8F06B794DD2EAFAD26A5BF105828E3DA1D137AD89AEE3A8B1530E50EB763C2E3, memoryHash=31143792422357125956136570212349222174659815935198650998945723269813059779108, prod=1941343588550860877169382983830675855638880660329067194558989874681233685718 )
|
Account State Difference:
Address | Before | After | State Difference | ||
---|---|---|---|---|---|
0x22A82147...9F18B5F76 |
415.568704438400289352 Eth
Nonce: 59633
|
415.565860123850739466 Eth
Nonce: 59634
| 0.002844314549549886 | ||
0x40864568...5130770fA | |||||
0x4675C7e5...ef3b0a263
Miner
| (Coinbase: MEV Builder) | 17.415864330646489873 Eth | 17.415869922946489873 Eth | 0.0000055923 |
Execution Trace
MemoryPageFactRegistry.registerContinuousMemoryPage( startAddr=2182442, values=[2435607108997582786771901057892768047649255032877514444651484127207078904436, 3441701461740985193353354815027099667831295359397007037425759061286358482448, 612911, 2016335904870237797605318455715579131150933704095328870884726667896961766313, 2590421891839256512113614983194993186457498815986333310670788206383913888162, 1, 1699220348254338357247455685424245298964558880443906702675, 4492882960061430110321955904980916581440851647481104496812, 3298583324788051363309164828457355449306250735229724395924461290624391330444, 272018102616998961513253712823009419869, 1169280361081424154365739659824815639, 0, 0], z=2686077624364687476520659586755188865094698171606399620290786772791655967150, alpha=213493137009243694554915727902255894717654307900266226341663365079545950917, prime=3618502788666131213697322783095070105623107215331596699973092056135872020481 ) => ( factHash=8F06B794DD2EAFAD26A5BF105828E3DA1D137AD89AEE3A8B1530E50EB763C2E3, memoryHash=31143792422357125956136570212349222174659815935198650998945723269813059779108, prod=1941343588550860877169382983830675855638880660329067194558989874681233685718 )
registerContinuousMemoryPage[MemoryPageFactRegistry (ln:230)]
LogMemoryPageFactContinuous[MemoryPageFactRegistry (ln:344)]
registerFact[MemoryPageFactRegistry (ln:345)]
/* Copyright 2019-2023 StarkWare Industries Ltd. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.starkware.co/open-source-license/ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12; import "../interfaces/IQueryableFactRegistry.sol"; contract FactRegistry is IQueryableFactRegistry { // Mapping: fact hash -> true. mapping(bytes32 => bool) private verifiedFact; // Indicates whether the Fact Registry has at least one fact registered. bool anyFactRegistered = false; /* Checks if a fact was registered. */ function isValid(bytes32 fact) external view virtual override returns (bool) { return internalIsValid(fact); } /* The internal implementation that checks if the fact was registered. */ function internalIsValid(bytes32 fact) internal view virtual returns (bool) { return verifiedFact[fact]; } function registerFact(bytes32 factHash) internal { // This function stores the fact hash in the mapping. verifiedFact[factHash] = true; // Mark first time off. if (!anyFactRegistered) { anyFactRegistered = true; } } /* Indicates whether at least one fact was registered. */ function hasRegisteredFact() external view override returns (bool) { return anyFactRegistered; } } /* Copyright 2019-2023 StarkWare Industries Ltd. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.starkware.co/open-source-license/ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12; /* The Fact Registry design pattern is a way to separate cryptographic verification from the business logic of the contract flow. A fact registry holds a hash table of verified "facts" which are represented by a hash of claims that the registry hash check and found valid. This table may be queried by accessing the isValid() function of the registry with a given hash. In addition, each fact registry exposes a registry specific function for submitting new claims together with their proofs. The information submitted varies from one registry to the other depending of the type of fact requiring verification. For further reading on the Fact Registry design pattern see this `StarkWare blog post <https://medium.com/starkware/the-fact-registry-a64aafb598b6>`_. */ interface IFactRegistry { /* Returns true if the given fact was previously registered in the contract. */ function isValid(bytes32 fact) external view returns (bool); } /* Copyright 2019-2023 StarkWare Industries Ltd. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.starkware.co/open-source-license/ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12; import "./IFactRegistry.sol"; /* Extends the IFactRegistry interface with a query method that indicates whether the fact registry has successfully registered any fact or is still empty of such facts. */ interface IQueryableFactRegistry is IFactRegistry { /* Returns true if at least one fact has been registered. */ function hasRegisteredFact() external view returns (bool); } /* Copyright 2019-2023 StarkWare Industries Ltd. Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. You may obtain a copy of the License at https://www.starkware.co/open-source-license/ Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ // SPDX-License-Identifier: Apache-2.0. pragma solidity ^0.6.12; import "../../components/FactRegistry.sol"; contract MemoryPageFactRegistryConstants { // A page based on a list of pairs (address, value). // In this case, memoryHash = hash(address, value, address, value, address, value, ...). uint256 internal constant REGULAR_PAGE = 0; // A page based on adjacent memory cells, starting from a given address. // In this case, memoryHash = hash(value, value, value, ...). uint256 internal constant CONTINUOUS_PAGE = 1; } /* A fact registry for the claim: I know n pairs (addr, value) for which the hash of the pairs is memoryHash, and the cumulative product: \\prod_i( z - (addr_i + alpha * value_i) ) is prod. The exact format of the hash depends on the type of the page (see MemoryPageFactRegistryConstants). The fact consists of (pageType, prime, n, z, alpha, prod, memoryHash, address). Note that address is only available for CONTINUOUS_PAGE, and otherwise it is 0. */ contract MemoryPageFactRegistry is FactRegistry, MemoryPageFactRegistryConstants { event LogMemoryPageFactRegular(bytes32 factHash, uint256 memoryHash, uint256 prod); event LogMemoryPageFactContinuous(bytes32 factHash, uint256 memoryHash, uint256 prod); /* Registers a fact based of the given memory (address, value) pairs (REGULAR_PAGE). */ function registerRegularMemoryPage( uint256[] calldata memoryPairs, uint256 z, uint256 alpha, uint256 prime ) external returns ( bytes32 factHash, uint256 memoryHash, uint256 prod ) { // Ensure 'memoryPairs.length' is bounded as a sanity check (the bound is somewhat arbitrary). require(memoryPairs.length < 2**20, "Too many memory values."); require(memoryPairs.length % 2 == 0, "Size of memoryPairs must be even."); require(z < prime, "Invalid value of z."); require(alpha < prime, "Invalid value of alpha."); (factHash, memoryHash, prod) = computeFactHash(memoryPairs, z, alpha, prime); emit LogMemoryPageFactRegular(factHash, memoryHash, prod); registerFact(factHash); } function computeFactHash( uint256[] memory memoryPairs, uint256 z, uint256 alpha, uint256 prime ) private pure returns ( bytes32 factHash, uint256 memoryHash, uint256 prod ) { uint256 memorySize = memoryPairs.length / 2; // NOLINT: divide-before-multiply. prod = 1; assembly { let memoryPtr := add(memoryPairs, 0x20) // Each value of memoryPairs is a pair: (address, value). let lastPtr := add(memoryPtr, mul(memorySize, 0x40)) for { let ptr := memoryPtr } lt(ptr, lastPtr) { ptr := add(ptr, 0x40) } { // Compute address + alpha * value. let address_value_lin_comb := addmod( // address= mload(ptr), mulmod( // value= mload(add(ptr, 0x20)), alpha, prime ), prime ) prod := mulmod(prod, add(z, sub(prime, address_value_lin_comb)), prime) } memoryHash := keccak256( memoryPtr, mul( // 0x20 * 2. 0x40, memorySize ) ) } factHash = keccak256( abi.encodePacked( REGULAR_PAGE, prime, memorySize, z, alpha, prod, memoryHash, uint256(0) ) ); } /* Registers a fact based on the given values, assuming continuous addresses. values should be [value at startAddr, value at (startAddr + 1), ...]. */ function registerContinuousMemoryPage( // NOLINT: external-function. uint256 startAddr, uint256[] memory values, uint256 z, uint256 alpha, uint256 prime ) public returns ( bytes32 factHash, uint256 memoryHash, uint256 prod ) { require(values.length < 2**20, "Too many memory values."); require(prime < 2**254, "prime is too big for the optimizations in this function."); require(z < prime, "Invalid value of z."); require(alpha < prime, "Invalid value of alpha."); // Ensure 'startAddr' less then prime and bounded as a sanity check (the bound is somewhat arbitrary). require((startAddr < prime) && (startAddr < 2**64), "Invalid value of startAddr."); uint256 nValues = values.length; assembly { // Initialize prod to 1. prod := 1 // Initialize valuesPtr to point to the first value in the array. let valuesPtr := add(values, 0x20) let minus_z := mod(sub(prime, z), prime) // Start by processing full batches of 8 cells, addr represents the last address in each // batch. let addr := add(startAddr, 7) let lastAddr := add(startAddr, nValues) for { } lt(addr, lastAddr) { addr := add(addr, 8) } { // Compute the product of (lin_comb - z) instead of (z - lin_comb), since we're // doing an even number of iterations, the result is the same. prod := mulmod( prod, mulmod( add(add(sub(addr, 7), mulmod(mload(valuesPtr), alpha, prime)), minus_z), add( add(sub(addr, 6), mulmod(mload(add(valuesPtr, 0x20)), alpha, prime)), minus_z ), prime ), prime ) prod := mulmod( prod, mulmod( add( add(sub(addr, 5), mulmod(mload(add(valuesPtr, 0x40)), alpha, prime)), minus_z ), add( add(sub(addr, 4), mulmod(mload(add(valuesPtr, 0x60)), alpha, prime)), minus_z ), prime ), prime ) prod := mulmod( prod, mulmod( add( add(sub(addr, 3), mulmod(mload(add(valuesPtr, 0x80)), alpha, prime)), minus_z ), add( add(sub(addr, 2), mulmod(mload(add(valuesPtr, 0xa0)), alpha, prime)), minus_z ), prime ), prime ) prod := mulmod( prod, mulmod( add( add(sub(addr, 1), mulmod(mload(add(valuesPtr, 0xc0)), alpha, prime)), minus_z ), add(add(addr, mulmod(mload(add(valuesPtr, 0xe0)), alpha, prime)), minus_z), prime ), prime ) valuesPtr := add(valuesPtr, 0x100) } // Handle leftover. // Translate addr to the beginning of the last incomplete batch. addr := sub(addr, 7) for { } lt(addr, lastAddr) { addr := add(addr, 1) } { let address_value_lin_comb := addmod( addr, mulmod(mload(valuesPtr), alpha, prime), prime ) prod := mulmod(prod, add(z, sub(prime, address_value_lin_comb)), prime) valuesPtr := add(valuesPtr, 0x20) } memoryHash := keccak256(add(values, 0x20), mul(0x20, nValues)) } factHash = keccak256( abi.encodePacked(CONTINUOUS_PAGE, prime, nValues, z, alpha, prod, memoryHash, startAddr) ); emit LogMemoryPageFactContinuous(factHash, memoryHash, prod); registerFact(factHash); } }