Skip to content

Commit

Permalink
Update permissioning smart contract interface to match updated EEA pr…
Browse files Browse the repository at this point in the history
…oposal (PegaSysEng#1287)
  • Loading branch information
Errorific authored and notlesh committed May 4, 2019
1 parent e9adfc2 commit 33e0dd4
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,13 @@ contract SimplePermissioning {
function connectionAllowed(
bytes32 sourceEnodeHigh, bytes32 sourceEnodeLow, bytes16 sourceEnodeIp, uint16 sourceEnodePort,
bytes32 destinationEnodeHigh, bytes32 destinationEnodeLow, bytes16 destinationEnodeIp, uint16 destinationEnodePort)
public view returns (bool) {
return (enodeAllowed(sourceEnodeHigh, sourceEnodeLow, sourceEnodeIp, sourceEnodePort) &&
enodeAllowed(destinationEnodeHigh, destinationEnodeLow, destinationEnodeIp, destinationEnodePort));
public view returns (bytes32) {
if (enodeAllowed(sourceEnodeHigh, sourceEnodeLow, sourceEnodeIp, sourceEnodePort) &&
enodeAllowed(destinationEnodeHigh, destinationEnodeLow, destinationEnodeIp, destinationEnodePort)) {
return 0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
} else {
return 0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff;
}
}
function enodeAllowed(bytes32 sourceEnodeHigh, bytes32 sourceEnodeLow, bytes16 sourceEnodeIp, uint16 sourceEnodePort)
public view returns (bool){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
package tech.pegasys.pantheon.tests.acceptance.dsl.transaction.perm;

import static java.nio.charset.StandardCharsets.UTF_8;
import static tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController.checkTransactionResult;

import tech.pegasys.pantheon.ethereum.core.Address;
import tech.pegasys.pantheon.ethereum.permissioning.SmartContractPermissioningController;
Expand Down Expand Up @@ -55,6 +54,32 @@ public Boolean execute(final JsonRequestFactories node) {
}
}

// Checks the returned bytes from the permissioning contract call to see if it's a value we
// understand
static Boolean checkTransactionResult(final BytesValue result) {
// booleans are padded to 32 bytes
if (result.size() != 32) {
throw new IllegalArgumentException("Unexpected result size");
}

// 0 is false
if (result.compareTo(
BytesValue.fromHexString(
"0x0000000000000000000000000000000000000000000000000000000000000000"))
== 0) {
return false;
// 1 filled to 32 bytes is true
} else if (result.compareTo(
BytesValue.fromHexString(
"0x0000000000000000000000000000000000000000000000000000000000000001"))
== 0) {
return true;
// Anything else is wrong
} else {
throw new IllegalStateException("Unexpected result form");
}
}

private org.web3j.protocol.core.methods.request.Transaction payload() {
final String sourceEnodeURL = ((RunnableNode) node).enodeUrl().toASCIIString();
final BytesValue payload =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"0x0000000000000000000000000000000000009999": {
"comment": "Simple permissioning smart contract",
"balance": "0",
"code": "608060405260043610610067576000357c01000000000000000000000000000000000000000000000000000000009004806312eef3631461006c5780633600f60d146100f45780633620b1df1461016457806378a402d51461022c578063aab2f5eb14610315575b600080fd5b34801561007857600080fd5b506100da6004803603608081101561008f57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610385565b604051808215151515815260200191505060405180910390f35b34801561010057600080fd5b506101626004803603608081101561011757600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff16906020019092919050505061046b565b005b34801561017057600080fd5b50610212600480360361010081101561018857600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506105ad565b604051808215151515815260200191505060405180910390f35b34801561023857600080fd5b5061029a6004803603608081101561024f57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506105dd565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102da5780820151818401526020810190506102bf565b50505050905090810190601f1680156103075780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561032157600080fd5b506103836004803603608081101561033857600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff16906020019092919050505061064f565b005b60006060610395868686866105dd565b9050600080826040518082805190602001908083835b6020831015156103d057805182526020820191506020810190506020830392506103ab565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902090506000700100000000000000000000000000000000028160020160009054906101000a9004700100000000000000000000000000000000026fffffffffffffffffffffffffffffffff1916111561046057600192505050610463565b50505b949350505050565b6104736107ae565b608060405190810160405280868152602001858152602001846fffffffffffffffffffffffffffffffff191681526020018361ffff16815250905060606104bc868686866105dd565b9050816000826040518082805190602001908083835b6020831015156104f757805182526020820191506020810190506020830392506104d2565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b60006105bb89898989610385565b80156105cf57506105ce85858585610385565b5b905098975050505050505050565b60608484848460405160200180858152602001848152602001836fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff191681526020018261ffff1661ffff1681526020019450505050506040516020818303038152906040529050949350505050565b606061065d858585856105dd565b90506106676107ae565b60806040519081016040528060006001028152602001600060010281526020016000700100000000000000000000000000000000026fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509050806000836040518082805190602001908083835b6020831015156106f857805182526020820191506020810190506020830392506106d3565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b608060405190810160405280600080191681526020016000801916815260200160006fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509056fea165627a7a723058205d7c55d1840d31bf182a29a52e7df6a735d27af6d711d8f3331b3ada03dc7d940029",
"code": "608060405260043610610067576000357c01000000000000000000000000000000000000000000000000000000009004806312eef3631461006c5780633600f60d146100f45780633620b1df1461016457806378a402d514610228578063aab2f5eb14610311575b600080fd5b34801561007857600080fd5b506100da6004803603608081101561008f57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610381565b604051808215151515815260200191505060405180910390f35b34801561010057600080fd5b506101626004803603608081101561011757600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190505050610467565b005b34801561017057600080fd5b50610212600480360361010081101561018857600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff169060200190929190803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506105a9565b6040518082815260200191505060405180910390f35b34801561023457600080fd5b506102966004803603608081101561024b57600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff16906020019092919050505061062e565b6040518080602001828103825283818151815260200191508051906020019080838360005b838110156102d65780820151818401526020810190506102bb565b50505050905090810190601f1680156103035780820380516001836020036101000a031916815260200191505b509250505060405180910390f35b34801561031d57600080fd5b5061037f6004803603608081101561033457600080fd5b81019080803590602001909291908035906020019092919080356fffffffffffffffffffffffffffffffff19169060200190929190803561ffff1690602001909291905050506106a0565b005b600060606103918686868661062e565b9050600080826040518082805190602001908083835b6020831015156103cc57805182526020820191506020810190506020830392506103a7565b6001836020036101000a038019825116818451168082178552505050505050905001915050908152602001604051809103902090506000700100000000000000000000000000000000028160020160009054906101000a9004700100000000000000000000000000000000026fffffffffffffffffffffffffffffffff1916111561045c5760019250505061045f565b50505b949350505050565b61046f6107ff565b608060405190810160405280868152602001858152602001846fffffffffffffffffffffffffffffffff191681526020018361ffff16815250905060606104b88686868661062e565b9050816000826040518082805190602001908083835b6020831015156104f357805182526020820191506020810190506020830392506104ce565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b60006105b789898989610381565b80156105cb57506105ca85858585610381565b5b156105fb577fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff6001029050610622565b7f7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff60010290505b98975050505050505050565b60608484848460405160200180858152602001848152602001836fffffffffffffffffffffffffffffffff19166fffffffffffffffffffffffffffffffff191681526020018261ffff1661ffff1681526020019450505050506040516020818303038152906040529050949350505050565b60606106ae8585858561062e565b90506106b86107ff565b60806040519081016040528060006001028152602001600060010281526020016000700100000000000000000000000000000000026fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509050806000836040518082805190602001908083835b6020831015156107495780518252602082019150602081019050602083039250610724565b6001836020036101000a0380198251168184511680821785525050505050509050019150509081526020016040518091039020600082015181600001556020820151816001015560408201518160020160006101000a8154816fffffffffffffffffffffffffffffffff02191690837001000000000000000000000000000000009004021790555060608201518160020160106101000a81548161ffff021916908361ffff160217905550905050505050505050565b608060405190810160405280600080191681526020016000801916815260200160006fffffffffffffffffffffffffffffffff19168152602001600061ffff168152509056fea165627a7a72305820c18b04628b7fa30a0188fb4ede3466f5d013b403793835501df6055a155b9c420029",
"storage": {}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,12 @@ private static BytesValue hashSignature(final String signature) {
}

// True from a contract is 1 filled to 32 bytes
private static final BytesValue TRUE_RESPONSE;

static {
final byte[] trueValue = new byte[32];
trueValue[31] = (byte) (0xFF & 1L);
TRUE_RESPONSE = BytesValue.wrap(trueValue);
}
private static final BytesValue TRUE_RESPONSE =
BytesValue.fromHexString(
"0xffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");
private static final BytesValue FALSE_RESPONSE =
BytesValue.fromHexString(
"0x7fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff");

/**
* Creates a permissioning controller attached to a blockchain
Expand Down Expand Up @@ -96,7 +95,7 @@ public static Boolean checkTransactionResult(final BytesValue result) {
}

// 0 is false
if (result.isZero()) {
if (result.compareTo(FALSE_RESPONSE) == 0) {
return false;
// 1 filled to 32 bytes is true
} else if (result.compareTo(TRUE_RESPONSE) == 0) {
Expand Down
Loading

0 comments on commit 33e0dd4

Please sign in to comment.