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

Validator manager contract in solidity #4

Merged
merged 17 commits into from Feb 5, 2018

Conversation

enriquefynn
Copy link
Contributor

@enriquefynn enriquefynn commented Jan 15, 2018

Work in progress.

Missing:

  • Withdraw
  • addHeader


import "RLP.sol";

interface ValidatorContract {
Copy link
Member

Choose a reason for hiding this comment

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

This is no longer needed

Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

@enriquefynn we could check in this contract with the finished methods and have skeleton/stub methods for the others that aren't complete yet.

See this thread for source on some of my comments: https://gitter.im/ethereum/py-evm?at=5a6d73da0ad3e04b1b79d5df

// Amount of wei the validator holds
uint deposit;
// The address which the validator's signatures must verify to (to be later replaced with validation code)
ValidatorContract validationCodeAddr;
Copy link
Member

Choose a reason for hiding this comment

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

We should store the validator account. Perhaps having the returnAddr and the validator address be the same

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 there's no need for validationCodeAddr anymore then. We can storeaddr instead

var msgHash = keccak256("withdraw");
// TODO: Check this function
var result = validators[_validatorIndex].validationCodeAddr.withdraw.gas(sigGasLimit)(_sig);
if (result) {
Copy link
Member

Choose a reason for hiding this comment

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

This goes away and we assert(msg.sender == validators[_validatorIndex].address)

}
}

function sample(int _shardId) public constant returns(address) {
Copy link
Member

Choose a reason for hiding this comment

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

Is this meant to be getEligibleProposer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@prestonvanloon
Copy link
Member

Also see ethereum/sharding#37

Remove validator's code and use the transaction's signature
to verify the validator's identity
@prestonvanloon
Copy link
Member

prestonvanloon commented Feb 5, 2018

We should sync with the changes in this PR: ethereum/py-evm#348 This removes the validator code requirement.

Also, can we prepare this to merge? Even if some of it is incomplete

Copy link
Member

@prestonvanloon prestonvanloon left a comment

Choose a reason for hiding this comment

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

Left a few comments. If any feel out of scope, please create an issue and mention it in response to my comment then we can resolve in another pull request.

Thanks for putting this together

function VMC() public {
}

function isStackEmpty() internal view returns(bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Please reorganize functions to this order:

constructor
fallback function (if exists)
external
public
internal
private

http://solidity.readthedocs.io/en/develop/style-guide.html#order-of-functions

function isStackEmpty() internal view returns(bool) {
return emptySlotsStackTop == 0;
}
function stackPush(int index) internal {
Copy link
Member

Choose a reason for hiding this comment

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

Please add space between function declarations.

address to;
}

mapping (int => Validator) validators;
Copy link
Member

Choose a reason for hiding this comment

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

Could you comment what the keys are for these mappings?

Copy link
Member

Choose a reason for hiding this comment

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

If the keys are shard ID or period number, shouldn't this be uint?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If the keys are shard ID or period number, shouldn't this be uint?

I want to do this afterwards, when I test the code gets bigger when modifying the ints to uint.
Some of those can also be packed in smaller sizes.

deposit: msg.value,
addr: msg.sender
});
++numValidators;
Copy link
Member

Choose a reason for hiding this comment

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

Formatting

// [TODO] Should check further if this safe or not
return validators[
int(
uint(keccak256(uint(block.blockhash(_period - lookAheadPeriods)) * periodLength, _shardId))
Copy link
Member

Choose a reason for hiding this comment

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

Formatting, please indent these three lines so it is clear that the result of modulus is cast to int.

return receiptId;
}

function updataGasPrice(int _receiptId, uint _txGasprice) public payable returns(bool) {
Copy link
Member

Choose a reason for hiding this comment

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

/updata/update/s

)].addr;
}

struct HeaderVars {
Copy link
Member

Choose a reason for hiding this comment

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

HeaderVars? Is this the collation header? Can we drop "Vars" and replace with something more meaningful?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That's just to pack variables used in the addHeader function

}
function addHeader(int _shardId, uint _expectedPeriodNumber, bytes32 _periodStartPrevHash,
bytes32 _parentCollationHash, bytes32 _txListRoot, address _collationCoinbase,
bytes32 _postStateRoot, bytes32 _receiptRoot, int _collationNumber) public returns(bool) {
Copy link
Member

Choose a reason for hiding this comment

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

Always returns true? When is a false state? Can this be a void method?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

From the sharding spec:

addHeader(bytes header) returns bool: attempts to process a collation header, returns True on success, reverts on failure.

I think it can be a void method. We should probably clone also the spec if we start differing so much, no?

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good to me

data: _data
});
var receiptId = numReceipts;
++numReceipts;
Copy link
Member

Choose a reason for hiding this comment

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

I'm not 100% on solidity, but if receiptId is the same reference as numReceipts then wouldn't they both be incremented?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, receiptId is a variable in memory.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

// during a future collation. Saves a `receipt ID` for this request,
// also saving `msg.sender`, `msg.value`, `to`, `shard_id`, `startgas`,
// `gasprice`, and `data`.
function txToShard(address _to, int _shardId, uint _txStartgas, uint _txGasprice, bytes12 _data) public payable returns(int) {
Copy link
Member

Choose a reason for hiding this comment

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

Line too long, can you limit to 100 characters for review?


// Constant values
uint constant periodLength = 5;
int constant shardCount = 100;
Copy link
Contributor

Choose a reason for hiding this comment

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

Please make shardcount public

@rauljordan
Copy link
Contributor

Looks all good to me...would you all be ok with merging??

// if (parent_collation_hash == 0), i.e., is the genesis,
// then there is no need to check.
if (_parentCollationHash != 0x0)
assert((_parentCollationHash == 0x0) || (collationHeaders[_shardId][_parentCollationHash].score > 0));
Copy link
Member

Choose a reason for hiding this comment

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

_parentCollationHash == 0x0 can never be true from within this if statement, please update

data: _data
});
var receiptId = numReceipts;
++numReceipts;
Copy link
Member

Choose a reason for hiding this comment

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

Sounds good

@prestonvanloon prestonvanloon changed the title WIP: Validator manager contract in solidity Validator manager contract in solidity Feb 5, 2018
@prestonvanloon prestonvanloon merged commit 11dc61f into prysmaticlabs:master Feb 5, 2018
prestonvanloon added a commit that referenced this pull request Jul 22, 2018
Validator manager contract in solidity
prestonvanloon added a commit that referenced this pull request Jul 22, 2018
Validator manager contract in solidity

Former-commit-id: 5c8e92a
prestonvanloon added a commit that referenced this pull request Jul 22, 2018
Validator manager contract in solidity

Former-commit-id: 41453f9a6262ca73e52ed93aa5e9539b7d6edc46 [formerly 5c8e92a]
Former-commit-id: 75b3b72
mdehoog added a commit to mdehoog/prysm that referenced this pull request Jun 14, 2022
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.

None yet

3 participants