-
Notifications
You must be signed in to change notification settings - Fork 213
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
[entropy] Change provider interface to simplify supporting many chains #1149
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -35,17 +35,18 @@ impl PebbleHashChain { | |
} | ||
|
||
pub fn from_config( | ||
opts: &RandomnessOptions, | ||
secret: &str, | ||
chain_id: &ChainId, | ||
random: [u8; 32], | ||
random: &[u8; 32], | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think seed is a better name here. |
||
chain_length: u64, | ||
) -> Result<Self> { | ||
let mut input: Vec<u8> = vec![]; | ||
input.extend_from_slice(&hex::decode(opts.secret.clone())?); | ||
input.extend_from_slice(&hex::decode(secret)?); | ||
input.extend_from_slice(&chain_id.as_bytes()); | ||
input.extend_from_slice(&random); | ||
input.extend_from_slice(random); | ||
|
||
let secret: [u8; 32] = Keccak256::digest(input).into(); | ||
Ok(Self::new(secret, opts.chain_length.try_into()?)) | ||
Ok(Self::new(secret, chain_length.try_into()?)) | ||
} | ||
|
||
/// Reveal the next hash in the chain using the previous proof. | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -95,7 +95,7 @@ contract Entropy is IEntropy, EntropyState { | |
function register( | ||
uint feeInWei, | ||
bytes32 commitment, | ||
bytes32 commitmentMetadata, | ||
bytes calldata commitmentMetadata, | ||
uint64 chainLength | ||
) public override { | ||
if (chainLength == 0) revert EntropyErrors.AssertionFailure(); | ||
|
@@ -186,7 +186,6 @@ contract Entropy is IEntropy, EntropyState { | |
req.providerCommitment = providerInfo.currentCommitment; | ||
req.providerCommitmentSequenceNumber = providerInfo | ||
.currentCommitmentSequenceNumber; | ||
req.providerCommitmentMetadata = providerInfo.commitmentMetadata; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive by: I deleted this field from req (it's not needed) |
||
|
||
if (useBlockHash) { | ||
req.blockNumber = block.number; | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -44,19 +44,14 @@ contract EntropyTest is Test { | |
random.register( | ||
provider1FeeInWei, | ||
provider1Proofs[0], | ||
bytes32(keccak256(abi.encodePacked(uint256(0x0100)))), | ||
hex"0100", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. drive-by: shorter way to write this |
||
provider1ChainLength | ||
); | ||
|
||
bytes32[] memory hashChain2 = generateHashChain(provider2, 0, 100); | ||
provider2Proofs = hashChain2; | ||
vm.prank(provider2); | ||
random.register( | ||
provider2FeeInWei, | ||
provider2Proofs[0], | ||
bytes32(keccak256(abi.encodePacked(uint256(0x0200)))), | ||
100 | ||
); | ||
random.register(provider2FeeInWei, provider2Proofs[0], hex"0200", 100); | ||
} | ||
|
||
function generateHashChain( | ||
|
@@ -323,12 +318,7 @@ contract EntropyTest is Test { | |
10 | ||
); | ||
vm.prank(provider1); | ||
random.register( | ||
provider1FeeInWei, | ||
newHashChain[0], | ||
bytes32(keccak256(abi.encodePacked(uint256(0x0100)))), | ||
10 | ||
); | ||
random.register(provider1FeeInWei, newHashChain[0], hex"0100", 10); | ||
assertInvariants(); | ||
EntropyStructs.ProviderInfo memory info1 = random.getProviderInfo( | ||
provider1 | ||
|
@@ -397,12 +387,7 @@ contract EntropyTest is Test { | |
|
||
// Check that overflowing the fee arithmetic causes the transaction to revert. | ||
vm.prank(provider1); | ||
random.register( | ||
MAX_UINT256, | ||
provider1Proofs[0], | ||
bytes32(keccak256(abi.encodePacked(uint256(0x0100)))), | ||
100 | ||
); | ||
random.register(MAX_UINT256, provider1Proofs[0], hex"0100", 100); | ||
vm.expectRevert(); | ||
random.getFee(provider1); | ||
} | ||
|
@@ -452,12 +437,7 @@ contract EntropyTest is Test { | |
|
||
// Reregistering updates the required fees | ||
vm.prank(provider1); | ||
random.register( | ||
12345, | ||
provider1Proofs[0], | ||
bytes32(keccak256(abi.encodePacked(uint256(0x0100)))), | ||
100 | ||
); | ||
random.register(12345, provider1Proofs[0], hex"0100", 100); | ||
|
||
assertRequestReverts(pythFeeInWei + 12345 - 1, provider1, 42, false); | ||
requestWithFee(user2, pythFeeInWei + 12345, provider1, 42, false); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why these got deleted? :?