mirror of
				https://github.com/ethereum/solidity
				synced 2023-10-03 13:03:40 +00:00 
			
		
		
		
	Merge pull request #13694 from ethereum/evmhost_set_storage
test: Improve precision of SSTORE cost in EVMHost
This commit is contained in:
		
						commit
						5c139b60b8
					
				| @ -179,7 +179,7 @@ void EVMHost::newTransactionFrame() | ||||
| 		for (auto& [slot, value]: account.storage) | ||||
| 		{ | ||||
| 			value.access_status = EVMC_ACCESS_COLD; // Clear EIP-2929 storage access indicator
 | ||||
| 			value.dirty = false;					// Clear EIP-2200 dirty slot flag
 | ||||
| 			value.original = value.current;			// Clear EIP-2200 dirty slot
 | ||||
| 		} | ||||
| 	// Process selfdestruct list
 | ||||
| 	for (auto& [address, _]: recorded_selfdestructs) | ||||
| @ -1195,7 +1195,7 @@ void EVMHostPrinter::storage() | ||||
| 			m_stateStream << "  " | ||||
| 				<< m_host.convertFromEVMC(slot) | ||||
| 				<< ": " | ||||
| 				<< m_host.convertFromEVMC(value.value) | ||||
| 				<< m_host.convertFromEVMC(value.current) | ||||
| 				<< endl; | ||||
| } | ||||
| 
 | ||||
|  | ||||
| @ -282,7 +282,7 @@ bool ExecutionFramework::storageEmpty(h160 const& _addr) const | ||||
| 	if (it != m_evmcHost->accounts.end()) | ||||
| 	{ | ||||
| 		for (auto const& entry: it->second.storage) | ||||
| 			if (!(entry.second.value == evmc::bytes32{})) | ||||
| 			if (entry.second.current != evmc::bytes32{}) | ||||
| 				return false; | ||||
| 	} | ||||
| 	return true; | ||||
|  | ||||
| @ -15,30 +15,20 @@ namespace evmc | ||||
| /// The string of bytes.
 | ||||
| using bytes = std::basic_string<uint8_t>; | ||||
| 
 | ||||
| /// Extended value (by dirty flag) for account storage.
 | ||||
| /// Extended value (with original value and access flag) for account storage.
 | ||||
| struct storage_value | ||||
| { | ||||
|     /// The storage value.
 | ||||
|     bytes32 value; | ||||
|     /// The current storage value.
 | ||||
|     bytes32 current; | ||||
| 
 | ||||
|     /// True means this value has been modified already by the current transaction.
 | ||||
|     bool dirty{false}; | ||||
|     /// The original storage value.
 | ||||
|     bytes32 original; | ||||
| 
 | ||||
|     /// Is the storage key cold or warm.
 | ||||
|     evmc_access_status access_status{EVMC_ACCESS_COLD}; | ||||
|     evmc_access_status access_status = EVMC_ACCESS_COLD; | ||||
| 
 | ||||
|     /// Default constructor.
 | ||||
|     storage_value() noexcept = default; | ||||
| 
 | ||||
|     /// Constructor.
 | ||||
|     storage_value(const bytes32& _value, bool _dirty = false) noexcept  // NOLINT
 | ||||
|       : value{_value}, dirty{_dirty} | ||||
|     {} | ||||
| 
 | ||||
|     /// Constructor with initial access status.
 | ||||
|     storage_value(const bytes32& _value, evmc_access_status _access_status) noexcept | ||||
|       : value{_value}, access_status{_access_status} | ||||
|     {} | ||||
| }; | ||||
| 
 | ||||
| /// Mocked account.
 | ||||
| @ -176,7 +166,7 @@ public: | ||||
| 
 | ||||
|         const auto storage_iter = account_iter->second.storage.find(key); | ||||
|         if (storage_iter != account_iter->second.storage.end()) | ||||
|             return storage_iter->second.value; | ||||
|             return storage_iter->second.current; | ||||
|         return {}; | ||||
|     } | ||||
| 
 | ||||
| @ -195,14 +185,13 @@ public: | ||||
|         // Follow https://eips.ethereum.org/EIPS/eip-1283 specification.
 | ||||
|         // WARNING! This is not complete implementation as refund is not handled here.
 | ||||
| 
 | ||||
|         if (old.value == value) | ||||
|         if (old.current == value) | ||||
|             return EVMC_STORAGE_UNCHANGED; | ||||
| 
 | ||||
|         evmc_storage_status status{}; | ||||
|         if (!old.dirty) | ||||
|         if (old.original == old.current)  // Storage slot not dirty
 | ||||
