9

Yes, it's golf. So sue me.

Rules

The response to getCode() should have some characters that aren’t either 0 or x.

To test it out, you can use the following with a local testrpc:

web3.eth.sendTransaction({data:'BYTECODE', from:web3.eth.accounts[0]});
web3.eth.getCode('THE_ADDRESS');

Or you can use the evm command that comes with Geth:

evm --debug --code BYTECODE run.

Example:

This is a valid, but long-ish example: 0x600180600b6000396000f3

Don't spoil it

If you use a leading >! before your answer

it will be hidden

5

6 bytes (code: 6 bytes, payload: 0 bytes); 3 distinct opcodes. Same idea just 2 gas cheaper than previous 6-byter.

Bytecode:

0x3838533838f3

Assembly:

CODESIZE CODESIZE MSTORE8 CODESIZE CODESIZE RETURN

Works as follows:

Use the cheapest single-byte operation to get a value onto the stack CODESIZE. Store CODESIZE bytes at CODESIZE address in memory and then return CODESIZE bytes from CODESIZE location in memory.

Sample transaction: on etherscan

Gas used to deploy: 54622.

  • That "payload" in the template might have been misleading. What I meant by "payload" was data-as-code that's customisable, i.e. the actual value in this many bytes does not strictly change the bytecode's operation, and can be used to modify the target contract. (This is an unnecessary feature under the exercise's rules.) – Noel Maersk Feb 24 '18 at 17:53
  • @NoelMaersk - in that case, my solution would have a payload of 0 because you cannot customize the payload at all. Am I understanding that correctl? – yarrumretep Feb 25 '18 at 15:55
  • Yup, and that's perfectly fine! :) – Noel Maersk Feb 25 '18 at 19:51
3

Since Noel got close, time to release my 6-byter:

0x3859818153F3

Bytecode:

CODESIZE MSIZE DUP2 DUP2 MSTORE8 RETURN

Works as follows:

Use CODESIZE to get a nonzero value (0x06) on the stack using only one byte. MSIZE puts 0 on the stack. This will deploy the contract 0x060000000000.

  • So, you were behind this all along? :D – Noel Maersk Feb 24 '18 at 13:57
  • No, no - this is @maurelian's thing, but I did get a little head start. I'm reasonably sure that 6 bytes is minimal, but somebody surprise me! – benjaminion Feb 24 '18 at 14:04
  • Well, MSTORE and RETURN will consume 4 stack entries, so it makes sense that you'd need those 2, plus 4 more to load the stack. Unless there's a way to place two at once? – maurelian Feb 25 '18 at 14:44
1

7 bytes (code: 6 bytes, payload: 1 byte); 4 distinct opcodes.

Bytecode:

0x600180808053f3

Assembly:

PUSH1 0x01 DUP1 DUP1 DUP1 BYTES8 RETURN

Works as follows:

Push a byte of value X to the stack. Duplicate it three times. Move a byte from stack to memory, to same location X as the byte's value. Return X bytes from memory, starting at location X.

Sample transaction: on etherscan or etherchain.

Gas used to deploy: 53694.

0

Meta: template used for my answer:


X bytes (code: X bytes, payload: X byte); X distinct opcodes.

Bytecode:

>! 0xXXXXXXXXXXXXX

Assembly:

>! XXXXXXXXXXXXXXX

Works as follows:

>! XXXXXXXXXXXXXXX
>! XXXXXXXXXXXXXXX
>! XXXXXXXXXXXXXXX

Sample transaction: on [etherscan](XXX) or [etherchain](XXX).

Gas used to deploy: XXXXX.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.