Merge pull request #10775 from ethereum/useRoundUpInArrayAlloc

Use round up function.
This commit is contained in:
Alex Beregszaszi 2021-01-14 21:46:32 +00:00 committed by GitHub
commit 31ee06d945
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 11 additions and 9 deletions

View File

@ -2056,8 +2056,7 @@ string YulUtilFunctions::arrayAllocationSizeFunction(ArrayType const& _type)
// Make sure we can allocate memory without overflow // Make sure we can allocate memory without overflow
if gt(length, 0xffffffffffffffff) { <panic>() } if gt(length, 0xffffffffffffffff) { <panic>() }
<?byteArray> <?byteArray>
// round up size := <roundUp>(length)
size := and(add(length, 0x1f), not(0x1f))
<!byteArray> <!byteArray>
size := mul(length, 0x20) size := mul(length, 0x20)
</byteArray> </byteArray>
@ -2070,6 +2069,7 @@ string YulUtilFunctions::arrayAllocationSizeFunction(ArrayType const& _type)
w("functionName", functionName); w("functionName", functionName);
w("panic", panicFunction(PanicCode::ResourceError)); w("panic", panicFunction(PanicCode::ResourceError));
w("byteArray", _type.isByteArray()); w("byteArray", _type.isByteArray());
w("roundUp", roundUpFunction());
w("dynamic", _type.isDynamicallySized()); w("dynamic", _type.isDynamicallySized());
return w.render(); return w.render();
}); });

File diff suppressed because one or more lines are too long

View File

@ -88,8 +88,7 @@ object \"C_11\" {
// Make sure we can allocate memory without overflow // Make sure we can allocate memory without overflow
if gt(length, 0xffffffffffffffff) { panic_error_0x41() } if gt(length, 0xffffffffffffffff) { panic_error_0x41() }
// round up size := round_up_to_mul_of_32(length)
size := and(add(length, 0x1f), not(0x1f))
// add length slot // add length slot
size := add(size, 0x20) size := add(size, 0x20)

View File

@ -88,8 +88,7 @@ object \"C_11\" {
// Make sure we can allocate memory without overflow // Make sure we can allocate memory without overflow
if gt(length, 0xffffffffffffffff) { panic_error_0x41() } if gt(length, 0xffffffffffffffff) { panic_error_0x41() }
// round up size := round_up_to_mul_of_32(length)
size := and(add(length, 0x1f), not(0x1f))
// add length slot // add length slot
size := add(size, 0x20) size := add(size, 0x20)

View File

@ -14,9 +14,9 @@ contract C {
} }
// ---- // ----
// creation: // creation:
// codeDepositCost: 1173600 // codeDepositCost: 1174000
// executionCost: 1221 // executionCost: 1221
// totalCost: 1174821 // totalCost: 1175221
// external: // external:
// a(): 1130 // a(): 1130
// b(uint256): infinite // b(uint256): infinite