|         { | ||||
|             old.dirty = true; | ||||
|             if (!old.value) | ||||
|             if (!old.current) | ||||
|                 status = EVMC_STORAGE_ADDED; | ||||
|             else if (value) | ||||
|                 status = EVMC_STORAGE_MODIFIED; | ||||
| @ -212,7 +201,7 @@ public: | ||||
|         else | ||||
|             status = EVMC_STORAGE_MODIFIED_AGAIN; | ||||
| 
 | ||||
|         old.value = value; | ||||
|         old.current = value; | ||||
|         return status; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -46,8 +46,8 @@ contract c { | ||||
| // storageEmpty -> 0 | ||||
| // test_long() -> 67 | ||||
| // gas irOptimized: 89148 | ||||
| // gas legacy: 105839 | ||||
| // gas legacyOptimized: 103293 | ||||
| // gas legacy: 108639 | ||||
| // gas legacyOptimized: 106093 | ||||
| // storageEmpty -> 0 | ||||
| // test_pop() -> 1780731860627700044960722568376592200742329637303199754547598369979433020 | ||||
| // gas legacy: 61930 | ||||
|  | ||||
| @ -24,5 +24,5 @@ contract c { | ||||
| // ---- | ||||
| // test() -> 3, 4 | ||||
| // gas irOptimized: 189690 | ||||
| // gas legacy: 195353 | ||||
| // gas legacyOptimized: 192441 | ||||
| // gas legacy: 215253 | ||||
| // gas legacyOptimized: 212341 | ||||
|  | ||||
| @ -46,6 +46,6 @@ contract C { | ||||
| } | ||||
| // ---- | ||||
| // f() -> 0xff | ||||
| // gas irOptimized: 119584 | ||||
| // gas legacy: 132274 | ||||
| // gas legacyOptimized: 123756 | ||||
| // gas irOptimized: 179284 | ||||
| // gas legacy: 191974 | ||||
| // gas legacyOptimized: 183456 | ||||
|  | ||||
| @ -15,3 +15,5 @@ contract C { | ||||
| // ---- | ||||
| // f() -> 0, 0, 0 | ||||
| // gas irOptimized: 90992 | ||||
| // gas legacy: 111037 | ||||
| // gas legacyOptimized: 109633 | ||||
|  | ||||
| @ -42,10 +42,10 @@ contract C { | ||||
| } | ||||
| // ---- | ||||
| // f() -> | ||||
| // gas irOptimized: 121657 | ||||
| // gas legacy: 122132 | ||||
| // gas legacyOptimized: 121500 | ||||
| // gas irOptimized: 141557 | ||||
| // gas legacy: 142032 | ||||
| // gas legacyOptimized: 141400 | ||||
| // g() -> | ||||
| // gas irOptimized: 145472 | ||||
| // gas legacy: 145707 | ||||
| // gas legacyOptimized: 144940 | ||||
| // gas irOptimized: 148272 | ||||
| // gas legacy: 148507 | ||||
| // gas legacyOptimized: 147740 | ||||
|  | ||||
| @ -52,18 +52,18 @@ contract C { | ||||
| // ---- | ||||
| // test_zeroed_indicies(uint256): 1 -> | ||||
| // test_zeroed_indicies(uint256): 5 -> | ||||
| // gas irOptimized: 153874 | ||||
| // gas legacy: 155001 | ||||
| // gas legacyOptimized: 152239 | ||||
| // gas irOptimized: 165074 | ||||
| // gas legacy: 166201 | ||||
| // gas legacyOptimized: 163439 | ||||
| // test_zeroed_indicies(uint256): 10 -> | ||||
| // gas irOptimized: 277077 | ||||
| // gas legacy: 279488 | ||||
| // gas legacyOptimized: 274412 | ||||
| // gas irOptimized: 282677 | ||||
| // gas legacy: 285088 | ||||
| // gas legacyOptimized: 280012 | ||||
| // test_zeroed_indicies(uint256): 15 -> | ||||
| // gas irOptimized: 399822 | ||||
| // gas legacy: 403538 | ||||
| // gas legacyOptimized: 396227 | ||||
| // gas irOptimized: 405422 | ||||
| // gas legacy: 409138 | ||||
| // gas legacyOptimized: 401827 | ||||
| // test_zeroed_indicies(uint256): 0xFF -> | ||||
| // gas irOptimized: 6399212 | ||||
| // gas legacy: 6460633 | ||||
| // gas legacyOptimized: 6327477 | ||||
| // gas irOptimized: 6404812 | ||||
| // gas legacy: 6466233 | ||||
| // gas legacyOptimized: 6333077 | ||||
|  | ||||
		Loading…
	
		Reference in New Issue
	
	Block a user