This commit is contained in:
wborgeaud 2023-04-20 17:28:33 +02:00 committed by GitHub
parent 6edd589138
commit 1a0a63003d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 1 deletions

View File

@ -130,7 +130,6 @@ after_constructor:
// stack: new_ctx, leftover_gas, success, address, kexit_info
POP
// TODO: EIP-170: Contract code size limit.
// TODO: EIP-3541: Reject new contract code starting with the 0xEF byte
// TODO: Skip blocks below if success is false.
@ -138,6 +137,10 @@ after_constructor:
SWAP3
// stack: kexit_info, success, address, leftover_gas
%returndatasize // Size of the code.
// stack: code_size, kexit_info, success, address, leftover_gas
DUP1 %gt_const(@MAX_CODE_SIZE)
%jumpi(fault_exception)
// stack: code_size, kexit_info, success, address, leftover_gas
%mul_const(@GAS_CODEDEPOSIT) %charge_gas
SWAP3

View File

@ -145,6 +145,16 @@ global process_contract_creation_txn_after_constructor:
// stack: success, leftover_gas, new_ctx, address, retdest
POP // TODO: Success will go into the receipt when we support that.
// stack: leftover_gas, new_ctx, address, retdest
%returndatasize // Size of the code.
// stack: code_size, leftover_gas, new_ctx, address, retdest
DUP1 %gt_const(@MAX_CODE_SIZE) %jumpi(panic) // TODO: need to revert changes here.
// stack: code_size, leftover_gas, new_ctx, address, retdest
%mul_const(@GAS_CODEDEPOSIT) SWAP1
// stack: leftover_gas, codedeposit_cost, new_ctx, address, retdest
DUP2 DUP2 LT %jumpi(panic) // TODO: need to revert changes here.
// stack: leftover_gas, codedeposit_cost, new_ctx, address, retdest
SUB
// stack: leftover_gas, new_ctx, address, retdest
%pay_coinbase_and_refund_sender
// TODO: Delete accounts in self-destruct list and empty touched addresses.
// stack: new_ctx, address, retdest

View File

@ -40,6 +40,10 @@ pub fn evm_constants() -> HashMap<String, U256> {
c.insert(name.into(), U256::from(value));
}
for (name, value) in CODE_SIZE_LIMIT {
c.insert(name.into(), U256::from(value));
}
for segment in Segment::all() {
c.insert(segment.var_name().into(), (segment as u32).into());
}
@ -227,3 +231,9 @@ const PRECOMPILES_GAS: [(&str, u16); 13] = [
("SNARKV_DYNAMIC_GAS", 34_000),
("BLAKE2_F_DYNAMIC_GAS", 1),
];
const CODE_SIZE_LIMIT: [(&str, u64); 3] = [
("MAX_CODE_SIZE", 0x6000),
("MAX_INITCODE_SIZE", 0xc000),
("INITCODE_WORD_COST", 2),
];