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

implement Hofmann structure #169

Merged
merged 12 commits into from
Jan 13, 2020
Merged

implement Hofmann structure #169

merged 12 commits into from
Jan 13, 2020

Conversation

TheReturnOfJan
Copy link
Contributor

@TheReturnOfJan TheReturnOfJan commented Jan 5, 2020

resolves #118

@troggy
Copy link
Member

troggy commented Jan 5, 2020

why you are removing fixtures? 🤔

@TheReturnOfJan
Copy link
Contributor Author

This is very much WIP. I made the PR so I have a nice diff to look at. I will announce when it's ready for review.

@TheReturnOfJan TheReturnOfJan changed the title Hofman WIP: Hofman Jan 5, 2020
@troggy
Copy link
Member

troggy commented Jan 5, 2020

cool. go go go 🚀

@johannbarbie
Copy link
Member

i have this one failing test:


  1) Runtime
       initAndExecute
         CALL transfer - successful transfer:

      AssertionError [ERR_ASSERTION]: tokenBag
      + expected - actual

seems easy to fix, need help?

@TheReturnOfJan
Copy link
Contributor Author

Still WIP @johannbarbie. patience :)

@TheReturnOfJan
Copy link
Contributor Author

Ok all tests now passing and it's cleaned up a bit. FIrst comments welcome!

@johannbarbie
Copy link
Member

JS Stepper
      1) STATICCALL balanceOf - successful read
      2) STATICCALL balanceOf - missed color
      3) STATICCALL balanceOf - missed address
      4) STATICCALL readData - successfull read
      5) CALL transfer - successfull transfer

i still have these guys failing. errors look like this:

  1) JS Stepper
       fixtures
         STATICCALL balanceOf - successful read:

      AssertionError [ERR_ASSERTION]: stack
      + expected - actual

       [
      -  "0x0000000000000000000000000000000000000000000000000000000000000000"
      +  "0x0000000000000000000000000000000000000000000000000000000000000001"
       ]

@TheReturnOfJan
Copy link
Contributor Author

Yeah I noticed this after, seems like I need to update the off-chain stepper to behave the same.

@johannbarbie
Copy link
Member

Yeah I noticed this after, seems like I need to update the off-chain stepper to behave the same.

is that even possible? or are we at a dead end here?

@TheReturnOfJan
Copy link
Contributor Author

Why not possible? I just didn't even know it existed in this repo. Will do it tomorrow.



contract EVMRuntime is EVMConstants {
using EVMMemory for EVMMemory.Memory;
using EVMStack for EVMStack.Stack;
using EVMCode for EVMCode.Code;
using EVMTokenBag for EVMTokenBag.TokenBag;

// bridge has to defreagment the tokens
Copy link
Member

Choose a reason for hiding this comment

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

minor detail, but it is not actually the Bridge, but the Enforcer that will have to do these things. see here: https://docs.google.com/drawings/d/1WXcAvTEpXDGeL68MfWOP20mERht8rzqfSzdiFtYZeSc
in that diagram the bridge takes the client contract role.
same in this diagram: https://docs.google.com/drawings/d/1vlRmrHJd-eozM9e34pgCEnm8Iuq9bhqVnopOva7Tfz4

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well the bridge should do that and enforcer just passes onwards i guess? Details of plasma should stay out of the EVM-enforcer as much as possible.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, i think we need some intermediate contract here. the bridge only understand transactions, but not runtime.

331690,
765537,
47813,
90953,
Copy link
Member

Choose a reason for hiding this comment

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

how does this one get created?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This entire file is generated during tests.

Copy link
Member

Choose a reason for hiding this comment

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

should we exclude it from git then?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Maybe 🤔
I did not take the time to fully understand what it does 😆 , but I assume it is committed for a reason.

}
state.gas -= gasFee;

bytes memory cd = state.mem.toBytes(stack.inOffset, stack.inSize);
Copy link
Member

Choose a reason for hiding this comment

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

maybe use cData or callDataBytes here, to keep it readable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

Copy link
Member

@johannbarbie johannbarbie left a comment

Choose a reason for hiding this comment

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

awesome work 💯
few details and comments required

bool success;
bytes memory returnData;

if (funSig == 0x22334455) {
Copy link
Member

Choose a reason for hiding this comment

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

should be 0xa9059cbb for transfer(address,uint256)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed and moved to constants.

to: dest,
value: amount
});
success = state.tokenBag.transfer(params);
Copy link
Member

Choose a reason for hiding this comment

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

could the creation of params be done inline, to save a stack element?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This was actually not needed anymore. Removed in favour of normal function params.

uint amount;

assembly {
dest := mload(add(cd,24))
Copy link
Member

Choose a reason for hiding this comment

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

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

}

if (!success) {
state.stack.push(0);
Copy link
Member

Choose a reason for hiding this comment

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

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

@@ -1609,7 +1690,13 @@ contract EVMRuntime is EVMConstants {
}
state.gas -= retEvm.gas;

retEvm.data = state.mem.toBytes(inOffset, inSize);
bytes memory cd = state.mem.toBytes(inOffset, inSize);
Copy link
Member

Choose a reason for hiding this comment

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

indentation

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

return tokenBag;
}

module.exports = TokenBagHelpers;
Copy link
Member

Choose a reason for hiding this comment

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

🎉

const success = runState.tokenBag.transfer(color, from, to, amount);

if (success) {
runState.stack.push(new BN(1));
Copy link
Member

Choose a reason for hiding this comment

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

add comment here if 1 is success or error

Copy link
Member

Choose a reason for hiding this comment

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

or use constant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FIXED.

const data = this.memLoad(runState, inOffset, inLength);
const funcSig = this.getFuncSig(data);

if (funcSig === '0x22334455') {
Copy link
Member

Choose a reason for hiding this comment

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

update sigHash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

FIxed.

runState.stack.push(new BN(1));
runState.returnValue = returnValue;
return;
} else if (funcSig === '0x12341234') {
Copy link
Member

Choose a reason for hiding this comment

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

update sigHash

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Fixed.

const data = this.memLoad(runState, inOffset, inLength);
const funcSig = this.getFuncSig(data);

if (toAddress.gten(0) && toAddress.lten(8)) {
Copy link
Member

@johannbarbie johannbarbie Jan 13, 2020

Choose a reason for hiding this comment

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

the address has to be larger than or equal to 0 and less than or equal 8? 🤔
when does this condition match?

Copy link
Member

Choose a reason for hiding this comment

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

ah, precompiles, got it.

@troggy troggy changed the title WIP: Hofman implement Hofman structure Jan 13, 2020
@troggy troggy changed the title implement Hofman structure implement Hofmann structure Jan 13, 2020
Copy link
Member

@johannbarbie johannbarbie left a comment

Choose a reason for hiding this comment

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

🥓

@johannbarbie johannbarbie merged commit b060a2f into master Jan 13, 2020
@johannbarbie johannbarbie deleted the hofman branch January 13, 2020 16:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

design hofmann structure
3 participants