This repository has been archived by the owner on Nov 6, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'upgrade-51' into change-default-values
- Loading branch information
Showing
34 changed files
with
304 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
{"format_version":1,"inbox":[{"Tuple":[{"Int":"4"},{"Int":"186a0"},{"Int":"989680"},{"Int":"0"},{"Int":"0"},{"Int":"77359400"},{"Int":"40"},{"Buffer":"625a539a292ffb7be735d7db3f6b9b9c88b9ced262ae58163dfb75ba308551f2000000000000000000000000000000000000000000000000000000000000a4b1"}]}],"logs":[{"Tuple":[{"Int":"1"},{"Int":"0"},{"Int":"0"},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"1"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"112a8800"}]},{"Int":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},{"Int":"0"}]}],"sends":[],"total_gas":1253250} | ||
{"format_version":1,"inbox":[{"Tuple":[{"Int":"4"},{"Int":"186a0"},{"Int":"989680"},{"Int":"0"},{"Int":"0"},{"Int":"77359400"},{"Int":"40"},{"Buffer":"625a539a292ffb7be735d7db3f6b9b9c88b9ced262ae58163dfb75ba308551f2000000000000000000000000000000000000000000000000000000000000a4b1"}]}],"logs":[{"Tuple":[{"Int":"1"},{"Int":"0"},{"Int":"0"},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"1"},{"Int":"0"}]},{"Tuple":[{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"0"},{"Int":"112a8800"}]},{"Int":"ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff"},{"Int":"0"}]}],"sends":[],"total_gas":1247162} |
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,151 @@ | ||
// | ||
// Copyright 2020, Offchain Labs, Inc. All rights reserved. | ||
// | ||
|
||
use std::biguint::biguint_equal; | ||
use std::biguint::biguint_fromUint; | ||
use std::biguint::biguint_modexp; | ||
use std::biguint::biguint_toBytes; | ||
use std::biguint::biguint_fromBytes; | ||
use std::biguint::biguint_isZero; | ||
|
||
use std::queue::queue_new; | ||
use std::queue::queue_isEmpty; | ||
use std::queue::queue_put; | ||
use std::queue::queue_get; | ||
use std::queue::queue_size; | ||
|
||
use std::bytearray::ByteArray; | ||
use std::bytearray::bytearray_new; | ||
use std::bytearray::bytearray_set64; | ||
use std::bytearray::bytearray_set256; | ||
use std::bytearray::bytearray_get256; | ||
use std::bytearray::bytearray_extract; | ||
|
||
use std::keccak::keccak256; | ||
|
||
var entropy: ByteArray; | ||
|
||
view write func main() { | ||
if let Some(res) = test() { | ||
asm(res) { log }; | ||
} else { | ||
asm("unwrap panic".1,) { log }; | ||
} | ||
} | ||
|
||
view write func test() -> option<any> { | ||
|
||
let q = queue_new(); | ||
|
||
q = queue_put(q, ( | ||
biguint_fromUint(0), // base | ||
biguint_fromUint(1), // exponent | ||
biguint_fromUint(1), // modulus | ||
biguint_fromUint(0), // expected result | ||
)); | ||
|
||
q = queue_put(q, ( | ||
biguint_fromUint(0x10001), | ||
biguint_fromUint(0xccf4d91acbdba9e9795b09c107816a4538d193be735e2aef192d49bc86e179ad), | ||
biguint_fromUint(0x73753b483ae0f07b9ad7fab2932e47bc8a67fa44d848770b26de2140aedf9996), | ||
biguint_fromUint(0x595368ed0128efa3fb81d46fbfec3ef263055b883fea4813b19b87cc218e8731), | ||
)); | ||
|
||
q = queue_put(q, ( | ||
biguint_fromBytes({ | ||
let base = bytearray_new(0); | ||
base = bytearray_set256(base, 0, 0x630f4bef8d4648e496b55384a8373cde2f2abcf9cf542436cfc69b884ae8840e); | ||
base = bytearray_set256(base, 32, 0x5726f10727c325c3be1cb08931c7bf42b9d163c9ecedd30abeec31d654ec3790); | ||
base | ||
}), | ||
biguint_fromBytes({ | ||
let exp = bytearray_new(0); | ||
exp = bytearray_set256(exp, 0, 0xccf4d91acbdba9e9795b09c107816a4538d193be735e2aef192d49bc86e179ad); | ||
exp = bytearray_set256(exp, 32, 0xccf4d91acbdba9e9795b09c107816a4538d193be735e2aef192d49bc86e179ad); | ||
exp | ||
}), | ||
biguint_fromBytes({ | ||
let mod = bytearray_new(0); | ||
mod = bytearray_set256(mod, 0, 0x73753b483ae0f07b9ad7fab2932e47bc8a67fa44d848770b26de2140aedf9996); | ||
mod = bytearray_set256(mod, 32, 0x73753b483ae0f07b9ad7fab2932e47bc8a67fa44d848770b26de2140aedf9996); | ||
mod | ||
}), | ||
biguint_fromBytes({ | ||
let res = bytearray_new(0); | ||
res = bytearray_set256(res, 0, 0x521c7db3320c62d2c9e27e53ecbc07105a0c2604d3c38828301391b747a149f8); | ||
res = bytearray_set256(res, 32, 0xeb04d256a17429f1590942d176b1fe89f600926a47b8a5874c1444180ef6a3e2); | ||
res | ||
}) | ||
)); | ||
|
||
while !queue_isEmpty(q) { | ||
let (*q, case) = queue_get(q)?; | ||
let case = unsafecast<([]uint, []uint, []uint, []uint)>(case); | ||
let (base, exponent, modulus, expected) = case; | ||
|
||
let result = biguint_modexp(base, exponent, modulus)?; | ||
if !biguint_equal(result, expected) { | ||
return Some(("failed on test #".1, (queue_size(q) + 1), "expected:", expected, "but have:", result)); | ||
} | ||
} | ||
|
||
entropy = bytearray_new(0); | ||
entropy = bytearray_set256(entropy, 0, 5); | ||
|
||
let rand = view write closure(bound: uint) -> uint { | ||
let keccak = uint(keccak256(entropy, 0, 32)); | ||
entropy = bytearray_set256(entropy, 0, keccak); | ||
bytearray_get256(entropy, 0) % bound | ||
}; | ||
|
||
let rand_bytes = view write closure(lower: uint, upper: uint) -> []uint { | ||
let bytes = bytearray_new(0); | ||
let i = 0; | ||
let length = lower + rand(upper - lower); | ||
while i < length { | ||
bytes = bytearray_set256(bytes, i*32, bytearray_get256(entropy, rand(1))); | ||
i = i + 1; | ||
} | ||
biguint_fromBytes(bytearray_extract(bytes, 0, 1)) | ||
}; | ||
|
||
let rounds = 100; | ||
let step = 0; | ||
while step < rounds { | ||
entropy = bytearray_set64(entropy, 0, step); | ||
debug((step, entropy.contents)); | ||
|
||
let base = rand_bytes(1, 2); | ||
let exponent = rand_bytes(1, 2); | ||
let modulus = rand_bytes(1, 2); | ||
|
||
if !biguint_isZero(modulus) { | ||
|
||
let result = biguint_modexp(base, exponent, modulus)?; | ||
let modexp = biguint_toBytes(result); | ||
let hashed = keccak256(modexp, 0, 32); | ||
|
||
entropy = bytearray_set256(entropy, 0, uint(hashed)); | ||
|
||
debug(( | ||
step, | ||
entropy.contents, | ||
bytearray_get256(biguint_toBytes(base), 0), | ||
bytearray_get256(biguint_toBytes(exponent), 0), | ||
bytearray_get256(biguint_toBytes(modulus), 0), | ||
bytearray_get256(biguint_toBytes(result), 0) | ||
)); | ||
} | ||
|
||
step = step + 1; | ||
} | ||
|
||
let accumulation = bytearray_get256(entropy, 0); | ||
|
||
if accumulation != 0x48078cfed56339ea54962e72c37c7f588fc4f8e5bc173827ba75cb10a63a96a5 { | ||
Some(accumulation) | ||
} else { | ||
Some(0) | ||
} | ||
} |
Oops, something went wrong.