Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EIP-6780: SELFDESTRUCT only in same transaction #4704

Merged
merged 30 commits into from
Jul 3, 2023

Conversation

smartprogrammer93
Copy link
Contributor

@smartprogrammer93 smartprogrammer93 commented Oct 5, 2022

Closes #4650

Types of changes

What types of changes does your code introduce?
Put an x in the boxes that apply

  • Bugfix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Documentation Update
  • Code style update (formatting, renaming)
  • Refactoring (no functional changes, no api changes)
  • Build related changes
  • Other (please describe):

Testing

Requires testing

  • Yes
  • No

In case you checked yes, did you write tests??

  • Yes
  • No

@Demuirgos
Copy link
Contributor

if you added a new value Instruction.SELLALL in the instruction enum with the same value of Instruction.SELFDESTRUCT , and in the switch statement you make the case like this :

switch(instruction) {
    ...
    case Instruction.SelfDestruct | Instruction.SellAll :
        Body with your changes
    ...
}

I think this way you wouldn't need to change all the old test files

@smartprogrammer93
Copy link
Contributor Author

@Demuirgos that did not work since both constants will be the same value. the constant name is same.

@Demuirgos
Copy link
Contributor

@smartprogrammer93, this is close to what I had in mind :

using System;
var opcode = (Instruction)0xff; //op code is name agnostic so it only depends on the value

test(opcode, activateShanghai : true); // we pretend test it with "shanghai" activated
// console result : "SELLALL behavior"
test(opcode, activateShanghai : false);// we pretend test it with "shanghai" deactivated
// console result : "SELFDESTRUCT behavior"

void test(Instruction instruction, bool activateShanghai) {
    switch(instruction) {
        case Instruction.SELLALL | Instruction.SELFDESTRUCT: // since they are both the same value underneath "or"ing them will result in the same value as themselves 
            if(activateShanghai) { // shanghai specific behaviour
                Console.WriteLine("SELLALL behavior");
            } else { // old behaviour
                Console.WriteLine("SELFDESTRUCT behavior");
            }
            break;
        default : 
            break;
    }
}

enum Instruction {
    SELFDESTRUCT = 0xff, // old instruction
    SELLALL = 0xff // new instruction with same value as old instruction
}

@smartprogrammer93
Copy link
Contributor Author

@Demuirgos Good idea. thank you

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not entirely sure if there isn't anything more to it?

src/Nethermind/Nethermind.Evm/VirtualMachine.cs Outdated Show resolved Hide resolved
Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@smartprogrammer93 we're renaming opcode for the second time in Nethermind history ;) We did it for the merge and DIFFICULTY/PREVRANDAO opcode. And we had to add one more thing to handle traces: https://github.com/NethermindEth/nethermind/blob/master/src/Nethermind/Nethermind.Evm/Instruction.cs#L192

Check this out, I believe you need to do similar thing. It is not consensus critical, but it could be easy to forget later.

@rubo rubo removed the draft eip label Dec 29, 2022
@smartprogrammer93 smartprogrammer93 changed the title EIP-4758: Deactivate SELFDESTRUCT EIP-6780: SELFDESTRUCT only in same transaction Apr 17, 2023
@smartprogrammer93 smartprogrammer93 marked this pull request as ready for review April 17, 2023 21:46
{
[TestCase(MainnetSpecProvider.GrayGlacierBlockNumber, 0ul, false)]
[TestCase(MainnetSpecProvider.GrayGlacierBlockNumber, MainnetSpecProvider.CancunBlockTimestamp, true)]
public void self_destruct_not_in_same_transaction(long blockNumber, ulong timestamp, bool onlyOnSameTransaction)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you document these tests a bit, to make it easy to understand the trick being used ?


[TestCase(MainnetSpecProvider.GrayGlacierBlockNumber, MainnetSpecProvider.CancunBlockTimestamp)]
public void self_destruct_in_same_transaction(long blockNumber, ulong timestamp)
{
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same here

.PushData(40)
.Op(Instruction.JUMP)
.Op(Instruction.JUMPDEST)
.PushData(TestItem.PrivateKeyB.Address)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what if you used the ADDRESS opcode, and why use PrivateKeyB?

Copy link
Contributor

@MarekM25 MarekM25 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QQ: no need to change tracing: ITxTracer.ReportSelfDestruct?

@MarekM25 MarekM25 self-requested a review July 3, 2023 10:47
@MarekM25 MarekM25 merged commit f30a724 into master Jul 3, 2023
61 checks passed
@MarekM25 MarekM25 deleted the shanghai/feature/EIP-4758_Deactivate_SELFDESTRUCT branch July 3, 2023 10:49
@@ -178,6 +181,7 @@ private int[] RentReturnStack()
_accessedAddresses = stateForAccessLists._accessedAddresses;
_accessedStorageCells = stateForAccessLists._accessedStorageCells;
_destroyList = stateForAccessLists._destroyList;
_createList = stateForAccessLists._createList;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you are not creating/restoring snapshot on _createList, while using parent collection. This can cause issues as created items will bubble up to parent context?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want it to bubble up. I want a list of created contracts in the whole transaction not only the current context

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

EIP-6780: SELFDESTRUCT only in same transaction
5 participants